-
Notifications
You must be signed in to change notification settings - Fork 89
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
Conversation
📊 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
expect(await response.text()).toBe('Hello from origin!') | ||
expect(response.status).toBe(200) | ||
} | ||
|
||
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
Superseded by a scaled down version #2555 |
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
/test
will also match any page at the next level, e.g./products/test
because the matcher assumesproducts
is a locale.This PR splits URL normalizing and localizing into separate functions, for clarity and type-safety (
buildNextRequest
now returns a partialNextRequest
object), and returns alocalizedURL
parameter 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