-
Notifications
You must be signed in to change notification settings - Fork 92
fix: ensure middleware matchers evaluate default locale #2548
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
Closed
Conversation
This file contains hidden or 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
📊 Package size report -0.02%↓
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
...types allow Headers object)
...tlify-plugin-nextjs into rs/frp-761-imiddleware-locale
orinokai
orinokai
commented
Jul 23, 2024
orinokai
orinokai
commented
Jul 23, 2024
orinokai
orinokai
commented
Jul 23, 2024
orinokai
orinokai
commented
Jul 23, 2024
}
for (const path of ['/hello/invalid', '/about', '/en/about']) {
for (const path of ['/hello/invalid', '/invalid/hello','/about', '/en/about','/es/about']) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/hello should not be matched when prefixed with a non-locale (this is the main part of the fix) and /about should not be matched when prefixed with anything other than the specific nl locale
pieh
pieh
reviewed
Jul 24, 2024
pieh
pieh
reviewed
Jul 24, 2024
pieh
pieh
reviewed
Jul 25, 2024
@orinokai
orinokai
added
test all versions
Run e2e tests against old and canary versions of Next.js
run-e2e-tests
labels
Jul 25, 2024
@orinokai
orinokai
removed
the
test all versions
Run e2e tests against old and canary versions of Next.js
label
Jul 25, 2024
Superseded by a scaled down version #2555
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Uh oh!
There was an error while loading. Please reload this page.
Description
Middleware matching is performed at the edge and also in the edge function because there are some patterns we are unable to evaluate at the edge.
When i18n is enabled, the regex generated by Next matches paths with or without a locale in the first segment of the URL path. However, it does not match the specific list of locales and simply matches any string in the first segment.
This is a problem because
/testwill also match any page at the next level, e.g./products/testbecause the matcher assumesproductsis a locale.This PR splits URL normalizing and localizing into separate functions, for clarity and type-safety (
buildNextRequestnow returns a partialNextRequestobject), and returns alocalizedURLparameter to the middleware matcher so that the above case is avoided by always evaluating the match using the prefixed locale or the default, e.g./en/products/test.Tests
Relevant links (GitHub issues, etc.) or a picture of cute animal
Fixes FRP-761