Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix splitting page path by buildId #19901

Merged
merged 4 commits into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -1401,9 +1401,11 @@ export default class Server {

const stripNextDataPath = (path: string) => {
if (path.includes(this.buildId)) {
path = denormalizePagePath(
(path.split(this.buildId).pop() || '/').replace(/\.json$/, '')
const splitPath = path.substring(
path.indexOf(this.buildId) + this.buildId.length
)

path = denormalizePagePath(splitPath.replace(/\.json$/, ''))
}

if (this.nextConfig.i18n) {
Expand Down
@@ -0,0 +1,33 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function Page(props) {
const router = useRouter()

return (
<>
<p id="developments">developments page</p>
<p id="props">{JSON.stringify(props)}</p>
<p id="router-locale">{router.locale}</p>
<p id="router-default-locale">{router.defaultLocale}</p>
<p id="router-locales">{JSON.stringify(router.locales)}</p>
<p id="router-query">{JSON.stringify(router.query)}</p>
<p id="router-pathname">{router.pathname}</p>
<p id="router-as-path">{router.asPath}</p>
<Link href="/">
<a id="to-index">to /</a>
</Link>
<br />
</>
)
}

export const getServerSideProps = ({ locale, locales, defaultLocale }) => {
return {
props: {
locale,
locales,
defaultLocale,
},
}
}
33 changes: 33 additions & 0 deletions test/integration/i18n-support/pages/developments/index.js
@@ -0,0 +1,33 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function Page(props) {
const router = useRouter()

return (
<>
<p id="developments">developments page</p>
<p id="props">{JSON.stringify(props)}</p>
<p id="router-locale">{router.locale}</p>
<p id="router-default-locale">{router.defaultLocale}</p>
<p id="router-locales">{JSON.stringify(router.locales)}</p>
<p id="router-query">{JSON.stringify(router.query)}</p>
<p id="router-pathname">{router.pathname}</p>
<p id="router-as-path">{router.asPath}</p>
<Link href="/">
<a id="to-index">to /</a>
</Link>
<br />
</>
)
}

export const getServerSideProps = ({ locale, locales, defaultLocale }) => {
return {
props: {
locale,
locales,
defaultLocale,
},
}
}
30 changes: 30 additions & 0 deletions test/integration/i18n-support/test/shared.js
Expand Up @@ -37,6 +37,36 @@ async function addDefaultLocaleCookie(browser) {
}

export function runTests(ctx) {
it('should navigate to page with same name as development buildId', async () => {
const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`)

await browser.eval(`(function() {
window.beforeNav = 1
window.next.router.push('/developments')
})()`)

await browser.waitForElementByCss('#developments')
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(await browser.elementByCss('#router-locale').text()).toBe('en-US')
expect(await browser.elementByCss('#router-default-locale').text()).toBe(
'en-US'
)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/developments'
)
expect(await browser.elementByCss('#router-as-path').text()).toBe(
'/developments'
)
expect(
JSON.parse(await browser.elementByCss('#router-query').text())
).toEqual({})
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
locales,
locale: 'en-US',
defaultLocale: 'en-US',
})
})

it('should redirect to locale domain correctly client-side', async () => {
const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`)

Expand Down