-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix rewrites to edge routes #58797
Merged
Merged
fix rewrites to edge routes #58797
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ijjk
added
area: tests
created-by: Next.js team
PRs by the Next.js team
type: next
labels
Nov 22, 2023
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
Tests Passed |
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
|
ztanner
requested review from
timneutkens,
ijjk,
shuding,
huozhi,
feedthejim and
wyattjoh
as code owners
November 23, 2023 01:11
ijjk
approved these changes
Nov 23, 2023
shuding
approved these changes
Nov 23, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Rewrites to an edge route currently throw an invariant rather than properly serving up the page that is rewritten to.
Why?
The
NextRequest
object that is provided to the edge route handler contains pathname information only for the "origin" request (e.g., when visiting/one/example
which rewrites to/two/example
, the pathname is still/one/example
. This hits an invariant since the route matcher is unable to find/one/example
since it does not exist.How?
This updates the module wrapper to grab the pathname from the route definition rather than the request object. For dynamic segments, we extract them from
request.nextUrl
since we know that even ifnextUrl
is referencing the origin path, the parameters it has are relevant for the rewrite.This adds the
getUtils
utility that's also used in base-server to handle the URL normalization, which also provides an interface for normalizing dynamic params from aParsedUrlQuery
.Closes NEXT-1724
Fixes #48295