File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -36,13 +36,23 @@ const augmentMatchers = (
36
36
matchers : NextDefinition [ 'matchers' ] ,
37
37
ctx : PluginContext ,
38
38
) : NextDefinition [ 'matchers' ] => {
39
- if ( ! ctx . buildConfig . i18n ) {
39
+ const i18NConfig = ctx . buildConfig . i18n
40
+ if ( ! i18NConfig ) {
40
41
return matchers
41
42
}
42
43
return matchers . flatMap ( ( matcher ) => {
43
44
if ( matcher . originalSource && matcher . locale !== false ) {
44
45
return [
45
- matcher ,
46
+ matcher . regexp
47
+ ? {
48
+ ...matcher ,
49
+ // https://github.com/vercel/next.js/blob/5e236c9909a768dc93856fdfad53d4f4adc2db99/packages/next/src/build/analysis/get-page-static-info.ts#L332-L336
50
+ // Next is producing pretty broad matcher for i18n locale. Presumably rest of their infrastructure protects this broad matcher
51
+ // from matching on non-locale paths. For us this becomes request entry point, so we need to narrow it down to just defined locales
52
+ // otherwise users might get unexpected matches on paths like `/api*`
53
+ regexp : matcher . regexp . replace ( / \[ \^ \/ \. ] + / g, `(${ i18NConfig . locales . join ( '|' ) } )` ) ,
54
+ }
55
+ : matcher ,
46
56
{
47
57
...matcher ,
48
58
regexp : pathToRegexp ( matcher . originalSource ) . source ,
You can’t perform that action at this time.
0 commit comments