-
Notifications
You must be signed in to change notification settings - Fork 87
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: narrow down middleware i18n locale matcher to concrete locales #2768
Merged
pieh
merged 2 commits into
main
from
michalpiechowiak/frb-1645-middleware-matcher-producing-unexpected-ef-manifest-with
Feb 25, 2025
Merged
fix: narrow down middleware i18n locale matcher to concrete locales #2768
pieh
merged 2 commits into
main
from
michalpiechowiak/frb-1645-middleware-matcher-producing-unexpected-ef-manifest-with
Feb 25, 2025
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
📊 Package size report 0.01%↑
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
ac52f3f
to
6348f63
Compare
6348f63
to
e1b3b8a
Compare
serhalp
approved these changes
Feb 24, 2025
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.
Seems worth a full e2e run, otherwise LGTM. Good find!
Note: Not merging yet - will run vercel/next.js e2e tests against multiple majors for testing to be doubly sure about this change |
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.
Description
Next.js produce very wide matcher for i18n path segment in localized path ( https://github.com/vercel/next.js/blob/5e236c9909a768dc93856fdfad53d4f4adc2db99/packages/next/src/build/analysis/get-page-static-info.ts#L332-L336 ) which is
[^/.]{1,}
that will match on any single path segment. If user attempt to exclude path likeapi
as described in one of https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher examples:resulting final regex that Next.js will produce in
middleware-manifest.json
will be:We currently do use this one as-is and addtionally produce on our own pattern without i18n segment (because for us edge middleware is entrypoint, so there is nothing inbetween ~user request that could massage/normalize request url) to also cover cases of ~user requests without i18n prefix (which will be canonical path for
defaultLocale
)Pattern we additionally produce is this
For demonstration purposes I combine both of those, name some matching groups and provide some examples of unintentional matches it produce - https://regex101.com/r/jRfvOE/1

the wide i18n matcher will "consume"
api
segment, meaning thatapi
exclusion in user defined matcher can no longer discard it and therefore it passes through.As a fix for this I'm replacing this currently wide i18n matcher with concrete locales that user defines in their next.config.js, which results in following - https://regex101.com/r/dPQIgE/1

So
api/*
routes no longer being matched as was intented by custom matcherDocumentation
Tests
Added fixture with i18n and exclussion + tests in first commit (without any changes one of those tests fail - the
api
case). After applying a fix with modyfying Next.js matcher - the test is now passing.Relevant links (GitHub issues, etc.) or a picture of cute animal
https://linear.app/netlify/issue/FRB-1645/middleware-matcher-producing-unexpected-ef-manifest-with-i18n