Unverified Commit c54f168d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add config check for invalid duplicate locale domains (#27451)

parent ee605cb6
...@@ -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)) {
......
...@@ -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'
)
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment