prefix stringlengths 512 512 | suffix stringlengths 256 256 | middle stringlengths 14 229 | meta dict |
|---|---|---|---|
() => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should match default and dynamic segment paths before catch-all', async () => {
let browser = await next.browser('/en/catchall/page')
// we have a top-level catch-all
expect(await browser.elementById('children').text()).toBe(
... | ct(await browser.elementById('slot0').text()).toBe(
'/[locale]/nested/@slot0/default.tsx'
)
// since there is a default defined in @slot1, we expect that to match
expect(await browser.elementById('slot1').text()).toBe(
'/[locale]/n | re is a page defined to be matched
expect(await browser.elementById('nested-children').text()).toBe(
'/[locale]/nested/page.tsx'
)
// since there is a default defined in @slot0, we expect that to match
expe | {
"filepath": "test/e2e/app-dir/parallel-routes-catchall-slotted-non-catchalls/parallel-routes-catchall-slotted-non-catchalls.test.ts",
"language": "typescript",
"file_size": 3617,
"cut_index": 614,
"middle_length": 229
} |
ype Playwright } from 'e2e-utils'
describe('parallel-routes-catchall-css', () => {
const { next } = nextTestSetup({
files: __dirname,
})
async function getChildrenBackgroundColor(browser: Playwright) {
return browser.eval(
`window.getComputedStyle(document.getElementById('main')).backgroundColor`
... | oBe('rgb(0, 0, 255)')
expect(await browser.elementByCss('title').text()).toBe('Home Page')
expect(await browser.elementsByCss('title')).toHaveLength(1)
// navigate to the page that matches a parallel route
await browser.elementByCss("[hre | it('should properly load the Head content from multiple leaf segments', async () => {
const browser = await next.browser('/')
// the page background should be blue
expect(await getChildrenBackgroundColor(browser)).t | {
"filepath": "test/e2e/app-dir/parallel-routes-css/parallel-routes-css.test.ts",
"language": "typescript",
"file_size": 1978,
"cut_index": 537,
"middle_length": 229
} |
as useAppRouter,
useSearchParams,
} from 'next/navigation'
import { useState, useEffect } from 'react'
export const RouterHooksFixtures = () => {
const pagesRouter = usePagesRouter()
const appRouter = useAppRouter()
const searchParams = useSearchParams()
const pathname = usePathname()
const [value, setVal... | }
return (
<div id={pagesRouter.isReady ? 'router-ready' : 'router-not-ready'}>
<div id="key-value">Value:{value}</div>
<div id="pathname">{pathname}</div>
<button type="button" onClick={onClick}>
Push
</button>
| () => {
appRouter.push('/adapter-hooks/pushed')
| {
"filepath": "test/e2e/app-dir/hooks/components/router-hooks-fixtures.js",
"language": "javascript",
"file_size": 928,
"cut_index": 606,
"middle_length": 52
} |
te { foo: [32m'just-some-object'[39m }
Error: :::0:err::: /console: test
at ConsolePage (app/console/page.tsx:<line>:<col>)
[0m [90m 40 |[39m })
[90m 41 |[39m [36mawait[39m [35m1[39m
[31m[1m>[22m[39m[90m 42 |[39m console[33m.[39merror([36mnew[39m [33mE... | [32m'just-some-object'[39m }
Assertion failed: :::0:err::: /console: This is an assert message with a template
[0m[7m Cache [0m :::0:err::: /console: not a template { foo: [32m'just-some-object'[39m }
Assertion failed: [0m[7m C | console[33m.[39massert(
[90m 45 |[39m [36mfalse[39m[33m,[39m[0m
Assertion failed: :::0:err::: /console: This is an assert message with a template
:::0:err::: /console: not a template { foo: | {
"filepath": "test/e2e/app-dir/cache-components-console/cache-components.console.test.ts",
"language": "typescript",
"file_size": 45942,
"cut_index": 2151,
"middle_length": 229
} |
oleCalls(outBadge: string, errBadge: string) {
'use cache'
console.info(`${outBadge} /console: template(one: %s, two: %s)`, 'one', 'two')
await 1
console.log(
`${outBadge} /console: This is a console page` +
". Don't match the codeframe."
)
await 1
console.warn(`${errBadge} /console: not a templ... |
let i = 0
export default async function ConsolePage() {
const outBadge = `:::${i}:out:::`
const errBadge = `:::${i++}:err:::`
console.info(`${outBadge} /console: template(one: %s, two: %s)`, 'one', 'two')
await 1
console.log(
`${outBadge} / | : test'))
console.assert(
false,
`${errBadge} /console: This is an assert message with a %s`,
'template'
)
console.assert(
true,
`${errBadge} /console: This is an assert message without a template`
)
} | {
"filepath": "test/e2e/app-dir/cache-components-console/fixtures/default/app/console/page.tsx",
"language": "tsx",
"file_size": 1569,
"cut_index": 537,
"middle_length": 229
} |
oleCalls(outBadge: string, errBadge: string) {
'use cache'
console.info(`${outBadge} /console: template(one: %s, two: %s)`, 'one', 'two')
await 1
console.log(
`${outBadge} /console: This is a console page` +
". Don't match the codeframe."
)
await 1
console.warn(`${errBadge} /console: not a templ... |
let i = 0
export default async function ConsolePage() {
const outBadge = `:::${i}:out:::`
const errBadge = `:::${i++}:err:::`
console.info(`${outBadge} /console: template(one: %s, two: %s)`, 'one', 'two')
await 1
console.log(
`${outBadge} / | : test'))
console.assert(
false,
`${errBadge} /console: This is an assert message with a %s`,
'template'
)
console.assert(
true,
`${errBadge} /console: This is an assert message without a template`
)
} | {
"filepath": "test/e2e/app-dir/cache-components-console/fixtures/hide-logs-after-abort/app/console/page.tsx",
"language": "tsx",
"file_size": 1569,
"cut_index": 537,
"middle_length": 229
} |
nv jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: undefined },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
implementation: 'sass-embedded',
},... | rectly', async () => {
const browser = await next.browser('/post-1')
const background = await browser
.elementByCss('#my-div')
.getComputedCss('background-color')
expect(background).toMatch(colorToRgb('red'))
})
}
| nextConfig,
})
it('should apply styles cor | {
"filepath": "test/e2e/app-dir/scss/dynamic-route-module/dynamic-route-module.test.ts",
"language": "typescript",
"file_size": 833,
"cut_index": 523,
"middle_length": 52
} |
* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: undefined },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
implementation: 'sass-embedded'... | nextConfig,
})
it('should render the module', async () => {
const browser = await next.browser('/post')
expect(
await browser.elementByCss('#my-div').getComputedCss('background-color')
).toBe(colorToRgb('red'))
})
} | encies,
| {
"filepath": "test/e2e/app-dir/scss/catch-all-module/catch-all-module.test.ts",
"language": "typescript",
"file_size": 786,
"cut_index": 513,
"middle_length": 14
} |
ext-test-utils'
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: undefined },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
implementation: 'sass-embedded',
},
},
},
])(
'CSS Module Composes Usage (External) ($dependencies)',
({ dep... | (
await browser.elementByCss('#verify-yellow').getComputedCss('color')
).toBe(colorToRgb('yellow'))
expect(
await browser
.elementByCss('#verify-yellow')
.getComputedCss('background-color')
).toBe(color | const browser = await next.browser('/')
expect | {
"filepath": "test/e2e/app-dir/scss/composes-external/composes-external.test.ts",
"language": "typescript",
"file_size": 942,
"cut_index": 606,
"middle_length": 52
} |
t nextConfig = {
turbopack: {
resolveAlias: {
'/*': './*',
'~*': '*',
},
},
}
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
...nextConfig,
sassOptions: {
implementation: 'sass-embedd... | nprogress: '0.2.0',
},
nextConfig,
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser
.elementByCss('#nprogress .bar')
.getComputedC | e,
dependencies: {
...dependencies,
| {
"filepath": "test/e2e/app-dir/scss/npm-import-tilde/npm-import-tilde.test.ts",
"language": "typescript",
"file_size": 960,
"cut_index": 582,
"middle_length": 52
} |
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('SCSS Support', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
// Production only test
;(isNextDev ? describe.skip : describe)('Friendly Webpack Error', () => {
... | de your workspace.'
)
expect(cliOutput).toContain(
'Learn more: https://nextjs.org/docs/messages/install-sass'
)
expect(cliOutput).not.toContain('css-loader')
expect(cliOutput).not.toContain('sass-loader')
})
}) | yles/global.scss')
expect(cliOutput).toContain(
"To use Next.js' built-in Sass support, you first need to install `sass`."
)
expect(cliOutput).toContain(
'Run `npm i sass` or `yarn add sass` insi | {
"filepath": "test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts",
"language": "typescript",
"file_size": 1001,
"cut_index": 512,
"middle_length": 229
} |
- draft mode', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
async function runTests({ basePath = '/' }: { basePath: string }) {
let origRandHome = 'unintialized'
let origRandWithCookies = 'unintialized'
let Cookie = ''
it(`should use initial rand when draft mode ... | ').text()).toBe('DISABLED')
expect($('#rand').text()).toBeDefined()
expect($('#data').text()).toBe('')
origRandWithCookies = $('#rand').text()
})
if (!isNextDev) {
if (basePath === '/') {
it('should not generate ran | origRandHome = $('#rand').text()
})
it(`should use initial rand when draft mode is disabled on ${basePath}with-cookies`, async () => {
const $ = await next.render$(`${basePath}with-cookies`)
expect($('#mode | {
"filepath": "test/e2e/app-dir/draft-mode/draft-mode.test.ts",
"language": "typescript",
"file_size": 4342,
"cut_index": 614,
"middle_length": 229
} |
Value: test')
// One more time!
await browser.elementByCss('input').type('another')
await browser.elementByCss('button').click()
const newLoading = await browser.waitForElementByCss('#loading')
expect(await newLoading.text()).toBe('Loading...')
const newSearchValue = await browser.waitForEle... | ":"1"}')
})
it('should reflect the correct searchParams when re-using the same page segment', async () => {
const browser = await next.browser('/')
await browser.elementByCss("[href='/params-first']").click()
await browser.elementByCss("[h | () => {
const browser = await next.browser('/search-params')
await browser.elementByCss("[href='/?id=1']").click()
const params = await browser.waitForElementByCss('#root-params').text()
expect(params).toBe('{"id | {
"filepath": "test/e2e/app-dir/searchparams-reuse-loading/searchparams-reuse-loading.test.ts",
"language": "typescript",
"file_size": 22794,
"cut_index": 1331,
"middle_length": 229
} |
lient'
import { useSearchParams, ReadonlyURLSearchParams } from 'next/navigation'
import { useSyncExternalStore } from 'react'
export default function Page() {
const searchParams = useSearchParams()
const searchParamsClient = useSyncExternalStore(
() => {
return () => {}
},
() => {
return ... |
client:{' '}
<span data-testid="client">
{searchParamsClient === null
? '<pending>'
: searchParamsClient instanceof ReadonlyURLSearchParams
? 'PASS instanceof check'
: `FAILED R | arams instanceof ReadonlyURLSearchParams
? 'PASS instanceof check'
: `FAILED Received: "${String(searchParams)}" instead instanceof ${searchParams.constructor.name}`}
</span>
</li>
<li> | {
"filepath": "test/e2e/app-dir/hooks/app/hooks/use-search-params/instanceof/page.js",
"language": "javascript",
"file_size": 1148,
"cut_index": 518,
"middle_length": 229
} |
ion cachedConsoleCalls(outBadge: string, errBadge: string) {
'use cache'
console.info(
`${outBadge} /console-after-abort/server: template(one: %s, two: %s)`,
'one',
'two'
)
console.log(
`${outBadge} /console-after-abort/server: This is a console page` +
". Don't match the codeframe."
)
... | ssert(
true,
`${errBadge} /console-after-abort/server: This is an assert message without a template`
)
}
let i = 0
export default async function ConsolePage() {
const outBadge = `:::${i}:out:::`
const errBadge = `:::${i++}:err:::`
console | Cache environment.
// console.error(new Error('/console-after-abort/server: test'))
console.assert(
false,
`${errBadge} /console-after-abort/server: This is an assert message with a %s`,
'template'
)
console.a | {
"filepath": "test/e2e/app-dir/cache-components-console/fixtures/default/app/console-after-abort/server/page.tsx",
"language": "tsx",
"file_size": 2218,
"cut_index": 563,
"middle_length": 229
} |
from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
const sassOptions = {
prependData: `
$var: red;
`,
}
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: { sassOptions } },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
...sassOp... | s,
nextConfig,
})
it('should render the module', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
}
) | estSetup({
files: __dirname,
dependencie | {
"filepath": "test/e2e/app-dir/scss/basic-module-prepend-data/basic-module-prepend-data.test.ts",
"language": "typescript",
"file_size": 868,
"cut_index": 559,
"middle_length": 52
} |
int-env jest */
import { nextTestSetup } from 'e2e-utils'
import { colorToRgb } from 'next-test-utils'
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: undefined },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
implementation: 'sass-embedded',
... | es,
nextConfig,
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('#verify-red').getComputedCss('color')
).toBe(colorToRgb('red'))
})
}
)
| dependenci | {
"filepath": "test/e2e/app-dir/scss/prod-module/prod-module.test.ts",
"language": "typescript",
"file_size": 788,
"cut_index": 518,
"middle_length": 14
} |
{ pathname: '/adapter-hooks/static' },
{ pathname: '/adapter-hooks/1' },
{ pathname: '/adapter-hooks/2' },
{ pathname: '/adapter-hooks/1/account' },
{ pathname: '/adapter-hooks/static', keyValue: 'value' },
{ pathname: '/adapter-hooks/1', keyValue: 'value' },
{ pathname: '/adapt... | 'key-value').text()).toBe(
`Value:${keyValue}`
)
expect(await browser.elementById('pathname').text()).toBe(pathname)
await browser.elementByCss('button').click()
await browser.waitForElementByCss('#pushed', { stat | ue = '' }) => {
const browser = await next.browser(
pathname + (keyValue ? `?key=${keyValue}` : '')
)
await browser.waitForElementByCss('#router-ready')
expect(await browser.elementById( | {
"filepath": "test/e2e/app-dir/hooks/hooks.test.ts",
"language": "typescript",
"file_size": 7691,
"cut_index": 716,
"middle_length": 229
} |
port { nextTestSetup } from 'e2e-utils'
import { colorToRgb, getUrlFromBackgroundImage } from 'next-test-utils'
// TODO: Skipped as this test should set up the server to handle assetPrefix which it currently does not do.
describe.skip('SCSS Support loader handling', () => {
describe.each([
{ dependencies: { sass... | extConfig,
})
it('should render the page', async () => {
const browser = await next.browser('/')
expect(
await browser.elementByCss('.red-text').getComputedCss('color')
).toBe(colorToRgb('red'))
const |
},
},
])(
'CSS URL via `file-loader` and asset prefix (1) ($dependencies)',
({ dependencies, nextConfig }) => {
const { next } = nextTestSetup({
files: __dirname,
dependencies,
n | {
"filepath": "test/e2e/app-dir/scss/url-global-asset-prefix-1/url-global-asset-prefix-1.test.ts",
"language": "typescript",
"file_size": 1567,
"cut_index": 537,
"middle_length": 229
} |
port { nextTestSetup } from 'e2e-utils'
import { colorToRgb, retry } from 'next-test-utils'
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig: undefined },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
sassOptions: {
implementation: 'sass-embedded',
},
},... | ser('/')
const desiredText = 'hello world'
await browser.elementById('text-input').type(desiredText)
expect(await browser.elementById('text-input').getValue()).toBe(
desiredText
)
expect(
await | dependencies,
nextConfig,
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should update CSS color without remounting <input>', async () => {
const browser = await next.brow | {
"filepath": "test/e2e/app-dir/scss/hmr-module/hmr-module.test.ts",
"language": "typescript",
"file_size": 1602,
"cut_index": 537,
"middle_length": 229
} |
tTestSetup } from 'e2e-utils'
describe('webpack-loader-module-type', () => {
const { next, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) return
// bytes type is Turbopack-only, webpack doesn't have a direct equivalent
const itTurbopackOnly = isTurb... | async () => {
const $ = await next.render$('/')
const bytesType = $('#bytes-type').text()
const bytesLength = $('#bytes-length').text()
const bytesText = $('#bytes-text').text()
// eslint-disable-next-line jest/no-standalone- | ould emit the file and return URL path
expect(src).toMatch(
/\/_next\/static\/(immutable\/)?media\/test\.[0-9a-z_-]+\.svg$/
)
})
itTurbopackOnly(
'should load data file as bytes and return Uint8Array',
| {
"filepath": "test/e2e/app-dir/webpack-loader-module-type/webpack-loader-module-type.test.ts",
"language": "typescript",
"file_size": 1273,
"cut_index": 524,
"middle_length": 229
} |
e client'
import { use } from 'react'
function log(outBadge: string, errBadge: string) {
console.info(
`${outBadge} /console-after-abort/client: template(one: %s, two: %s)`,
'one',
'two'
)
console.log(
`${outBadge} /console-after-abort/client: This is a console page. Don't match the codeframe.`
... | without a template`
)
}
export default function ClientConsolePage({
data,
outBadge,
errBadge,
}: {
data: Promise<any>
outBadge: string
errBadge: string
}) {
console.log(
`${outBadge} /console-after-abort/client: logging before prerend | console.assert(
false,
`${errBadge} /console-after-abort/client: This is an assert message with a %s`,
'template'
)
console.assert(
true,
`${errBadge} /console-after-abort/client: This is an assert message | {
"filepath": "test/e2e/app-dir/cache-components-console/fixtures/default/app/console-after-abort/client/client.tsx",
"language": "tsx",
"file_size": 1117,
"cut_index": 515,
"middle_length": 229
} |
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/', {
beforePageLoad(page) {
act = createRouterAct(page)
},
})
await act(
async () => {
// Reveal the link to trigger a prefetch, but block the responses.
const link = await act(async ... | 'Dynamic in nav',
}
)
// The static and dynamic content appears simultaneously because everything
// was fetched as part of the same navigation request.
const nav = await browser.elementById('nav')
expect( | // While the prefetches are blocked, navigate to the test page.
await act(
async () => {
// Navigate to the test page
await link.click()
},
{
includes: | {
"filepath": "test/e2e/app-dir/segment-cache/basic/segment-cache-basic.test.ts",
"language": "typescript",
"file_size": 14989,
"cut_index": 921,
"middle_length": 229
} |
pe * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
/**
* When a dynamic param contains a percent-encoded forward slash (`%2F`), the
* client double-encodes the URL part when deriving its segment cache key, while
* the server encodes the decoded value once. The resulting segment mismat... | ms', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled in dev mode', () => {})
return
}
describe.each([
{ label: 'unencoded param', href: '/foo' },
{ labe | The fixture is intentionally fully dynamic (no `generateStaticParams`): a
* statically prerendered file is served from the CDN without the `%2F`
* round-trip the bug depends on.
*/
describe('segment cache - encoded slash para | {
"filepath": "test/e2e/app-dir/segment-cache/encoded-slash-params/encoded-slash-params.test.ts",
"language": "typescript",
"file_size": 2865,
"cut_index": 563,
"middle_length": 229
} |
in development / deployment', () => {})
return
}
let port = -1
let server
let dataVersions = new Map()
let TestLog = createTestLog()
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})
beforeAll(async () => {
port = await findPort()
server = createTestDataServe... | ' + key)
res.resolve(response)
})
server.listen(port)
next.env.TEST_DATA_SERVICE_URL = `http://localhost:${port}`
await next.start()
})
beforeEach(async () => {
dataVersions = new Map()
TestLog = createTestLog()
})
| ion = currentVersion === undefined ? 1 : currentVersion + 1
dataVersions.set(key, nextVersion)
// Append the version number to the response
const response = `${key} [${nextVersion}]`
TestLog.log('REQUEST: | {
"filepath": "test/e2e/app-dir/segment-cache/revalidation/segment-cache-revalidation.test.ts",
"language": "typescript",
"file_size": 13977,
"cut_index": 921,
"middle_length": 229
} |
'next/link'
import Form from 'next/form'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = us... | dren,
prefetch,
}: {
action: string
children: React.ReactNode
prefetch?: null | false
}) {
const [isVisible, setIsVisible] = useState(false)
return (
<>
<input
type="checkbox"
checked={isVisible}
onChange={() = | {isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
<>{children} (link is hidden)</>
)}
</>
)
}
export function FormAccordion({
action,
chil | {
"filepath": "test/e2e/app-dir/segment-cache/revalidation/components/link-accordion.tsx",
"language": "tsx",
"file_size": 2911,
"cut_index": 563,
"middle_length": 229
} |
alidatePath, updateTag } from 'next/cache'
import {
LinkAccordion,
FormAccordion,
ManualPrefetchLinkAccordion,
} from '../components/link-accordion'
import Link from 'next/link'
export default async function Page() {
return (
<>
<form>
<button
id="revalidate-by-path"
formA... | <li>
<LinkAccordion href="/greeting">
Link to target page with prefetching enabled
</LinkAccordion>
</li>
<li>
<FormAccordion action="/greeting">
Form pointing to target page with prefet | revalidate-by-tag"
formAction={async function () {
'use server'
updateTag('random-greeting')
}}
>
Revalidate by tag
</button>
</form>
<ul>
| {
"filepath": "test/e2e/app-dir/segment-cache/revalidation/app/page.tsx",
"language": "tsx",
"file_size": 1458,
"cut_index": 524,
"middle_length": 229
} |
k-accordion'
export default function RefetchOnNewBaseTreeLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<>
<div style={{ backgroundColor: 'lightgray', padding: '1rem' }}>
<p>
This demonstrates what happens when a link is prefetched using{' '}
<code>{'prefetc... | etch for
this link will be empty, because there's no delta between the base
tree and the target tree.
</p>
<p>
However, if you then navigate to page B, we should re-prefetch the
link to A, because the |
Everything in this gray section is part of a shared layout. The links
below are prefetched using <code>{'prefetch={true}'}</code>. If the
first loaded page is "/refetch-on-new-base-tree/a", the pref | {
"filepath": "test/e2e/app-dir/segment-cache/revalidation/app/refetch-on-new-base-tree/layout.tsx",
"language": "tsx",
"file_size": 2289,
"cut_index": 563,
"middle_length": 229
} |
ort { LinkAccordion } from './link-accordion'
export default function Page() {
return (
<>
<ul>
<li>
<LinkAccordion prefetch={true} href="/page-with-dynamic-head">
Page with dynamic head (prefetch=true)
</LinkAccordion>
</li>
<li>
<LinkAccor... | prefetch=true)
</LinkAccordion>
</li>
<li>
<LinkAccordion
prefetch={true}
href="/rewrite-to-page-with-runtime-prefetchable-head"
>
Rewrite to page with runtime-prefetchable h | </li>
</ul>
<hr />
<ul>
<li>
<LinkAccordion
prefetch={true}
href="/page-with-runtime-prefetchable-head"
>
Page with runtime-prefetchable head ( | {
"filepath": "test/e2e/app-dir/segment-cache/metadata/app/page.tsx",
"language": "tsx",
"file_size": 1087,
"cut_index": 515,
"middle_length": 229
} |
use cache'
import { cacheTag } from 'next/cache'
import { Suspense } from 'react'
const TEST_DATA_SERVICE_URL = process.env.TEST_DATA_SERVICE_URL
const ARTIFICIAL_DELAY = 3000
async function Greeting() {
cacheTag('random-greeting')
if (!TEST_DATA_SERVICE_URL) {
// If environment variable is not set, resolve ... | t = await response.text()
if (response.status !== 200) {
throw new Error(text)
}
return (
<>
<h1>Greeting</h1>
<div id="greeting">{text}</div>
</>
)
}
export default async function Page() {
return (
<Suspense fallback | e(), ARTIFICIAL_DELAY)
)
// Return a random greeting
return ['Hello', 'Hi', 'Hey', 'Howdy'][Math.floor(Math.random() * 4)]
}
const response = await fetch(TEST_DATA_SERVICE_URL + '?key=random-greeting')
const tex | {
"filepath": "test/e2e/app-dir/segment-cache/revalidation/app/greeting/page.tsx",
"language": "tsx",
"file_size": 1054,
"cut_index": 513,
"middle_length": 229
} |
ort function middleware(request: NextRequest) {
if (request.nextUrl.pathname.startsWith('/search-params/target-page')) {
const searchParam = request.nextUrl.searchParams.get('searchParam')
if (
searchParam === 'rewritesToANewSearchParam' ||
searchParam === 'alsoRewritesToThatSameSearchParam'
)... | eeting')) {
return NextResponse.rewrite(
new URL('/search-params?greeting=hello', request.url)
)
}
if (request.nextUrl.pathname.startsWith('/search-params-with-no-greeting')) {
return NextResponse.rewrite(new URL('/search-params', re | .nextUrl.pathname.startsWith('/search-params-with-gr | {
"filepath": "test/e2e/app-dir/segment-cache/search-params/middleware.ts",
"language": "typescript",
"file_size": 932,
"cut_index": 606,
"middle_length": 52
} |
createRouterAct } from 'router-act'
describe('segment cache (search params shared loading state)', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled', () => {})
return
}
it(
"if there's no matching prefetch entry for a pag... | // Reveal and prefetch the link without search params
const revealFirstLink = await browser.elementByCss(
'input[data-link-accordion="/search-params-shared-loading-state/target-page"]'
)
await act(
async () => {
| typeof createRouterAct>
const browser = await next.browser(
'/search-params-shared-loading-state',
{
beforePageLoad(page) {
act = createRouterAct(page)
},
}
)
| {
"filepath": "test/e2e/app-dir/segment-cache/search-params/segment-cache-search-params-shared-loading-state.test.ts",
"language": "typescript",
"file_size": 2743,
"cut_index": 563,
"middle_length": 229
} |
arams in the cache key', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/search-params', {
beforePageLoad(page) {
act = createRouterAct(page)
},
})
// Prefetch a page with search param `a_PPR`.
const revealA = await browser.elementB... | // Prefetch the same page but with the search param changed to `c_PPR`.
const revealC = await browser.elementByCss(
'input[data-link-accordion="/search-params/target-page?searchParam=c_PPR"]'
)
await act(
async () => {
aw | ll include a shell of the page, but nothing that is
// based on the search param.
{
includes:
// This is the id assigned to a container div
'target-page-with-search-param',
}
)
| {
"filepath": "test/e2e/app-dir/segment-cache/search-params/segment-cache-search-params.test.ts",
"language": "typescript",
"file_size": 9774,
"cut_index": 921,
"middle_length": 229
} |
rt default function SearchParamsPage({
searchParams,
}: {
searchParams: Promise<{ greeting?: string }>
}) {
return (
<>
<p>
Demonstrates that we can prefetch a page that reads from search params
</p>
<ul>
<li>
<LinkAccordion href="/search-params/target-page?searchPa... | rchParam=c_PPR
</LinkAccordion>
</li>
<li>
<LinkAccordion
prefetch={true}
href="/search-params/target-page?searchParam=d_full"
>
searchParam=d_full, prefetch={true}
| e?searchParam=b_full"
>
searchParam=b_full, prefetch={true}
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/search-params/target-page?searchParam=c_PPR">
sea | {
"filepath": "test/e2e/app-dir/segment-cache/search-params/app/search-params/page.tsx",
"language": "tsx",
"file_size": 3441,
"cut_index": 614,
"middle_length": 229
} |
{import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
experimental: {
optimisticRouting: true,
varyParams: true,
},
// Each rewrite below crafts one of the rewrite-affected response shapes
// we want to verify. They live in `beforeFiles` so they take precedence
// over the fil... | hrough the dynamic /[teamSlug] route.
{ source: '/featured', destination: '/some-team' },
// Case "static-visible-null": URL is shorter than the response,
// and the deeper segment is a visible static segment.
{ source: '/te | // never observe the rewrite-affected response shape under test.
async rewrites() {
return {
beforeFiles: [
// Case "static-sibling": URL matches a known static sibling, but
// the rewrite sends it t | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-routing-rewrite-detection-regression/next.config.js",
"language": "javascript",
"file_size": 1259,
"cut_index": 524,
"middle_length": 229
} |
'
describe('optimistic routing - rewrite detection regression', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
// Optimistic routing is a production-build feature; in dev mode the
// router does not have complete information about which routes
// exist,... | URLs of the same dynamic shape would receive an incorrect
// "free" prediction and could render a stale loading state
// instantly.
// 2. Reveal one of the click-target links (prefetch={false}).
// 3. Click it inside an act scope. With the b | a a rewrite. The
// response describes a route shape the URL would not naturally
// route to. The router must not learn from this response as a
// prediction template — otherwise future navigations to other
// | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-routing-rewrite-detection-regression/optimistic-routing-rewrite-detection-regression.test.ts",
"language": "typescript",
"file_size": 5012,
"cut_index": 614,
"middle_length": 229
} |
kAccordion } from '../components/link-accordion'
export default function Home() {
return (
<main>
<h1>HOME</h1>
<ul>
{/* The four prefetch URLs below each arrive via a rewrite that
produces a route shape the URL would not naturally route to.
Each test reveals one of th... | <LinkAccordion href="/team-shorter">
Static-visible-null
</LinkAccordion>
</li>
{/* Click target — prefetch={false} so revealing it fires no
request. Inside an act scope, the test clicks this and | earned. */}
<li>
<LinkAccordion href="/myteam/garbage">Tree-shorter</LinkAccordion>
</li>
<li>
<LinkAccordion href="/featured">Static-sibling</LinkAccordion>
</li>
<li>
| {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-routing-rewrite-detection-regression/app/page.tsx",
"language": "tsx",
"file_size": 1353,
"cut_index": 524,
"middle_length": 229
} |
uspense } from 'react'
import { connection } from 'next/server'
async function DynamicOverview({
params,
}: {
params: Promise<{ teamSlug: string }>
}) {
await connection()
const { teamSlug } = await params
return (
<h1 id="overview-page" data-slug={teamSlug}>
Overview: {teamSlug}
</h1>
)
}
/... | t.
export default function OverviewPage({
params,
}: {
params: Promise<{ teamSlug: string }>
}) {
return (
<main>
<Suspense fallback={<div id="team-loading">Loading team...</div>}>
<DynamicOverview params={params} />
</Suspens | part to feed i | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-routing-rewrite-detection-regression/app/[teamSlug]/overview/page.tsx",
"language": "tsx",
"file_size": 815,
"cut_index": 522,
"middle_length": 14
} |
from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('dynamic on hover', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled', () => {})
return
}
it('prefetches the... | Reveal the link to start prefetching. Since the link has not been hovered
// yet, the prefetch only includes static data.
await act(async () => {
await linkVisibilityToggle.click()
await browser.elementByCss('a[href="/dynamic"]')
}, | act = createRouterAct(p)
},
})
// This Link's unstable_dynamicOnHover prop is set to true
const linkVisibilityToggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic"]'
)
// | {
"filepath": "test/e2e/app-dir/segment-cache/dynamic-on-hover/dynamic-on-hover.test.ts",
"language": "typescript",
"file_size": 1871,
"cut_index": 537,
"middle_length": 229
} |
inkProps } from 'next/link'
import { useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
unstable_dynamicOnHover,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
unstable_dynamicOnHover?: boolean
}) {
const [isVisible, setIsVisible] = useStat... | prefetch={prefetch}
// @ts-expect-error - unstable_dynamicOnHover is not part of the public types
unstable_dynamicOnHover={unstable_dynamicOnHover}
>
{children}
</Link>
) : (
<>{children} | {isVisible ? (
<Link
href={href}
| {
"filepath": "test/e2e/app-dir/segment-cache/dynamic-on-hover/components/link-accordion.tsx",
"language": "tsx",
"file_size": 899,
"cut_index": 547,
"middle_length": 52
} |
from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('segment cache - stale search params on replace regression', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('skipped in dev mode', () => {})
return
}
// Regression test for https://... | ge-2">` — navigates to /dummy-page-2.
// 5. Click the button that calls `router.replace('/')`.
//
// Expected: URL is `/` with no search string.
// Buggy: URL becomes `/?query=param` — the search string from the
// original page load i | :
//
// 1. Build and start the application.
// 2. Open `/?query=param` directly in the browser (full page load).
// 3. Click `<Link href="/dummy-page-1">` — navigates to /dummy-page-1.
// 4. Click `<Link href="/dummy-pa | {
"filepath": "test/e2e/app-dir/segment-cache/stale-search-params-on-replace-regression/stale-search-params-on-replace-regression.test.ts",
"language": "typescript",
"file_size": 1735,
"cut_index": 537,
"middle_length": 229
} |
eRouterAct } from 'router-act'
describe('force stale', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled in dev', () => {})
return
}
it(
'during a navigation, don\'t request segments that have a pending "full" ' +
'p... | dynamic content.
const toggleLinkVisibility = await browser.elementByCss(
'input[data-link-accordion="/dynamic"]'
)
await act(async () => await toggleLinkVisibility.click(), {
includes: 'Dynamic page c | act = createRouterAct(p)
},
})
await act(
async () => {
// Reveal a link to a dynamic page. The Link has prefetch={true}, so the
// full page data is prefetched, including | {
"filepath": "test/e2e/app-dir/segment-cache/force-stale/force-stale.test.ts",
"language": "typescript",
"file_size": 3452,
"cut_index": 614,
"middle_length": 229
} |
t { nextTestSetup } from 'e2e-utils'
import { createRouterAct } from 'router-act'
describe('prefetch inlining without cacheComponents', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('prefetch hints are only computed during build', () => {})
return
}
... | {
await browser
.elementByCss('input[data-link-accordion="/static-page"]')
.click()
},
{ includes: 'Static page' }
)
await act(async () => {
await browser.elementByCss('a[href="/static-page"]').click() | ly.
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
const act = createRouterAct(page!)
await act(
async () => | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining-no-cache-components/prefetch-inlining-no-cache-components.test.ts",
"language": "typescript",
"file_size": 2994,
"cut_index": 563,
"middle_length": 229
} |
xt-test-utils'
import { isNextDeploy, isNextDev, nextTestSetup } from 'e2e-utils'
import { createFakeCDN } from './server.mjs'
describe('segment cache (CDN cache busting)', () => {
if (isNextDev || isNextDeploy) {
test('should not run during dev or deploy test runs', () => {})
return
}
const { next } = ... | let nextExit: Promise<any> | undefined
let cdnServer: Server
let port: number
beforeAll(async () => {
await next.build()
const nextPort = await findPort()
const proxyPort = (port = await findPort())
let resolveReady!: () => void
| // This will start the Next app and also a proxy server that simulates a CDN.
// Like certain real-world CDNs, our fake CDN doesn't respect the Vary header.
// It only uses the URL.
let nextChild: ChildProcess | undefined
| {
"filepath": "test/e2e/app-dir/segment-cache/cdn-cache-busting/cdn-cache-busting.test.ts",
"language": "typescript",
"file_size": 5412,
"cut_index": 716,
"middle_length": 229
} |
from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('segment cache - root params segment prefetch', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled in dev mode', () =>... | response.request()
if (request.headers()['next-router-segment-prefetch']) {
segmentPrefetchBodies.push(response.text().catch(() => ''))
}
})
},
})
await act(
async () => {
const toggle = | : Array<Promise<string>> = []
const browser = await next.browser('/root-params', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
p.on('response', (response) => {
const request = | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/root-params-segment-prefetch.test.ts",
"language": "typescript",
"file_size": 1756,
"cut_index": 537,
"middle_length": 229
} |
s of features and edge cases.
*/
describe('segment cache - vary params', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled in dev mode', () => {})
return
}
it('renders cached loading state instantly during navigation', async ... | wait act(
async () => {
const toggle = await browser.elementByCss(
'input[data-link-accordion="/instant-loading/electronics/phone"]'
)
await toggle.click()
},
{ includes: 'Category: electronics' }
)
| f createRouterAct>
const browser = await next.browser('/instant-loading', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
})
// Prefetch the first link - layout is fetched
a | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/vary-params.test.ts",
"language": "typescript",
"file_size": 28902,
"cut_index": 1331,
"middle_length": 229
} |
port { LinkAccordion } from '../../../components/link-accordion'
export default function RuntimePrefetchLayoutSplitIndexPage() {
return (
<div id="runtime-prefetch-layout-split-index">
<h1>Runtime Prefetch - Layout/Page Param Split</h1>
<ul>
<li>
<LinkAccordion href="/runtime-prefet... | Electronics: Tablet
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/runtime-prefetch-layout-split/clothing/shirt">
Clothing: Shirt
</LinkAccordion>
</li>
</ul>
</div>
| cs/tablet">
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-layout-split/page.tsx",
"language": "tsx",
"file_size": 789,
"cut_index": 514,
"middle_length": 14
} |
} from 'react'
/**
* Layout that accesses both category and itemId params inside Suspense.
*
* Since this layout accesses both params, it varies on both — changing
* either param requires re-fetching this layout segment.
*/
type Params = { category: string; itemId: string }
export default async function Runtime... | nt params={params} />
</Suspense>
{children}
</div>
)
}
async function LayoutContent({ params }: { params: Promise<Params> }) {
const { category, itemId } = await params
return <div data-layout-content="true">{`Layout: ${category}/${ | {<div>Loading layout...</div>}>
<LayoutConte | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-layout-split/[category]/[itemId]/layout.tsx",
"language": "tsx",
"file_size": 857,
"cut_index": 529,
"middle_length": 52
} |
'react'
import { connection } from 'next/server'
/**
* Page that accesses only category (not itemId) in the static portion.
*
* Combined with the layout (which accesses both params), this tests that
* vary params are tracked per-segment in runtime prefetches:
* - Layout varies on both category AND itemId → re-fet... | ms = { category: string; itemId: string }
export default async function RuntimePrefetchLayoutSplitPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="runtime-prefetch-layout-split-page">
<Suspense fallback={<div>Loading page | : string } }>
} = {
unstable_samples: [
{ params: { category: 'electronics', itemId: 'phone' } },
{ params: { category: 'clothing', itemId: 'shirt' } },
],
}
export const unstable_prefetch = 'force-runtime'
type Para | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-layout-split/[category]/[itemId]/page.tsx",
"language": "tsx",
"file_size": 1650,
"cut_index": 537,
"middle_length": 229
} |
from '../../../components/link-accordion'
/**
* Index page for the instant loading state test. This is the canonical test
* for the vary params feature — it demonstrates the core user-facing benefit:
* instant loading feedback when navigating to routes that share cached segments.
*
* All links share category='ele... | * 1. Click the checkbox for "phone" — triggers prefetch, layout is fetched
* 2. Click the checkbox for "tablet" — cache hit, no request
* 3. Click the checkbox for "laptop" — cache hit, no request
* 4. Click the "headphones" link to navigate — loading | e page component renders itemId dynamically (not in generateStaticParams),
* so when navigating, the cached layout/loading shell renders instantly while
* the dynamic page content loads in the background.
*
* Manual testing:
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/instant-loading/page.tsx",
"language": "tsx",
"file_size": 2021,
"cut_index": 537,
"middle_length": 229
} |
/**
* Layout for the [category] segment. This layout:
* - Accesses only 'category' param → cached across different itemIds
* - Has generateStaticParams for 'electronics' → this segment is static
*
* The child [itemId] segment is dynamic (no generateStaticParams), so when
* navigating to different itemIds within ... | ntLoadingCategoryLayout({
children,
params,
}: {
children: React.ReactNode
params: Promise<Params>
}) {
const { category } = await params
return (
<div data-instant-loading-layout="true">
<div data-layout-category={category}>{`Catego | ectronics' }]
}
export default async function Insta | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/instant-loading/[category]/layout.tsx",
"language": "tsx",
"file_size": 917,
"cut_index": 547,
"middle_length": 52
} |
s = { category: string; itemId: string }
/**
* Page component that renders the itemId param. This segment has NO
* generateStaticParams, so itemId is fully dynamic and loads behind
* the Suspense boundary (loading.tsx).
*
* When navigating to this page:
* 1. The parent [category] layout renders instantly from ca... | Page({
params,
}: {
params: Promise<Params>
}) {
const { category, itemId } = await params
return (
<div id="instant-loading-page">
<div data-category={category} data-item-id={itemId}>
Item: {itemId} (in category: {category})
| InstantLoading | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/instant-loading/[category]/[itemId]/page.tsx",
"language": "tsx",
"file_size": 818,
"cut_index": 522,
"middle_length": 14
} |
kAccordion } from '../../../components/link-accordion'
/**
* Index page for the metadata vary params test.
*
* This tests that param access in generateMetadata is tracked in the head
* segment's varyParams, separate from body segment tracking.
*
* Setup:
* - [slug]/page.tsx has generateMetadata that accesses pa... | or "bbb" - cache miss, new prefetch (slug changed)
* 3. Click checkbox for "ccc" - cache miss, new prefetch (slug changed)
*/
export default function MetadataIndexPage() {
return (
<div id="metadata-index">
<h1>Metadata Vary Params Test</h1>
| g)
* - Subsequent prefetches with different slugs require new fetches
* because metadata accesses the slug param
*
* Manual testing:
* 1. Click checkbox for "aaa" - triggers prefetch, content fetched
* 2. Click checkbox f | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/metadata/page.tsx",
"language": "tsx",
"file_size": 1477,
"cut_index": 524,
"middle_length": 229
} |
'react'
import { connection } from 'next/server'
type Params = { slug: string }
/**
* Page where generateMetadata accesses params but the body does NOT.
*
* This tests that metadata param access is tracked separately from page body.
* When the slug changes:
* - Head segment should be re-fetched (metadata accesse... | refetch is still cacheable across
* slug changes.
*/
export async function generateStaticParams(): Promise<Params[]> {
return [{ slug: 'aaa' }, { slug: 'bbb' }, { slug: 'ccc' }]
}
export async function generateMetadata({
params,
}: {
params: Promi | mitigation for dynamic
* `generateMetadata` on an otherwise-static body — it makes the body partially
* dynamic via PPR, which is what we actually want here: the body doesn't depend
* on `slug`, so the static portion of the p | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/metadata/[slug]/page.tsx",
"language": "tsx",
"file_size": 1560,
"cut_index": 537,
"middle_length": 229
} |
pense } from 'react'
import { connection } from 'next/server'
/**
* Runtime prefetch page where generateMetadata accesses params but the
* page body does NOT.
*
* This tests that head vary params are tracked separately from segment body
* in the runtime prefetch pipeline. When slug changes:
* - Head segment shou... | {
params: Promise<Params>
}) {
const { slug } = await params
return { title: `Runtime Metadata: ${slug}` }
}
export default async function RuntimePrefetchMetadataPage() {
// Intentionally NOT accessing params in the body
return (
<div id="r | } }>
} = {
unstable_samples: [{ params: { slug: 'aaa' } }, { params: { slug: 'bbb' } }],
}
export const unstable_prefetch = 'force-runtime'
type Params = { slug: string }
export async function generateMetadata({
params,
}: | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-metadata/[slug]/page.tsx",
"language": "tsx",
"file_size": 1354,
"cut_index": 524,
"middle_length": 229
} |
link-accordion'
/**
* Index page for the search params access tracking test.
*
* This tests that when a page accesses searchParams, separate cache entries
* are created for each unique search param value.
*
* Two sub-routes:
* - /search-params/target-page?foo=X - Page accesses searchParams, NO cache reuse
* - ... | ault function SearchParamsIndexPage() {
return (
<div id="search-params-index">
<h1>Search Params Access Tracking Test</h1>
<p>
Tests that accessing searchParams creates separate cache entries for
each unique search param | for "?foo=2" target link - should trigger NEW prefetch (no cache)
* 3. Click checkbox for "?foo=1" static-target link - triggers prefetch
* 4. Click checkbox for "?foo=2" static-target link - should be cache hit
*/
export def | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/search-params/page.tsx",
"language": "tsx",
"file_size": 2319,
"cut_index": 563,
"middle_length": 229
} |
Act } from 'router-act'
import { findPort } from 'next-test-utils'
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { join } from 'path'
import { createExportServer } from './server.mjs'
describe('segment cache (output: "export")', () => {
if (!isNextStart) {
test('build test should not run during d... | r: Server
beforeAll(async () => {
await next.build()
port = await findPort()
server = createExportServer(join(next.testDir, 'out'))
server.listen(port)
})
afterAll(() => {
server?.close()
})
it('basic prefetch in output: "e | ly, first build the app, then run:
//
// node start.mjs
//
// This will serve the static `/out` directory, and also set up a server-side
// rewrite, which some of the tests below rely on.
let port: number
let serve | {
"filepath": "test/e2e/app-dir/segment-cache/export/segment-cache-output-export.test.ts",
"language": "typescript",
"file_size": 3841,
"cut_index": 614,
"middle_length": 229
} |
ent cache (metadata)', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('disabled in development', () => {})
return
}
describe("regression: prefetch the head if it's missing even if all other data is cached", () => {
it('pages with dynamic content ... | )
await checkbox.click()
}, [
{
includes: 'Target page',
},
// Because the link is prefetched with prefetch={true},
// we should be able to prefetch the title, even though it's dynamic.
| act = createRouterAct(p)
},
})
// Fully prefetch a page
await act(async () => {
const checkbox = await browser.elementByCss(
'input[data-link-accordion="/page-with-dynamic-head"]'
| {
"filepath": "test/e2e/app-dir/segment-cache/metadata/segment-cache-metadata.test.ts",
"language": "typescript",
"file_size": 4491,
"cut_index": 614,
"middle_length": 229
} |
sure', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('disabled in development', () => {})
return
}
it('evicts least recently used prefetch data once cache size exceeds limit', async () => {
let act: ReturnType<typeof createRouterAct>
const ... | ync () => {
await switchToTab1.click()
},
{ includes: 'Page 0.' }
)
// Switching to tab 2 causes the cache to overflow, evicting the prefetch
// for the Page 0 link.
await act(
async () => {
await switchTo | 'input[type="radio"][value="1"]'
)
const switchToTab2 = await browser.elementByCss(
'input[type="radio"][value="2"]'
)
// Switch to tab 1 to kick off a prefetch for a link to Page 0.
await act(
as | {
"filepath": "test/e2e/app-dir/segment-cache/memory-pressure/segment-cache-memory-pressure.test.ts",
"language": "typescript",
"file_size": 5472,
"cut_index": 716,
"middle_length": 229
} |
useState } from 'react'
import { useRouter } from 'next/navigation'
function Tab0() {
return <p id="tab-0-content">Intentionally empty</p>
}
function Tab1() {
return <Link href="/memory-pressure/0">Link 0</Link>
}
function Tab2() {
const links = []
for (let i = 1; i < 60; i++) {
links.push(<Link href={'/... | b1 />
break
case '2':
tab = <Tab2 />
break
default:
tab = null
break
}
return (
<form>
<h1>Memory pressure</h1>
<p>
Tests that prefetch data is evicted once the cache size grows too large,
| onst handlePageChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedTab(event.target.value)
}
let tab
switch (selectedTab) {
case '0':
tab = <Tab0 />
break
case '1':
tab = <Ta | {
"filepath": "test/e2e/app-dir/segment-cache/memory-pressure/app/memory-pressure/page.tsx",
"language": "tsx",
"file_size": 2831,
"cut_index": 563,
"middle_length": 229
} |
ture for max prefetch inlining. With Infinity thresholds, all
// segments are bundled into a single response per route, similar to how
// prefetching worked before the Segment Cache (pre-Next 16).
import { LinkAccordion } from '../components/link-accordion'
export default function Home() {
return (
<div>
<... | nkAccordion href="/shared/a/b/c" id="duplicate-a">
Route A (duplicate)
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/dynamic/hello">Dynamic Route</LinkAccordion>
</li>
</ul>
</div>
)
} | kAccordion>
</li>
<li>
<Li | {
"filepath": "test/e2e/app-dir/segment-cache/max-prefetch-inlining/app/page.tsx",
"language": "tsx",
"file_size": 832,
"cut_index": 523,
"middle_length": 52
} |
kAccordion } from '../components/link-accordion'
export default function Page() {
return (
<>
<p>
This page is used to test various scenarios related to prefetch cache
staleness. In the corresponding e2e test, the links below are prefetched
(by toggling their visibility), time is el... | i>
<LinkAccordion href="/runtime-stale-2-minutes">
Page whose runtime prefetch has a stale time of 2 minutes
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/runtime-stale-4-minutes">
P | ith stale time of 2 minutes
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/stale-4-minutes">
Page with stale time of 4 minutes
</LinkAccordion>
</li>
<l | {
"filepath": "test/e2e/app-dir/segment-cache/staleness/app/page.tsx",
"language": "tsx",
"file_size": 1409,
"cut_index": 524,
"middle_length": 229
} |
/link-accordion'
export default function Page() {
return (
<>
<p>
This page tests per-page dynamic stale time configuration via{' '}
<code>export const unstable_dynamicStaleTime</code>.
</p>
<ul>
<li>
<LinkAccordion href="/per-page-config/dynamic-stale-60">
... | Accordion>
</li>
<li>
<LinkAccordion href="/per-page-config/parallel-slots">
Parallel routes with slots having different stale times (60s and
15s)
</LinkAccordion>
</li>
</ul>
</ | page with stale time of 10 seconds
</Link | {
"filepath": "test/e2e/app-dir/segment-cache/staleness/app/per-page-config/page.tsx",
"language": "tsx",
"file_size": 875,
"cut_index": 559,
"middle_length": 52
} |
e TreePrefetch as an ASCII tree showing inlining decisions.
* Segments marked with "⇣ inlined" have their data included in a descendant's
* response instead of being fetched separately. Validates that parent/child
* hints are consistent (every InlinedIntoChild parent must have a child with
* ParentInlinedIntoSelf, ... | tring[] = []
const isHeadOutlined = (tree.prefetchHints & HeadOutlined) !== 0
collectNodes(tree, '', !isHeadOutlined, false, lines)
if (isHeadOutlined) {
// Metadata is not inlined into any page — render as a standalone sibling.
lines.push(`$ | UTLINED_TAG.length)
const RUNTIME_TAG = 'runtime \u25FB'.padStart(OUTLINED_TAG.length)
const DYNAMIC_TAG = 'dynamic \u25FB'.padStart(OUTLINED_TAG.length)
function renderInliningTree(tree: TreePrefetch): string {
const lines: s | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/prefetch-inlining.test.ts",
"language": "typescript",
"file_size": 29270,
"cut_index": 1331,
"middle_length": 229
} |
Runtime layout with parallel routes. The parent's data should pass through
// this layout into one child slot only — not into both. This tests that the
// pass-through behavior respects the "parent inlines into one child" rule
// even when the pass-through segment has multiple child slots.
import { ReactNode, Suspense ... | /p>
}
export default function RuntimeParallelLayout({
children,
sidebar,
}: {
children: ReactNode
sidebar: ReactNode
}) {
return (
<div>
<Suspense fallback={<p>Loading layout...</p>}>
<DynamicContent />
</Suspense>
| tch = 'force-runtime'
async function DynamicContent() {
const cookieStore = await cookies()
const theme = cookieStore.get('theme')?.value ?? 'default'
return <p id="layout-runtime-parallel">Runtime layout (theme: {theme})< | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-runtime-parallel/layout.tsx",
"language": "tsx",
"file_size": 1074,
"cut_index": 515,
"middle_length": 229
} |
s prefetching disabled because it performs uncached dynamic
// I/O (connection()). Static parents above it should be able to inline through
// it and into the static child below, because this layout acts as a transparent
// pass-through — its slot in the bundle is null but the chain isn't broken.
import { ReactNode, Su... | -passthrough">Dynamic layout</p>
}
export default function InstantFalsePassthroughLayout({
children,
}: {
children: ReactNode
}) {
return (
<div>
<Suspense fallback={<p>Loading...</p>}>
<DynamicContent />
</Suspense>
{c | it connection()
return <p id="layout-instant-false | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-instant-false-passthrough/layout.tsx",
"language": "tsx",
"file_size": 865,
"cut_index": 529,
"middle_length": 52
} |
{ ReactNode, Suspense } from 'react'
import { cookies } from 'next/headers'
// This layout uses runtime prefetching and sits ABOVE the [item] param.
// It's shared between /test-independent-head/a and /test-independent-head/b.
// Once cached from the first prefetch, a subsequent prefetch to a sibling
// page won't ne... | me = cookieStore.get('theme')?.value ?? 'default'
return (
<div>
<p id="layout-independent-head">Shared layout (theme: {theme})</p>
{children}
</div>
)
}
export default function Layout({ children }: { children: ReactNode }) {
ret | ms: { q: null },
params: { item: 'a' },
},
],
}
export const unstable_prefetch = 'force-runtime'
async function LayoutContent({ children }: { children: ReactNode }) {
const cookieStore = await cookies()
const the | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-independent-head/layout.tsx",
"language": "tsx",
"file_size": 1132,
"cut_index": 518,
"middle_length": 229
} |
mistic routing - route cache keying regression', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('skipped in dev mode', () => {})
return
}
// Regression test for https://github.com/vercel/next.js/pull/88863
//
// When navigating to a route that ... | was always set to null, even though the rest of the
// system uses the real nextUrl value when looking up entries. This meant
// every subsequent cache lookup missed, and the client would make
// redundant requests for route data it already had.
// |
// navigations and prefetches to the same URL.
//
// A bug caused these entries to be stored with an incorrect cache key: the
// "nextUrl" dimension (which tracks the referring page for interception
// route purposes) | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-route-cache-keying-regression/optimistic-route-cache-keying-regression.test.ts",
"language": "typescript",
"file_size": 4428,
"cut_index": 614,
"middle_length": 229
} |
{ connection } from 'next/server'
import { Suspense } from 'react'
import Link from 'next/link'
async function PhotoContent({ params }: { params: Promise<{ id: string }> }) {
// connection() opts this page into dynamic rendering. This is important
// because the test uses staleTimes.dynamic to control when cache ... | <PhotoContent params={params} />
</Suspense>
<h2>Step 2: Navigate back</h2>
<p style={{ color: '#666', fontSize: 14 }}>
Click this link to go back to the feed page. The route and segment data
from this page remain in the | ams
return <div id="photo-page">Photo {id}</div>
}
export default function PhotoPage({
params,
}: {
params: Promise<{ id: string }>
}) {
return (
<div>
<Suspense fallback={<div>Loading photo...</div>}>
| {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-route-cache-keying-regression/app/photo/[id]/page.tsx",
"language": "tsx",
"file_size": 1173,
"cut_index": 518,
"middle_length": 229
} |
from 'next/link'
import { LinkAccordion } from '../../components/link-accordion'
export default function FeedPage() {
return (
<div>
<div id="feed-page">Feed page</div>
<h2>Step 1: Navigate without prefetch</h2>
<p style={{ color: '#666', fontSize: 14 }}>
Click this link to navigate to... | k</h2>
<p style={{ color: '#666', fontSize: 14 }}>
After navigating to the photo page and back, toggle this checkbox to
reveal a prefetched link to the same URL. The prefetch system should
find the route data already in the ca |
cache for future use.
</p>
<p>
<Link href="/photo/1" prefetch={false} id="link-no-prefetch">
Go to photo 1 (no prefetch)
</Link>
</p>
<h2>Step 3: Reveal a prefetched lin | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-route-cache-keying-regression/app/feed/page.tsx",
"language": "tsx",
"file_size": 1327,
"cut_index": 524,
"middle_length": 229
} |
port { LinkAccordion } from '../../components/link-accordion'
// TODO: Once the appropriate API exists/is implemented, configure the param to
// be statically generated on demand but not at build time (`dynamicParams =
// true` isn't supported when `cacheComponents` is enabled.) For now this test case
// seems to work... | ot generated at build
time but is lazily generated on demand
</p>
<ul>
<li>
<LinkAccordion href="/lazily-generated-params/some-param-value">
Target
</LinkAccordion>
</li>
</ul>
< | aram that is n | {
"filepath": "test/e2e/app-dir/segment-cache/basic/app/lazily-generated-params/page.tsx",
"language": "tsx",
"file_size": 793,
"cut_index": 514,
"middle_length": 14
} |
efault function OutputExport() {
return (
<>
<p>
Demonstrates that per-segment prefetching works in{' '}
<code>output: export</code> mode.
</p>
<ul>
<li>
<LinkAccordion href="/target-page">Target</LinkAccordion>
</li>
</ul>
<p>
The fo... | </li>
</ul>
<p>
The following link is redirected on the server to the same page as the
link above:
</p>
<ul>
<li>
<LinkAccordion href="/redirect-to-target-page">
Redirect to target pag | ite to target page
</LinkAccordion>
| {
"filepath": "test/e2e/app-dir/segment-cache/export/app/page.tsx",
"language": "tsx",
"file_size": 959,
"cut_index": 582,
"middle_length": 52
} |
ort { Suspense } from 'react'
type Params = { step: string }
async function Content({ params }: { params: Promise<Params> }) {
const { step } = await params
return (
<div id="memory-pressure-step-page">
<h1>{`Page ${step}.`}</h1>
{/* Render a large string such that a prefetch of this segment is ro... | gger the
// default LRU limit used by the client prefetch cache.
// TODO: Once we add a config option to set the prefetch limit, we can set a
// smaller number, to speed up testing iteration (and CI).
const result: Array<Params> = []
for (let i = | Suspense fallback="Loading...">
<Content params={params} />
</Suspense>
)
}
export async function generateStaticParams(): Promise<Array<Params>> {
// Generate some number of steps. This should be just enough to tri | {
"filepath": "test/e2e/app-dir/segment-cache/memory-pressure/app/memory-pressure/[step]/page.tsx",
"language": "tsx",
"file_size": 1081,
"cut_index": 515,
"middle_length": 229
} |
from 'e2e-utils'
import { build, start } from './servers.mjs'
describe('segment cache (deployment skew)', () => {
if (isNextDev) {
test('should not run during dev', () => {})
return
}
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
env: {
// rely on skew protection ... | // based on the request information.
if (isNextStart) {
let cleanup: () => Promise<void>
let port: number
describe('with BUILD_ID', () => {
beforeAll(async () => {
build('BUILD_ID')
const proxyPort = (port = await find | p:
// node build.mjs
//
// Then start:
// node start.mjs
//
// This will build two versions of the same app on different ports, then
// start a proxy server that rewrites incoming requests to one or the other
| {
"filepath": "test/e2e/app-dir/segment-cache/deployment-skew/deployment-skew.test.ts",
"language": "typescript",
"file_size": 7770,
"cut_index": 716,
"middle_length": 229
} |
ccordion'
export default function Page() {
return (
<div>
<h1 id="home">Prefetch inlining home</h1>
<ul>
<li>
<LinkAccordion href="/test-small-chain">Small chain</LinkAccordion>
</li>
<li>
<LinkAccordion href="/test-deep/a/b/c">Deep chain</LinkAccordion>
... | c</LinkAccordion>
</li>
<li>
<LinkAccordion href="/test-runtime-bailout">
Runtime bailout
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/test-stale-hints/nested/deep">
| Restart
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/test-parallel">Parallel</LinkAccordion>
</li>
<li>
<LinkAccordion href="/test-dynamic/hello">Dynami | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/page.tsx",
"language": "tsx",
"file_size": 2127,
"cut_index": 563,
"middle_length": 229
} |
mport { ReactNode } from 'react'
import { NoInline } from '../../../components/no-inline'
// This layout renders large content that depends on the route param.
// In a fallback shell render, `await params` causes postponement so
// the segment output is small. In a concrete render the full content
// appears, pushing ... | unction Layout({
children,
params,
}: {
children: ReactNode
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return (
<div>
<NoInline />
<p>{`Dynamic layout for: ${slug}`}</p>
{children}
</div>
)
| efault async f | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-dynamic/[slug]/layout.tsx",
"language": "tsx",
"file_size": 787,
"cut_index": 513,
"middle_length": 14
} |
ort { LinkAccordion } from '../../../components/link-accordion'
// The page segment itself is fully static — it doesn't access searchParams
// or cookies. Only the metadata accesses searchParams (making the head
// depend on runtime data) and the [item] param (so it differs per route).
// The page segment content is t... | xport default async function Page({
params,
}: {
params: Promise<{ item: string }>
}) {
const { item } = await params
const sibling = item === 'a' ? 'b' : 'a'
return (
<div>
<p id="page-independent-head">Independent head page</p>
| params: Promise<{ item: string }>
searchParams: Promise<{ q?: string }>
}) {
const { item } = await params
const { q } = await searchParams
return { title: `Independent Head Title: ${item}${q ? ` (q=${q})` : ''}` }
}
e | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-independent-head/[item]/page.tsx",
"language": "tsx",
"file_size": 1125,
"cut_index": 515,
"middle_length": 229
} |
Link from 'next/link'
import { connection } from 'next/server'
export default async function SamePageNav() {
// Treat the page as dynamic so we can detect when it's refreshed
await connection()
return (
<>
<p>
Demonstrates that when navigating to the exact same URL as the current
loca... | <Link href="/same-page-nav">Link to current page</Link>
</li>
<li id="hash-b">
<Link href="/same-page-nav#hash-a">
Link to current page with hash fragment <code>#hash-a</code>
</Link>
</li>
| links.
</p>
<p>
Random number (changes on each refresh):{' '}
<span id="random-number">
{Math.floor(Math.random() * 1_000_000_000)}
</span>
</p>
<ul>
<li>
| {
"filepath": "test/e2e/app-dir/segment-cache/basic/app/same-page-nav/page.tsx",
"language": "tsx",
"file_size": 1198,
"cut_index": 518,
"middle_length": 229
} |
spense } from 'react'
import { cacheLife } from 'next/cache'
export default function Page() {
return (
<main>
<p>
Caches that use the 'seconds' profile will be omitted from static
prerenders, making this essentially dynamic. If we omit it, it should
not affect the cache life of the ... | )
}
async function ShortLivedContent() {
'use cache'
cacheLife('seconds')
return <div>Short-lived cached content</div>
}
async function LongerLivedContent() {
'use cache'
cacheLife('minutes')
return <div>Longer-lived cached content</div>
}
| page.</p>
<LongerLivedContent />
</main>
| {
"filepath": "test/e2e/app-dir/segment-cache/staleness/app/seconds/page.tsx",
"language": "tsx",
"file_size": 831,
"cut_index": 523,
"middle_length": 52
} |
eRouterAct } from 'router-act'
// Tests prefetch inlining with maxSize and maxBundleSize set to Infinity,
// which inlines all segments into a single response per route. This
// approximates the behavior of pre-Segment Cache (pre-Next 16) prefetching,
// where all prefetch data was bundled into one response. The trade... | , () => {})
return
}
it('bundles all segment data into a single request per route', async () => {
// The test app has two routes that are 5 segments deep:
// /shared/a/b/c and /shared/a/d/e
// Without inlining, prefetching each rou | g` directory. We may consolidate these tests
// in the future.
describe('max prefetch inlining', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('disabled in development' | {
"filepath": "test/e2e/app-dir/segment-cache/max-prefetch-inlining/max-prefetch-inlining.test.ts",
"language": "typescript",
"file_size": 5071,
"cut_index": 614,
"middle_length": 229
} |
t should
// be able to inline through it and into the static child below, because this
// layout acts as a transparent pass-through — its slot in the bundle is null
// but the chain isn't broken.
import { ReactNode, Suspense } from 'react'
import { cookies } from 'next/headers'
export const unstable_instant = {
unst... | default'
return <p id="layout-runtime-passthrough">Runtime layout (theme: {theme})</p>
}
export default function RuntimePassthroughLayout({
children,
}: {
children: ReactNode
}) {
return (
<div>
<Suspense fallback={<p>Loading layout...</ | const theme = cookieStore.get('theme')?.value ?? ' | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-inlining/app/test-runtime-passthrough/layout.tsx",
"language": "tsx",
"file_size": 976,
"cut_index": 582,
"middle_length": 52
} |
default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html>
<body>
<div style={{ maxWidth: 600, margin: '0 auto', padding: 20 }}>
<h1>Route Cache Keying Regression Test</h1>
<p style={{ color: '#666', fontSize: 14 }}>
Reproduces a ... | taleTimes feature to keep route cache
entries alive across navigations. The client cache currently only
writes segment data during prefetches, not navigations, so
staleTimes is needed to preserve the entries for reuse. O | ke redundant
requests. See{' '}
<a href="https://github.com/vercel/next.js/pull/88863">#88863</a>.
</p>
<p style={{ color: '#666', fontSize: 14 }}>
This test relies on the s | {
"filepath": "test/e2e/app-dir/segment-cache/optimistic-route-cache-keying-regression/app/layout.tsx",
"language": "tsx",
"file_size": 1221,
"cut_index": 518,
"middle_length": 229
} |
kAccordion } from '../../../components/link-accordion'
export default function InPageLoadingBoundaryIndexPage() {
return (
<div id="in-page-loading-boundary-index">
<h1>In-Page Loading Boundary Test</h1>
<p>
Verifies that a page with an in-page Suspense boundary (instead of a
separate... | LinkAccordion href="/in-page-loading-boundary/phone">
Phone
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/in-page-loading-boundary/tablet">
Tablet
</LinkAccordion>
</li>
| he child component that awaits
params suspends, so the prefetch contains only the Suspense fallback
with empty varyParams — making it reusable across all slug values.
</p>
<ul>
<li>
< | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/in-page-loading-boundary/page.tsx",
"language": "tsx",
"file_size": 1322,
"cut_index": 524,
"middle_length": 229
} |
Suspense } from 'react'
import { DebugRenderKind } from '../../shared'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Layout({ children }) {
return (
<main>
<div>
<h2>Shared layout</h2>
<DebugRenderKind />
<p id="... | Suspense>
</div>
<hr />
{children}
</main>
)
}
async function RuntimePrefetchable() {
await cookies()
return (
<div id="runtime-prefetchable-content-layout">
Runtime-prefetchable content from shared layout
</div>
| g ...">
<RuntimePrefetchable />
</ | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/segment-config/runtime-prefetchable/layout.tsx",
"language": "tsx",
"file_size": 873,
"cut_index": 559,
"middle_length": 52
} |
next/headers'
import { DebugLinkAccordion } from '../../../components/link-accordion'
import { Suspense } from 'react'
// No `export const unstable_instant = ...` is needed, we default to static
// (but see page description for more on the actual behavior)
export default function Page() {
return (
<main>
... | <Suspense fallback="Loading...">
<RuntimePrefetchable />
</Suspense>
</div>
<ul>
<li>
A page that shares some layouts with this page, and should use a
static prefetch:
<br />
| ode> segment, the page
contents will be runtime-prefetched (despite this segment not being
marked as runtime-prefetchable) because the parent layout is marked as
runtime-prefetchable.
</p>
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/segment-config/runtime-prefetchable/page.tsx",
"language": "tsx",
"file_size": 1822,
"cut_index": 537,
"middle_length": 229
} |
{ cookies } from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
// Technically, no `export const unstable_instant = ...` is needed, because we default to static,
// this is just to make sure that we excercise the codepaths for it
export const unstable_instant = true
export de... | <Suspense fallback="Loading...">
<DynamicContent />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await cookies()
return (
<div id="runtime-prefetchable-content-page">
Runtime-prefetchable content from | fetchable layout that is not
configured as runtime-prefetchable. We should not use a runtime prefetch
for it.
</p>
<Suspense fallback="Loading...">
<RuntimePrefetchable />
</Suspense>
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/segment-config/runtime-prefetchable/configured-as-static/page.tsx",
"language": "tsx",
"file_size": 1156,
"cut_index": 518,
"middle_length": 229
} |
import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { DebugRenderKind } from '../../../shared'
// No `export const unstable_instant = ...` is needed, we default to static
export default async function SubLayout({ children }) {
return (
<main>
<div>
<h3>Sub-layout</h3>
... | ble />
</Suspense>
</div>
<hr />
{children}
</main>
)
}
async function RuntimePrefetchable() {
await cookies()
return (
<div id="runtime-prefetchable-content-sub-layout">
Runtime-prefetchable content from sub- | be prefetched statically by
default.
</p>
<Suspense
fallback={
<div id="runtime-prefetchable-fallback-sub-layout">Loading ...</div>
}
>
<RuntimePrefetcha | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/segment-config/runtime-prefetchable/configured-as-runtime/layout.tsx",
"language": "tsx",
"file_size": 1021,
"cut_index": 512,
"middle_length": 229
} |
mport { cookies } from 'next/headers'
import { Suspense } from 'react'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default function Page() {
return (
<main>
<h1 style={{ color: 'green' }}>
A runtime-prefetchable child of a runtime-prefetchable layou... | tatically.
</p>
<Suspense fallback="Loading...">
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await cookies()
return (
<div id="runtime-prefetchable-content-page">
Run | 2. A statically-prefetchable sub-layout not shared with other pages.
<br />
<br />
We should use a runtime prefetch for it without any overrides on Link,
but its sub-layout should be prefetched s | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/segment-config/runtime-prefetchable/configured-as-runtime/page.tsx",
"language": "tsx",
"file_size": 1051,
"cut_index": 513,
"middle_length": 229
} |
kies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../shared'
import { connection } from 'next/server'
export default async function Layout({ children }) {
return (
<main>
<div>
<h2>Shared layout</h2>
<DebugRenderKind />
... | ieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cook | fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</div>
<hr />
{children}
</main>
)
}
async function RuntimePrefetchable() {
const cook | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/shared-layout/layout.tsx",
"language": "tsx",
"file_size": 1417,
"cut_index": 524,
"middle_length": 229
} |
ort { Suspense } from 'react'
import { cachedDelay, uncachedIO } from '../../shared'
import { cookies } from 'next/headers'
export default function Page() {
return (
<main>
<h1 style={{ color: 'green' }}>Page two</h1>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<Ru... | ack={<div style={{ color: 'grey' }}>Loading 2...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
async function Dynamic() {
await uncachedIO()
return (
<div style={{ border: '1px solid tomato', padding: '1em' }}>
<div id="dyna | e ?? null
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
<Suspense fallb | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/shared-layout/two/page.tsx",
"language": "tsx",
"file_size": 1071,
"cut_index": 515,
"middle_length": 229
} |
ort { Suspense } from 'react'
import { cachedDelay, uncachedIO } from '../../shared'
import { cookies } from 'next/headers'
export default function Page() {
return (
<main>
<h1 style={{ color: 'yellow' }}>Page one</h1>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<R... | back={<div style={{ color: 'grey' }}>Loading 2...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
async function Dynamic() {
await uncachedIO()
return (
<div style={{ border: '1px solid tomato', padding: '1em' }}>
<div id="dyn | ue ?? null
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
<Suspense fall | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/shared-layout/one/page.tsx",
"language": "tsx",
"file_size": 1072,
"cut_index": 515,
"middle_length": 229
} |
() => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('disabled in development', () => {})
return
}
it('router.refresh() refreshes both cached and dynamic data', async () => {
// Load the main Dashboard page. This will render the nav bar into the
... | const toggleAnalyticsLink = await browser.elementByCss(
'input[data-link-accordion="/dashboard/analytics"]'
)
await toggleAnalyticsLink.click()
const link = await browser.elementByCss('a[href="/dashboard/analytics"]')
aw | = createRouterAct(page)
// Navigate to the Analytics page. The analytics page does not match the
// @navbar slot, so the client reuses the one that was rendered by the
// previous page.
await act(async () => {
| {
"filepath": "test/e2e/app-dir/segment-cache/refresh/segment-cache-refresh.test.ts",
"language": "typescript",
"file_size": 6826,
"cut_index": 716,
"middle_length": 229
} |
ort { LinkAccordion } from '../../components/link-accordion'
import { ClientRefreshButton } from './client'
import { refresh } from 'next/cache'
function ServerRefreshButton() {
return (
<form
action={async () => {
'use server'
refresh()
}}
>
<button id="server-refresh-butto... | n href="/dashboard">Dashboard Home</LinkAccordion>
</li>
<li>
<LinkAccordion href="/dashboard/analytics">Analytics</LinkAccordion>
</li>
<li>
<LinkAccordion href="/docs">Docs</LinkAccordion>
| <div style={{ border: '1px solid black', padding: '1rem' }}>
{navbar}
<div>
<ClientRefreshButton />
<ServerRefreshButton />
</div>
<ul>
<li>
<LinkAccordio | {
"filepath": "test/e2e/app-dir/segment-cache/refresh/app/dashboard/layout.tsx",
"language": "tsx",
"file_size": 1083,
"cut_index": 515,
"middle_length": 229
} |
ction } from 'next/server'
import { RenderCounterClient } from './client'
async function DynamicRenderCounter(): Promise<React.ReactNode> {
// Renders a count of the number of times the client receives new dynamic data
// from the server. The count is computed on the client and stored in React
// state, so it ge... | <Suspense fallback={<div>Loading...</div>}>
<p>
Navbar dynamic render counter:{' '}
<span id="navbar-dynamic-render-counter">
<DynamicRenderCounter />
</span>
</p>
</Suspense>
</div> | ngPage() {
return (
<div>
<p>Navbar</p>
| {
"filepath": "test/e2e/app-dir/segment-cache/refresh/app/dashboard/@navbar/page.tsx",
"language": "tsx",
"file_size": 874,
"cut_index": 559,
"middle_length": 52
} |
retry } from 'next-test-utils'
describe('segment cache (MPA navigations)', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('ppr is disabled', () => {})
return
}
type ElementWithExpando = Element & { __expando?: boolean }
it('triggers MPA navigati... | lementByCss(`a[href="/foo"]`)
await link.click()
// The expando should not be present because we did a full-page navigation.
await retry(async () => {
const htmlAfterNav = await browser.elementByCss('html')
expect(
await ht | loaded.
const html = await browser.elementByCss('html')
await html.evaluate((el) => ((el as ElementWithExpando).__expando = true))
// Navigate to a page with a different root layout.
const link = await browser.e | {
"filepath": "test/e2e/app-dir/segment-cache/mpa-navigations/mpa-navigations.test.ts",
"language": "typescript",
"file_size": 2469,
"cut_index": 563,
"middle_length": 229
} |
enerateStaticParams() {
return [{ rootParam: 'foo' }, { rootParam: 'bar' }]
}
export default async function Page(props: {
params: Promise<{ rootParam: string }>
}) {
const { rootParam } = await props.params
const otherRootParam = rootParam === 'foo' ? 'bar' : 'foo'
return (
<>
<p>
<p>
... | em>should</em> trigger an MPA navigation, because in
addition to changing a root param, it also navigates to a different
root layout:
</p>
<Link href={`/${otherRootParam}/inner`}>/{otherRootParam}/inner</Link>
</p> | </p>
<p>
<p>
This link < | {
"filepath": "test/e2e/app-dir/segment-cache/mpa-navigations/app/(group2)/[rootParam]/(groupA)/page.tsx",
"language": "tsx",
"file_size": 882,
"cut_index": 559,
"middle_length": 52
} |
eRouterAct } from 'router-act'
describe('App Shell prefetching', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('is skipped', () => {})
return
}
it('reuses the app shell across different param values so navigation to an unprefetched route is instant'... | posts" substring appears in two responses: one
// for the App Shell itself and one for the per-link prefetch of
// /posts/1 (which, for a dynamic page, also includes the shell
// content above its inner Suspense fallback).
await act(async ( | uterAct(page)
// Reveal the LinkAccordion for /posts/1. This caches the App Shell
// for the route — the param-independent content of the page that's
// reusable for any /posts/[id].
//
// The "App shell for | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-app-shell/prefetch-app-shell.test.ts",
"language": "typescript",
"file_size": 4957,
"cut_index": 614,
"middle_length": 229
} |
import Link from 'next/link'
import { LinkAccordion } from '../components/link-accordion'
export default function Page() {
return (
<main>
<h1>Home</h1>
<h2>Dynamic posts</h2>
<p>
These posts read request-time data (cookies). Their App Shell is the
part of the page that doesn&a... | posts/124" prefetch={false}>
Unprefetched post
</Link>
</li>
<li>
<Link href="/posts/125?foo=bar" prefetch={false}>
Unprefetched post with search params
</Link>
</li>
</ul> | </li>
<li>
<LinkAccordion href="/posts/2">Post 2</LinkAccordion>
</li>
<li>
<LinkAccordion href="/posts/3">Post 3</LinkAccordion>
</li>
<li>
<Link href="/ | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-app-shell/app/page.tsx",
"language": "tsx",
"file_size": 1016,
"cut_index": 512,
"middle_length": 229
} |
'react'
import { cookies } from 'next/headers'
import { connection } from 'next/server'
type Params = { id: string }
export const unstable_prefetch = 'force-runtime'
export default function Page({ params }: { params: Promise<Params> }) {
return (
<main>
{/* Cookies are part of the request context, so the... | aramsDependent params={params} />
</Suspense>
</main>
)
}
async function CookieDependent() {
const cookieStore = await cookies()
const value = cookieStore.get('testCookie')?.value ?? 'none'
return <p id="cookie-value">{`Cookie: ${value}` | <CookieDependent />
</Suspense>
{/* The fallback is the App Shell — the part of the page that
doesn't depend on params. */}
<Suspense fallback={<p id="shell">App shell for posts</p>}>
<P | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-app-shell/app/posts/[id]/page.tsx",
"language": "tsx",
"file_size": 1591,
"cut_index": 537,
"middle_length": 229
} |
layout-max'
| 'tag-layout-legacy'
| 'server-action-tag-layout-expireNow'
| 'server-action-tag-layout-max'
| 'server-action-tag-layout-legacy'
type SegmentPrefetchResponse = {
body: string
requestPathname: string
requestSegmentPath: string
segmentPrefetchPath: string
status: number
}
describe('segmen... | l',
'/acme/dashboard/settings':
'Project settings overview content - team: acme, project: dashboard',
'/globex/portal/settings':
'Project settings overview content - team: globex, project: portal',
'/acme/dashboard/settings/domains' | {})
return
}
const expectedTextByHref: Record<string, string> = {
'/acme/dashboard': 'Team project content - team: acme, project: dashboard',
'/globex/portal': 'Team project content - team: globex, project: porta | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/vary-params-base-dynamic.test.ts",
"language": "typescript",
"file_size": 17357,
"cut_index": 921,
"middle_length": 229
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.