Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c54f168d
Unverified
Commit
c54f168d
authored
Jul 23, 2021
by
JJ Kasper
Committed by
GitHub
Jul 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add config check for invalid duplicate locale domains (#27451)
parent
ee605cb6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
config.ts
packages/next/server/config.ts
+13
-0
index.test.js
test/integration/i18n-support/test/index.test.js
+34
-0
No files found.
packages/next/server/config.ts
View file @
c54f168d
...
@@ -340,6 +340,19 @@ function assignDefaults(userConfig: { [key: string]: any }) {
...
@@ -340,6 +340,19 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if
(
!
item
.
defaultLocale
)
return
true
if
(
!
item
.
defaultLocale
)
return
true
if
(
!
item
.
domain
||
typeof
item
.
domain
!==
'string'
)
return
true
if
(
!
item
.
domain
||
typeof
item
.
domain
!==
'string'
)
return
true
const
defaultLocaleDuplicate
=
i18n
.
domains
?.
find
(
(
altItem
)
=>
altItem
.
defaultLocale
===
item
.
defaultLocale
&&
altItem
.
domain
!==
item
.
domain
)
if
(
defaultLocaleDuplicate
)
{
console
.
warn
(
`Both
${
item
.
domain
}
and
${
defaultLocaleDuplicate
.
domain
}
configured the defaultLocale
${
item
.
defaultLocale
}
but only one can. Change one item's default locale to continue`
)
return
true
}
let
hasInvalidLocale
=
false
let
hasInvalidLocale
=
false
if
(
Array
.
isArray
(
item
.
locales
))
{
if
(
Array
.
isArray
(
item
.
locales
))
{
...
...
test/integration/i18n-support/test/index.test.js
View file @
c54f168d
...
@@ -498,4 +498,38 @@ describe('i18n Support', () => {
...
@@ -498,4 +498,38 @@ describe('i18n Support', () => {
runSlashTests
(
curCtx
)
runSlashTests
(
curCtx
)
})
})
})
})
it
(
'should show proper error for duplicate defaultLocales'
,
async
()
=>
{
nextConfig
.
write
(
`
module.exports = {
i18n: {
locales: ['en', 'fr', 'nl'],
defaultLocale: 'en',
domains: [
{
domain: 'example.com',
defaultLocale: 'en'
},
{
domain: 'fr.example.com',
defaultLocale: 'fr',
},
{
domain: 'french.example.com',
defaultLocale: 'fr',
}
]
}
}
`
)
const
{
code
,
stderr
}
=
await
nextBuild
(
appDir
,
undefined
,
{
stderr
:
true
,
})
nextConfig
.
restore
()
expect
(
code
).
toBe
(
1
)
expect
(
stderr
).
toContain
(
'Both fr.example.com and french.example.com configured the defaultLocale fr but only one can'
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment