Skip to content

Commit

Permalink
Updated condition and test
Browse files Browse the repository at this point in the history
  • Loading branch information
pekarja5 committed May 10, 2022
1 parent c2bac0d commit 1a8735e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/export/worker.ts
Expand Up @@ -210,7 +210,11 @@ export default async function exportPage({
req.url += '/'
}

if (buildExport && renderOpts.domainLocales) {
if (
buildExport &&
renderOpts.domainLocales &&
renderOpts.domainLocales.length > 0
) {
addRequestMeta(req, '__nextIsLocaleDomain', true)
}

Expand Down
43 changes: 43 additions & 0 deletions test/integration/i18n-support/test/shared.js
Expand Up @@ -382,6 +382,49 @@ export function runTests(ctx) {
}
})

// The page is accessible on subpath as well as on the domain url without subpath.
// Once this is not the case the test will need to be changed to access it via domain.
// Beware of the different expectations on dev and prod version since the pre-rendering on dev does not work with domain locales
it('should prerender with the correct href for locale domain', async () => {
let browser = await webdriver(ctx.appPort, `${ctx.basePath || ''}/go`)

for (const [element, pathname] of [
['#to-another', '/another'],
['#to-gsp', '/gsp'],
['#to-fallback-first', '/gsp/fallback/first'],
['#to-fallback-hello', '/gsp/fallback/hello'],
['#to-gssp', '/gssp'],
['#to-gssp-slug', '/gssp/first'],
]) {
const href = await browser.elementByCss(element).getAttribute('href')
if (ctx.isDev) {
expect(href).toBe(`${ctx.basePath || ''}/go${pathname}`)
} else {
expect(href).toBe(`https://example.com${ctx.basePath || ''}${pathname}`)
}
}

browser = await webdriver(ctx.appPort, `${ctx.basePath || ''}/go-BE`)

for (const [element, pathname] of [
['#to-another', '/another'],
['#to-gsp', '/gsp'],
['#to-fallback-first', '/gsp/fallback/first'],
['#to-fallback-hello', '/gsp/fallback/hello'],
['#to-gssp', '/gssp'],
['#to-gssp-slug', '/gssp/first'],
]) {
const href = await browser.elementByCss(element).getAttribute('href')
if (ctx.isDev) {
expect(href).toBe(`${ctx.basePath || ''}/go-BE${pathname}`)
} else {
expect(href).toBe(
`https://example.com${ctx.basePath || ''}/go-BE${pathname}`
)
}
}
})

it('should render the correct href with locale domains but not on a locale domain', async () => {
let browser = await webdriver(
ctx.appPort,
Expand Down

0 comments on commit 1a8735e

Please sign in to comment.