| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,36 @@ |
| +import { LinkAccordion } from '../../../components/link-accordion' |
| + |
| +type Params = { slug?: string[] } |
| + |
| +export function generateStaticParams(): Params[] { |
| + return [{ slug: [] }, { slug: ['alpha'] }, { slug: ['beta'] }] |
| +} |
| + |
| +/** |
| + * An optional catch-all where the index (empty slug) and the named pages are |
| + * the same route. The page reads `params`, so every one of these segments |
| + * varies by `slug` — the server reports that in the response's vary params. |
| + */ |
| +export default async function DocsPage({ |
| + params, |
| +}: { |
| + params: Promise<Params> |
| +}) { |
| + const { slug } = await params |
| + const name = slug && slug.length > 0 ? slug.join('/') : 'index' |
| + return ( |
| + <div> |
| + {/* |
| + The id is slug-specific so a test can wait for the navigation to |
| + actually commit — an id shared by every slug would match the |
| + pre-navigation DOM and read stale content. |
| + |
| + One interpolated string so the text is a single node in the RSC |
| + payload, which lets the test assert on response contents. |
| + */} |
| + <div id={`docs-page-${name}`}>{`Docs: ${name}`}</div> |
| + <LinkAccordion href="/docs/alpha">alpha</LinkAccordion> |
| + <LinkAccordion href="/docs/beta">beta</LinkAccordion> |
| + </div> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,11 @@ |
| +export default function RootLayout({ |
| + children, |
| +}: { |
| + children: React.ReactNode |
| +}) { |
| + return ( |
| + <html> |
| + <body>{children}</body> |
| + </html> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,15 @@ |
| +import { LinkAccordion } from '../components/link-accordion' |
| + |
| +export default function HomePage() { |
| + return ( |
| + <div> |
| + <div id="home-page">Home</div> |
| + {/* |
| + Revealing this link prefetches /docs — the fully static index of the |
| + optional catch-all route. That prefetch is what used to poison the |
| + param-wildcard slot for every other slug. |
| + */} |
| + <LinkAccordion href="/docs">Docs index</LinkAccordion> |
| + </div> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,29 @@ |
| +'use client' |
| + |
| +import Link from 'next/link' |
| +import { useState } from 'react' |
| + |
| +export function LinkAccordion({ |
| + href, |
| + children, |
| +}: { |
| + href: string |
| + children: React.ReactNode |
| +}) { |
| + const [isVisible, setIsVisible] = useState(false) |
| + return ( |
| + <> |
| + <input |
| + type="checkbox" |
| + checked={isVisible} |
| + onChange={() => setIsVisible(!isVisible)} |
| + data-link-accordion={href} |
| + /> |
| + {isVisible ? ( |
| + <Link href={href}>{children}</Link> |
| + ) : ( |
| + <>{children} (link is hidden)</> |
| + )} |
| + </> |
| + ) |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,13 @@ |
| +/** |
| + * @type {import('next').NextConfig} |
| + */ |
| +const nextConfig = { |
| + cacheComponents: true, |
| + // Partial Prefetching enables the Shell prefetch phase, where the bug lived. |
| + partialPrefetching: true, |
| + experimental: { |
| + varyParams: process.env.TEST_VARY_PARAMS === 'true', |
| + }, |
| +} |
| + |
| +module.exports = nextConfig |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,91 @@ |
| +import { nextTestSetup } from 'e2e-utils' |
| +import type * as Playwright from 'playwright' |
| +import { createRouterAct } from 'router-act' |
| + |
| +describe.each([ |
| + ['vary params enabled', 'true'], |
| + ['vary params disabled', 'false'], |
| +])( |
| + 'segment cache - static shell vary params regression (%s)', |
| + (_, varyParams) => { |
| + const { next, isNextDev } = nextTestSetup({ |
| + files: __dirname, |
| + env: { TEST_VARY_PARAMS: varyParams }, |
| + }) |
| + |
| + if (isNextDev) { |
| + // Depends on build-time prerenders, which don't exist in dev. |
| + test('skipped in dev mode', () => {}) |
| + return |
| + } |
| + |
| + // Regression test for a segment cache keying bug. |
| + // |
| + // During the Shell prefetch phase the client walks at the StaticShell |
| + // strategy, and it used to key whatever came back at `tree.shellVaryPath`, |
| + // which replaces every non-root param with Fallback. That's only correct |
| + // when the payload really is the param-independent shell. |
| + // |
| + // When a route renders with no dynamic hole, the response has no shell/full |
| + // split — the "shell" payload IS the concrete render for the params that |
| + // were requested. Keying it at the wildcard path published one param's page |
| + // as the answer for every other param value, and recorded it at the highest |
| + // tier, so later navigations rendered the wrong page and skipped the network |
| + // entirely. |
| + // |
| + // On an optional catch-all, the index (empty slug) is the case that hits |
| + // this: prefetching /docs poisoned /docs/alpha and /docs/beta. |
| + // |
| + // The fix makes the server-reported vary params authoritative, so the shell |
| + // path is used exactly when the segment really is param-independent. |
| + it('does not serve the catch-all index page for a different slug', async () => { |
| + let page: Playwright.Page |
| + const browser = await next.browser('/', { |
| + beforePageLoad(p: Playwright.Page) { |
| + page = p |
| + }, |
| + }) |
| + const act = createRouterAct(page, { includeAppShellRequests: true }) |
| + |
| + // Prefetch the fully static index of the optional catch-all route. Its |
| + // response has no shell/full split, so this is the write that used to land |
| + // in the param-wildcard slot. |
| + await act( |
| + async () => { |
| + await browser |
| + .elementByCss('input[data-link-accordion="/docs"]') |
| + .click() |
| + }, |
| + { includes: 'Docs: index' } |
| + ) |
| + |
| + // Navigate there. Fully prefetched, so nothing should be requested. |
| + await act(async () => { |
| + await browser.elementByCss('a[href="/docs"]').click() |
| + expect(await browser.elementById('docs-page-index').text()).toBe( |
| + 'Docs: index' |
| + ) |
| + }, 'no-requests') |
| + |
| + // Now prefetch a different slug on the same route. Before the fix the |
| + // index's page segment was sitting in the wildcard slot marked complete, |
| + // so this fired no request at all for the page content and this |
| + // expectation would time out. |
| + await act( |
| + async () => { |
| + await browser |
| + .elementByCss('input[data-link-accordion="/docs/alpha"]') |
| + .click() |
| + }, |
| + { includes: 'Docs: alpha' } |
| + ) |
| + |
| + await act(async () => { |
| + await browser.elementByCss('a[href="/docs/alpha"]').click() |
| + expect(await browser.elementById('docs-page-alpha').text()).toBe( |
| + 'Docs: alpha' |
| + ) |
| + }, 'no-requests') |
| + }) |
| + } |
| +) |
|
|