fix(nextjs): Parameterize [lng] locale routes and prefer narrower routes over catch-alls - #23520
Merged
Merged
Conversation
…outes over catch-alls Routes using a `[lng]` locale param were reported as the 404 catch-all. Two causes: `hasOptionalPrefix` only matched `locale`, `lang` and `language`, so `[lng]` never got the unprefixed-default-locale retry. Route specificity summed per-segment scores, letting a short catch-all beat a longer but strictly narrower route. Compare segment by segment instead. This also affected prefixed locales, not just unprefixed ones. Add `routeManifestInjection.localeParamNames` to override the built-in list. It replaces rather than extends the defaults so apps with a non-i18n `[lang]` param can opt out. Fixes #23488 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
|
bugbot run |
Contributor
size-limit report 📦
|
The length tiebreaker preferred the longer route whenever the shared segments tied, so '/fr' matched '/:lng/:notFound*' via the optional-prefix retry instead of '/:lng'. Compare one segment past the shorter route instead, ranking the end of a route between a dynamic segment and a catch-all: continuing into a static or dynamic segment narrows a route, continuing into a catch-all widens it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ddbdd91. Configure here.
chargome
marked this pull request as ready for review
August 24, 2026 13:23
chargome
requested review from
logaretm,
mydea and
nicohrubec
and removed request for
a team and
mydea
August 24, 2026 13:23
logaretm
approved these changes
Aug 24, 2026
JPeer264
pushed a commit
that referenced
this pull request
Aug 25, 2026
…outes over catch-alls (#23520) `[lng]` locale routes were reported as the 404 catch-all. Two causes: - `hasOptionalPrefix` only matched `locale`/`lang`/`language`, so `[lng]` never got the unprefixed-default-locale retry. - Route specificity summed per-segment scores, letting a short catch-all (`/:lng/:notFound*`) beat a longer but strictly narrower route (`/:lng/guides/:category/:rest*`). It is now compared segment by segment. This one also affected prefixed locales, which the issue assumed were working. Also adds `routeManifestInjection.localeParamNames` to override the built-in list, as raised in #17927. It replaces rather than extends the defaults so an app with a genuine non-i18n `[lang]` param can opt out. Fixes #23488 --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
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.
[lng]locale routes were reported as the 404 catch-all. Two causes:hasOptionalPrefixonly matchedlocale/lang/language, so[lng]never got the unprefixed-default-locale retry./:lng/:notFound*) beat a longer but strictly narrower route (/:lng/guides/:category/:rest*). It is now compared segment by segment. This one also affected prefixed locales, which the issue assumed were working.Also adds
routeManifestInjection.localeParamNamesto override the built-in list, as raised in #17927. It replaces rather than extends the defaults so an app with a genuine non-i18n[lang]param can opt out.Fixes #23488