Unverified Commit cb469ded authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

[test] Expand root-param navigation regression coverage (#98731)

This extends the coverage for #98674 to root-param reads inside nested
public caches and static-stage reuse during Cached Navigations.

The tests verify that an initial document's extracted static stage is
not reused across locales. A same-locale control verifies that reuse
still works when only a fallback parameter changes.

The cross-locale test checks the pending navigation state because the
final dynamic response can otherwise hide incorrect static-stage reuse.
parent fbe0d562
import { nextTestSetup } from 'e2e-utils'
import { join } from 'path'
import { createRouterAct } from 'router-act'
// @force-gate !dev
describe('cached navigations - root params', () => {
const { next } = nextTestSetup({
files: join(__dirname, 'root-params'),
})
it('does not reuse the initial static stage across root param values', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/en/foo', {
beforePageLoad(page) {
act = createRouterAct(page)
},
})
expect(await browser.elementById('dynamic-content').text()).toBe(
'Dynamic slug: foo'
)
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: en'
)
await act(async () => {
await browser.elementByCss('a[href="/de/foo"]').click()
// The router keeps the resolved English page visible until the German
// response arrives.
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: en'
)
expect(await browser.elementById('dynamic-boundary').text()).toBe(
'Dynamic slug: foo'
)
})
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: de'
)
expect(await browser.elementById('dynamic-content').text()).toBe(
'Dynamic slug: foo'
)
})
it('reuses the initial static stage when only a fallback param changes', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/en/foo', {
beforePageLoad(page) {
act = createRouterAct(page)
},
})
expect(await browser.elementById('dynamic-content').text()).toBe(
'Dynamic slug: foo'
)
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: en'
)
await act(async () => {
await browser.elementByCss('a[href="/en/bar"]').click()
// The router reuses the English static stage and shows a fallback until
// the new slug's dynamic content arrives.
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: en'
)
expect(await browser.elementById('dynamic-boundary').text()).toBe(
'Loading dynamic...'
)
})
expect(await browser.elementById('cached-locale').text()).toBe(
'Cached locale: en'
)
expect(await browser.elementById('dynamic-content').text()).toBe(
'Dynamic slug: bar'
)
})
})
import { locale } from 'next/root-params'
import { connection } from 'next/server'
import { Suspense } from 'react'
async function getLocale() {
'use cache'
return locale()
}
async function CachedLocale() {
'use cache'
return <p id="cached-locale">{`Cached locale: ${await getLocale()}`}</p>
}
async function DynamicContent({
params,
}: {
params: Promise<{ slug: string }>
}) {
await connection()
const { slug } = await params
return <p id="dynamic-content">{`Dynamic slug: ${slug}`}</p>
}
export default function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
return (
<>
<CachedLocale />
<div id="dynamic-boundary">
<Suspense fallback="Loading dynamic...">
<DynamicContent params={params} />
</Suspense>
</div>
</>
)
}
import type { ReactNode } from 'react'
import Link from 'next/link'
export function generateStaticParams() {
return [{ locale: 'en' }, { locale: 'de' }]
}
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>
<Link href="/de/foo" prefetch={false}>
German foo
</Link>
<Link href="/en/bar" prefetch={false}>
English bar
</Link>
{children}
</body>
</html>
)
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
cacheComponents: true,
}
export default nextConfig
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