File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -36,13 +36,23 @@ const augmentMatchers = (
3636 matchers : NextDefinition [ 'matchers' ] ,
3737 ctx : PluginContext ,
3838) : NextDefinition [ 'matchers' ] => {
39- if ( ! ctx . buildConfig . i18n ) {
39+ const i18NConfig = ctx . buildConfig . i18n
40+ if ( ! i18NConfig ) {
4041 return matchers
4142 }
4243 return matchers . flatMap ( ( matcher ) => {
4344 if ( matcher . originalSource && matcher . locale !== false ) {
4445 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 ,
4656 {
4757 ...matcher ,
4858 regexp : pathToRegexp ( matcher . originalSource ) . source ,
You can’t perform that action at this time.
0 commit comments