Commit graph

18 commits

Author SHA1 Message Date
JJ Kasper
8f09bc44f7
Fix middleware catch-all rewrite case (#63254)
This ensures we properly set the matched header when applying a
middleware skip optimization so that the client router has enough
context to finish resolving the dynamic route params.

Fixes: https://github.com/vercel/next.js/issues/59561

Closes NEXT-2803
2024-03-13 14:14:04 -07:00
JJ Kasper
71d354363e
Fix external rewrite with body (#49487)
This ensures we use the proper body stream when rewriting to an external
resource as currently it tries to consume an already read body stream.

Fixes: https://github.com/vercel/next.js/issues/48040
2023-05-08 15:22:02 -07:00
JJ Kasper
533c242094
Add middleware prefetching config (#42936)
This adds a new `experimental.middlewarePrefetch` config with two modes
with the default being the `flexible` config.

- `strict` only prefetches when the `href` explicitly matches an SSG
route (won't prefetch for middleware rewrite usage unless manual
`href`/`as` values are used)
- `flexible` always prefetches ensuring middleware rewrite usage is
handled and also prevents executing SSR routes during prefetch to avoid
unexpected invocations

x-ref: https://github.com/vercel/next.js/pull/39920
x-ref: [slack
thread](https://vercel.slack.com/archives/C047HMFN58X/p1668473101696689?thread_ts=1667856323.709179&cid=C047HMFN58X)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-17 13:22:36 -08:00
JJ Kasper
f2c2343ca8
Ensure query is provided correctly with middleware rewrites (#42818)
x-ref: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1668195556550659)
Fixes: https://github.com/vercel/next.js/issues/42463

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-14 20:30:23 -08:00
Tim Neutkens
f260328900
BREAKING CHANGE: Enable newNextLinkBehavior (#41459)
- Enable newNextLinkBehavior. See #36436 
- Run next/link codemod on test suite

Note that from when this lands on apps trying canary will need to run
the new-link codemod in order to upgrade.
Ideally we have to detect `<a>` while rendering the new link and warn
for it.

Co-authored-by: Steven <steven@ceriously.com>
2022-10-17 21:20:28 -04:00
JJ Kasper
889af9fd2c
Fix edge workers being re-used unexpectedly (#41402)
This ensures we don't re-use edge workers locally as they are meant to
be isolated.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

Fixes: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1665708744315109)
2022-10-13 22:56:42 -07:00
JJ Kasper
7777130324
Fix middleware URL normalize case (#41342)
Follow-up to https://github.com/vercel/next.js/pull/41341 this fixes a
related issue with the URL normalizing in middleware and updates the
regression tests.

x-ref: [slack
thread](https://vercel.slack.com/archives/C01224Q5M99/p1665161421775079?thread_ts=1664536480.045539&cid=C01224Q5M99)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
2022-10-11 14:27:31 -07:00
JJ Kasper
31886589a0
Fix middleware rewrite for _next/data (#41341)
x-ref: [slack
thread](https://vercel.slack.com/archives/C01224Q5M99/p1665161421775079?thread_ts=1664536480.045539&cid=C01224Q5M99)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
2022-10-11 12:23:22 -07:00
JJ Kasper
f7df3fc158
Ensure prefetch heuristic matches with and without middleware (#39920)
This fixes the prefetching handling when middleware is present as currently we are incorrectly triggering data requests for non-SSG pages to handle the case where a middleware rewrite is present and pointing to an SSG path. Since the majority use case won't be rewriting in middleware and this incurs a lot of potentially heavy requests to `getServerSideProps` paths this matches the prefetch handling when middleware isn't present and only prefetches the data route when we match an SSG path. 

Fixes: [slack thread](https://vercel.slack.com/archives/C0289CGVAR2/p1661364670589519?thread_ts=1661199566.675759&cid=C0289CGVAR2)
Fixes: https://github.com/vercel/next.js/issues/38918

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-08-26 16:24:10 -05:00
JJ Kasper
a154c15799
Fix middleware + afterFiles SSG rewrite case (#39153) 2022-07-28 20:23:18 -05:00
JJ Kasper
e3efc030cd
Ensure we hard navigate for failed _next/data with middleware (#39148)
* Ensure we hard navigate for failed _next/data with middleware

* fix-lint
2022-07-28 15:48:26 -05:00
JJ Kasper
3a31b96f26
Ensure query is updated correctly with shallow and middleware (#39086)
This ensures we properly update the query when doing a shallow navigation with middleware present and expands our test coverage of this kind of navigation. This also adds middleware rewrite coverage for the case described in https://github.com/vercel/next.js/issues/38405  and ensures we properly resolve dynamic middleware rewrites which was causing https://github.com/vercel/next.js/issues/39049

Test deployment with fix can be seen [here](https://middleware-i18n-redirect-repro-8jd3x47j9-ijjk-testing.vercel.app/gsp/first) and [here](https://nextjs-middleware-rewrite-l6q20cwo3-ijjk-testing.vercel.app/)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/38495
Fixes: https://github.com/vercel/next.js/issues/39049
Fixes: https://github.com/vercel/next.js/issues/38405
2022-07-28 00:52:56 +00:00
Jiachi Liu
f21a9dd5cb
Fix pageProps is missing when route changes (#38178)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-30 18:13:07 +00:00
Javi Velasco
ca621ced66
Add init to some NextResponse methods (#38071)
* Add `init` to some `NextResponse` methods

* Add NextResponse.redirect test and fix headers

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-27 18:39:00 -05:00
JJ Kasper
85e643be83
Ensure query params are populated correctly with middleware (#37784)
* Ensure query params are populated correctly with middleware

* update test

* dont match edge ssr

* fix query hydrate check

* fix lint

* update test
2022-06-17 10:28:25 -05:00
Javi Velasco
2d5d43fb75
Refactor server routing (#37725)
This PR fixes an issue where we have a middleware that rewrites every single request to the same origin while having `i18n` configured. It would be something like: 

```typescript
import { NextResponse } from 'next/server'

export function middleware(req) {
  return NextResponse.rewrite(req.nextUrl)
}
```

In this case we are going to be adding always the `locale` at the beginning of the destination since it is a rewrite. This causes static assets to not match and the whole application to break. I believe this is a potential footgun so in this PR we are addressing the issue by removing the locale from pathname for those cases where we check against the filesystem (e.g. public folder).

To achieve this change, this PR introduces some preparation changes and then a refactor of the logic in the server router. After this refactor we are going to be relying on properties that can be defined in the `Route` to decide wether or not we should remove the `basePath`, `locale`, etc instead of checking which _type_ of route it is that we are matching.

Overall this simplifies quite a lot the server router. The way we are testing the mentioned issue is by adding a default rewrite in the rewrite tests middleware.
2022-06-16 21:43:01 +00:00
Javi Velasco
c501842311
Add test combining middleware & config rewrites (#37667)
* Add test combining middleware & config rewrites

* Add `afterFiles` test

* update some tests

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-14 17:31:33 -05:00
JJ Kasper
607ff2b322
Update to process redirects/rewrites for _next/data with middleware (#37574)
* Update to process redirects/rewrites for _next/data

* correct matched-path resolving with middleware

* Add next-data header

* migrate middleware tests

* lint-fix

* update error case

* update test case

* Handle additional resolving cases and add more tests

* update test from merge

* fix test

* rm .only

* apply changes from review

* ensure _next/data resolving does not apply without middleware
2022-06-10 12:35:12 -05:00