prefix stringlengths 512 512 | suffix stringlengths 256 256 | middle stringlengths 14 229 | meta dict |
|---|---|---|---|
lidateLayoutByTagLegacyAction,
revalidateLayoutByTagMaxAction,
} from '../app/revalidate-actions'
type ApiRevalidateMode =
| 'tag-layout-expireNow'
| 'tag-layout-max'
| 'tag-layout-legacy'
| 'path-root-layout'
| 'path-team-layout'
| 'path-team-page'
type ServerActionMode =
| 'server-action-tag-layout-e... | })
const data = await response.json()
setResult(JSON.stringify(data))
} catch (error) {
setResult(
JSON.stringify({
error: error instanceof Error ? error.message : 'unknown error',
mode,
})
| tIsPending] = useState(false)
const runApiRevalidate = async (mode: ApiRevalidateMode) => {
setIsPending(true)
try {
const response = await fetch(`/api/revalidate-layout?mode=${mode}`, {
method: 'GET',
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/components/revalidate-controls.tsx",
"language": "tsx",
"file_size": 3676,
"cut_index": 614,
"middle_length": 229
} |
nk'
import { LinkAccordion } from '../components/link-accordion'
import { RevalidateControls } from '../components/revalidate-controls'
export default function HomePage() {
return (
<div id="home-page">
<h1>Root Dynamic Route Vary Params</h1>
<p>
Prefetch dynamic team/project routes and valid... | href="/acme/dashboard/settings/domains"
data-nav-link="/acme/dashboard/settings/domains"
>
Navigate: acme/dashboard/settings/domains
</Link>
</li>
<li>
<Link
href="/ | cme/dashboard
</Link>
</li>
<li>
<Link href="/globex/portal" data-nav-link="/globex/portal">
Navigate: globex/portal
</Link>
</li>
<li>
<Link
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/app/page.tsx",
"language": "tsx",
"file_size": 1578,
"cut_index": 537,
"middle_length": 229
} |
from 'next/link'
import { Suspense } from 'react'
import { LinkAccordion } from '../../../components/link-accordion'
type Params = { teamSlug: string; project: string }
export default function TeamProjectPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="team-project-page">
<Suspense
... | Navigate: acme/dashboard
</Link>
</li>
<li>
<Link href="/globex/portal" data-nav-link="/globex/portal">
Navigate: globex/portal
</Link>
</li>
<li>
| <ul>
<li>
<Link href="/" data-nav-link="/">
Navigate: home
</Link>
</li>
<li>
<Link href="/acme/dashboard" data-nav-link="/acme/dashboard">
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/app/[teamSlug]/[project]/page.tsx",
"language": "tsx",
"file_size": 2988,
"cut_index": 563,
"middle_length": 229
} |
from 'next/link'
import { Suspense } from 'react'
import { LinkAccordion } from '../../../../components/link-accordion'
type Params = { teamSlug: string; project: string }
export default function ProjectSettingsPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="team-project-settings-page">
... | /domains"
data-nav-link="/acme/dashboard/settings/domains"
>
Navigate: acme/dashboard/settings/domains
</Link>
</li>
<li>
<Link
href="/globex/portal/settings/ | list="true">
<ul>
<li>
<Link href="/" data-nav-link="/">
Navigate: home
</Link>
</li>
<li>
<Link
href="/acme/dashboard/settings | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/app/[teamSlug]/[project]/settings/page.tsx",
"language": "tsx",
"file_size": 2021,
"cut_index": 563,
"middle_length": 229
} |
from 'next/link'
import { Suspense } from 'react'
import { LinkAccordion } from '../../../../../../components/link-accordion'
type Params = { teamSlug: string; project: string }
export default function ProjectDomainsSettingsPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="team-project-sett... | ashboard/settings"
>
Navigate: acme/dashboard/settings
</Link>
</li>
<li>
<Link
href="/globex/portal/settings"
data-nav-link="/globex/portal/settings"
| ectDomainsSettingsContent params={params} />
</Suspense>
<nav data-nav-link-list="true">
<ul>
<li>
<Link
href="/acme/dashboard/settings"
data-nav-link="/acme/d | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/app/[teamSlug]/[project]/(domains)/settings/domains/page.tsx",
"language": "tsx",
"file_size": 2463,
"cut_index": 563,
"middle_length": 229
} |
revalidateTag } from 'next/cache'
import { NextRequest } from 'next/server'
type RevalidateMode =
| 'tag-layout-expireNow'
| 'tag-layout-max'
| 'tag-layout-legacy'
| 'path-root-layout'
| 'path-team-layout'
| 'path-team-page'
function isRevalidateMode(value: string): value is RevalidateMode {
return (
... | ry
: 'tag-layout-expireNow'
switch (mode) {
case 'tag-layout-expireNow':
revalidateTag('_N_T_/layout', 'expireNow')
break
case 'tag-layout-max':
revalidateTag('_N_T_/layout', 'max')
break
case 'tag-layout-legacy | == 'path-team-page'
)
}
export async function GET(request: NextRequest) {
const modeQuery = request.nextUrl.searchParams.get('mode')
const mode: RevalidateMode =
modeQuery && isRevalidateMode(modeQuery)
? modeQue | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params-base-dynamic/app/api/revalidate-layout/route.ts",
"language": "typescript",
"file_size": 1518,
"cut_index": 537,
"middle_length": 229
} |
/dynamic-params/123"]`
)
await linkToggle.click()
}, [
// Should allow reading dynamic params
{
includes: 'Param: 123',
},
// Should not prefetch the dynamic content
{
includes: 'Dynamic content',
block: 'reject',
},
... | // Should not prefetch the dynamic content
{
includes: 'Dynamic content',
block: 'reject',
},
])
// Navigate to the page
await act(async () => {
await act(
async () => {
| `input[data-link-accordion="/${prefix}/dynamic-params/456"]`
)
await linkToggle.click()
}, [
// Should allow reading dynamic params
{
includes: 'Param: 456',
},
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/prefetch-runtime.test.ts",
"language": "typescript",
"file_size": 36951,
"cut_index": 2151,
"middle_length": 229
} |
import Link, { type LinkProps } from 'next/link'
import { ComponentProps, useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = useState(false)
return (
... | cordion({
href,
prefetch,
}: Omit<ComponentProps<typeof LinkAccordion>, 'children'>) {
const prefetchKind = getPrefetchKind(prefetch)
return (
<LinkAccordion href={href} prefetch={prefetch} data-prefetch={prefetch}>
{href} ({prefetchKind} | prefetch)}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
<>{children} (link is hidden)</>
)}
</>
)
}
export function DebugLinkAc | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/components/link-accordion.tsx",
"language": "tsx",
"file_size": 1318,
"cut_index": 524,
"middle_length": 229
} |
import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../shared'
export default async function Layout({ children }) {
return (
<main>
<div>
<h2>Shared layout</h2>
<DebugRenderKind />
<p id="shared-layout-description">
... | alue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div>
| Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</div>
<hr />
{children}
</main>
)
}
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieV | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/runtime-prefetchable-layout/layout.tsx",
"language": "tsx",
"file_size": 1012,
"cut_index": 512,
"middle_length": 229
} |
{ Suspense } from 'react'
import { cachedDelay } 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>}>
<RuntimePrefetcha... | refetched layout that had no holes itself will still be considered partial
if any other segment in the response is partial, because we don't track partiality per-segment,
so if we want to test that full prefetches can reuse layouts from run | ait cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
{/*
TODO: a runtime-p | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/runtime-prefetchable-layout/one/page.tsx",
"language": "tsx",
"file_size": 1234,
"cut_index": 518,
"middle_length": 229
} |
pense } from 'react'
/**
* Page that accesses searchParams with runtime prefetching.
*
* By awaiting searchParams, this page's cache key varies by search params.
* Different search param values will NOT share cached prefetch data.
*
* The searchParams access must be inside a Suspense boundary for runtime
* pref... | e SearchParams = { foo?: string }
export default async function SearchParamsTargetPage({
searchParams,
}: {
searchParams: Promise<SearchParams>
}) {
return (
<div id="search-params-target-page">
<Suspense fallback={<div>Loading search para | 1 content
* - Prefetching /target?foo=2 fetches the segment AGAIN (no cache hit)
*/
export const unstable_instant = {
unstable_samples: [{ searchParams: { foo: '1' } }],
}
export const unstable_prefetch = 'force-runtime'
typ | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/search-params/target-page/page.tsx",
"language": "tsx",
"file_size": 1459,
"cut_index": 524,
"middle_length": 229
} |
etch page that does NOT access searchParams.
*
* Since searchParams are not accessed, the '?' sentinel is not added to
* varyParams, and different search param values share the cached segment.
*/
export const unstable_instant = {
unstable_samples: [{ searchParams: { q: '1' } }],
}
export const unstable_prefetch =... | t - searchParams not accessed</div>
<Suspense fallback={<div>Loading...</div>}>
<DynamicContent />
</Suspense>
</div>
)
}
async function DynamicContent() {
await connection()
return <div data-dynamic-content="true">Dynamic co | arget">
<div data-content="true">Static conten | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-search-params/target-page/page.tsx",
"language": "tsx",
"file_size": 935,
"cut_index": 606,
"middle_length": 52
} |
from '../../../components/link-accordion'
/**
* Index page for the page segment reuse test.
*
* This test demonstrates a non-obvious case: a page segment can be reused when
* it doesn't access a param that the layout DOES access. This is the inverse
* of the typical pattern where layouts are reused while pages va... | *
* Manual testing:
* 1. Click checkbox for "phone" β layout and page both fetched
* 2. Click checkbox for "tablet" β layout re-fetched, page is cache hit
*/
export default function PageReuseIndexPage() {
return (
<div id="page-reuse-index">
| he same category but different
* items (e.g., /electronics/phone β /electronics/tablet), the layout must be
* re-fetched (it accesses `item`), but the page is a cache hit (it only
* accesses `category`, which hasn't changed).
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/page-reuse/page.tsx",
"language": "tsx",
"file_size": 1737,
"cut_index": 537,
"middle_length": 229
} |
t that accesses ONLY the `category` param, NOT `item`.
*
* This is the key to this test: even though the URL includes both params,
* this page only accesses `category`. Therefore:
* - When navigating between /electronics/phone and /electronics/tablet,
* this page segment is a cache hit (category unchanged)
*
*... | {
params: Promise<Params>
}) {
// NOTE: Only accessing `category`, NOT `item`
// This is intentional to demonstrate page reuse when item changes
const { category } = await params
return (
<div id="page-reuse-page">
<div data-page-cate | default async function PageReusePage({
params,
}: | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/page-reuse/[category]/[item]/page.tsx",
"language": "tsx",
"file_size": 960,
"cut_index": 582,
"middle_length": 52
} |
pense } from 'react'
import { connection } from 'next/server'
/**
* Runtime prefetch page where NO params are accessed in the static portion.
*
* Both category and itemId are accessed only after connection(), so they
* are NOT tracked in varyParams. This means ALL param combinations should
* share the same cached... | }
export default async function RuntimePrefetchNoVaryPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="runtime-prefetch-no-vary-page">
<Suspense
fallback={
<div data-loading="true">Loading all content dy | [
{ params: { category: 'electronics', itemId: 'phone' } },
{ params: { category: 'clothing', itemId: 'shirt' } },
],
}
export const unstable_prefetch = 'force-runtime'
type Params = { category: string; itemId: string | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-no-vary/[category]/[itemId]/page.tsx",
"language": "tsx",
"file_size": 1358,
"cut_index": 524,
"middle_length": 229
} |
kAccordion } from '../../../components/link-accordion'
/**
* Index page for the metadata-no-params vary params test.
*
* This is the inverse of the metadata test: generateMetadata does NOT access
* params, so the head segment should be cacheable across different param values.
*
* Setup:
* - [slug]/page.tsx has ... | ontent fetched
* 2. Click checkbox for "bbb" - cache hit, no new request
*/
export default function MetadataNoParamsIndexPage() {
return (
<div id="metadata-no-params-index">
<h1>Metadata No Params Test</h1>
<p>
Tests that when | rst prefetch fetches head and body segments
* - Subsequent prefetches with different slugs are cache hits
* (neither metadata nor body access params)
*
* Manual testing:
* 1. Click checkbox for "aaa" - triggers prefetch, c | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/metadata-no-params/page.tsx",
"language": "tsx",
"file_size": 1437,
"cut_index": 524,
"middle_length": 229
} |
'react'
import { connection } from 'next/server'
/**
* Runtime prefetch page where ALL params are accessed in the static portion.
*
* Both category and itemId are accessed before connection(), so they
* are both tracked in varyParams. Every unique combination of (category, itemId)
* requires its own prefetch β no... | imePrefetchAllVaryPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="runtime-prefetch-all-vary-page">
<Suspense fallback={<div>Loading...</div>}>
<StaticContent params={params} />
</Suspense>
</div>
)
}
| ics', itemId: 'phone' } },
{ params: { category: 'clothing', itemId: 'shirt' } },
],
}
export const unstable_prefetch = 'force-runtime'
type Params = { category: string; itemId: string }
export default async function Runt | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch-all-vary/[category]/[itemId]/page.tsx",
"language": "tsx",
"file_size": 1604,
"cut_index": 537,
"middle_length": 229
} |
from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('<Link prefetch="auto">', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('disabled in development / deployment', () => {})
return
}
/... | page
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
const act = createRouterAct(page)
// Reveal the link to trigger a prefetch
await act( | s just a quick test to confirm that the
// alias exists.
it('<Link prefetch="auto"> works the same as if prefetch were undefined or null', async () => {
// Test that the link only prefetches the static part of the target | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-auto/prefetch-auto.test.ts",
"language": "typescript",
"file_size": 1673,
"cut_index": 537,
"middle_length": 229
} |
n (
<main>
<h1>Home</h1>
<h2>
Links with <code>prefetch=false</code>
</h2>
<ul>
<li>
<Link href="/partially-static" prefetch={false}>
Go to partially static page
</Link>
</li>
<li>
<Link href="/fully-static" prefetch={... | <Link href="/with-fallback-params/foo" prefetch={false}>
Go to page with fallback params
</Link>
</li>
<li>
<Link href="/runtime-prefetchable" prefetch={false}>
Go to runtime-prefetchable p | ams
</Link>
</li>
<li>
| {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/page.tsx",
"language": "tsx",
"file_size": 956,
"cut_index": 582,
"middle_length": 52
} |
kies, headers } from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ q?: string }>
}) {
return (
<main>
<CachedContent />
<div id="search-params-boundary">
<Suspense fa... | pense>
</div>
<div id="connection-boundary">
<Suspense fallback={<p>Loading connection...</p>}>
<ConnectionContent />
</Suspense>
</div>
</main>
)
}
async function CachedContent() {
'use cache'
cacheLi | lback={<p>Loading cookies...</p>}>
<CookiesContent />
</Suspense>
</div>
<div id="headers-boundary">
<Suspense fallback={<p>Loading headers...</p>}>
<HeadersContent />
</Sus | {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/partially-static/page.tsx",
"language": "tsx",
"file_size": 2104,
"cut_index": 563,
"middle_length": 229
} |
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { ReactNode } from 'react'
import { LinkAccordion } from '../../components/link-accordion'
export default function ParamsLayout({ children }: { children: ReactNode }) {
const { bfcacheId } = useRouter()
return (
<>
<ul>
... | ink>
</li>
<li>
<LinkAccordion
key={bfcacheId}
href="/with-fallback-params/foo"
prefetch={true}
>
/with-fallback-params/foo (prefetch=true)
</LinkAccordion>
| rams/foo" prefetch={false}>
/with-fallback-params/foo
</Link>
</li>
<li>
<Link href="/with-fallback-params/bar" prefetch={false}>
/with-fallback-params/bar
</L | {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/with-fallback-params/layout.tsx",
"language": "tsx",
"file_size": 1307,
"cut_index": 524,
"middle_length": 229
} |
opt-in has been removed. These tests need to be updated to use the segment configuration.
it.skip('runtime prefetches should omit layouts that were already prefetched with a runtime prefetch', async () => {
// Prefetches should re-use results from previous prefetches with the same fetch strategy.
let page: ... | er a runtime prefetch for page one
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="/shared-layout/one"]`
)
await linkToggle.click()
}, [
// | esn't happen automatically.
await using _ = defer(() => browser.deleteCookies())
const act = createRouterAct(page)
await browser.addCookie({ name: 'testCookie', value: 'testValue' })
// Reveal the link to trigg | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/prefetch-layout-sharing.test.ts",
"language": "typescript",
"file_size": 29951,
"cut_index": 1331,
"middle_length": 229
} |
he'
import { setTimeout } from 'timers/promises'
export async function uncachedIO() {
await setTimeout(0)
}
export async function cachedDelay(key: any) {
'use cache'
cacheLife('minutes')
await setTimeout(1)
}
export function DebugRenderKind() {
const { workUnitAsyncStorage } =
require('next/dist/server... | re.type}
{(() => {
switch (workUnitStore.type) {
case 'prerender':
return '(static prefetch)'
case 'prerender-runtime':
return '(runtime prefetch)'
default:
return null
| n (
<div>
workUnitStore.type: {workUnitSto | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/shared.tsx",
"language": "tsx",
"file_size": 887,
"cut_index": 547,
"middle_length": 52
} |
import Link, { type LinkProps } from 'next/link'
import { ComponentProps, useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = useState(false)
return (
... | cordion({
href,
prefetch,
}: Omit<ComponentProps<typeof LinkAccordion>, 'children'>) {
const prefetchKind = getPrefetchKind(prefetch)
return (
<LinkAccordion href={href} prefetch={prefetch} data-prefetch={prefetch}>
{href} ({prefetchKind} | prefetch)}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
<>{children} (link is hidden)</>
)}
</>
)
}
export function DebugLinkAc | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/components/link-accordion.tsx",
"language": "tsx",
"file_size": 1318,
"cut_index": 524,
"middle_length": 229
} |
pe Params = { slug?: string[] }
/**
* Optional catch-all page that checks for the param using the `in` operator.
*
* Using `'slug' in params` should cause the segment to vary on the optional
* catch-all param, even when the param has no value.
*/
export async function generateStaticParams(): Promise<Params[]> {
... | const hasSlug = 'slug' in resolvedParams
const slug = hasSlug ? resolvedParams.slug : undefined
const slugDisplay = `Slug: ${slug ? slug.join('/') : 'none'}`
return (
<div id="optional-catchall-has-page">
<div>{slugDisplay}</div>
</div> | wait params
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/optional-catchall-has/[[...slug]]/page.tsx",
"language": "tsx",
"file_size": 791,
"cut_index": 514,
"middle_length": 14
} |
n } from 'next/server'
/**
* Runtime prefetch page - canonical test for runtime prefetching.
*
* This is the runtime prefetch equivalent of the instant-loading test:
* - `category` is accessed in the static/cached portion β enables cache sharing
* - `itemId` is accessed only in the dynamic portion β not relevant ... | const unstable_prefetch = 'force-runtime'
type Params = { category: string; itemId: string }
export default async function RuntimePrefetchPage({
params,
}: {
params: Promise<Params>
}) {
return (
<div id="runtime-prefetch-page">
{/* Outer | _samples: Array<{ params: { category: string; itemId: string } }>
} = {
unstable_samples: [
{ params: { category: 'electronics', itemId: 'phone' } },
{ params: { category: 'clothing', itemId: 'shirt' } },
],
}
export | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch/[category]/[itemId]/page.tsx",
"language": "tsx",
"file_size": 2224,
"cut_index": 563,
"middle_length": 229
} |
time (30s)
// but under the static cache's stale time (120s). If the stale time sent to
// the client incorrectly used the runtime cache's value, the cached
// segments would have expired and the second navigation wouldn't be
// instant.
await page.clock.fastForward(60_000)
// Second navigatio... | block: true,
}
)
// The static/cached part should be visible while the dynamic
// request is still blocked
expect(await browser.elementById('cached-content').text()).toContain(
'Cached content'
)
| },
{
// Block the dynamic request. The cached/prefetchable content
// should still be visible even though the dynamic data hasn't
// arrived yet.
includes: 'Dynamic content',
| {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/cached-navigations.test.ts",
"language": "typescript",
"file_size": 33920,
"cut_index": 2151,
"middle_length": 229
} |
import { connection } from 'next/server'
import { Suspense } from 'react'
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return (
<main>
<CachedContent ... | )
}
async function CachedContent() {
'use cache'
return <p id="cached-content">Cached content ({new Date().toISOString()})</p>
}
async function ConnectionContent() {
await connection()
return <p>Dynamic content ({new Date().toISOString()})</p>
}
| t />
</Suspense>
</div>
</main>
| {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/with-static-params/[slug]/page.tsx",
"language": "tsx",
"file_size": 820,
"cut_index": 512,
"middle_length": 52
} |
ugLinkAccordion } from '../components/link-accordion'
import { cacheLife } from 'next/cache'
export default async function Page() {
'use cache'
cacheLife('minutes')
return (
<main>
<h2>shared layout prefetching - layout with cookies and dynamic data</h2>
<ul>
<li>
<DebugLinkAcco... | n
href="/runtime-prefetchable-layout/one"
prefetch={true}
/>
</li>
<li>
<DebugLinkAccordion
href="/runtime-prefetchable-layout/two"
prefetch={'auto'}
/>
< | <li>
<DebugLinkAccordion href="/shared-layout/two" prefetch={true} />
</li>
</ul>
<h2>shared layout prefetching - layout with cookies</h2>
<ul>
<li>
<DebugLinkAccordio | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-layout-sharing/app/page.tsx",
"language": "tsx",
"file_size": 1379,
"cut_index": 524,
"middle_length": 229
} |
link-accordion'
/**
* Index page for the runtime prefetch vary params test.
*
* This tests vary params tracking with runtime prefetching enabled. Unlike
* static prefetching, runtime prefetching allows dynamic params to be rendered
* as part of the prefetch (rather than being omitted). This enables testing
* mor... | checkbox for "phone" β triggers prefetch, page content fetched
* 2. Click checkbox for "tablet" and "laptop" β cache hits (same category)
* 3. Navigate to "headphones" β loading state instant, then dynamic content loads
*/
export default function Runti | * Since `itemId` is only accessed in the dynamic section (inside Suspense after
* connection()), the page should only vary on `category`, allowing cache reuse
* across different itemId values.
*
* Manual testing:
* 1. Click | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/runtime-prefetch/page.tsx",
"language": "tsx",
"file_size": 2171,
"cut_index": 563,
"middle_length": 229
} |
arams = { category: string; item: string }
/**
* Layout for the [category]/[item] segment. This layout:
* - Accesses BOTH 'category' AND 'item' β must be re-fetched when either changes
*
* This is the inverse of the typical pattern. Usually the layout accesses fewer
* params than the page, enabling layout reuse. ... | { category: 'electronics', item: 'tablet' },
]
}
export default async function PageReuseLayout({
children,
params,
}: {
children: React.ReactNode
params: Promise<Params>
}) {
const { category, item } = await params
return (
<div data- |
* This tests that param access is tracked at the segment level, not just at
* the route level.
*/
export async function generateStaticParams(): Promise<Params[]> {
return [
{ category: 'electronics', item: 'phone' },
| {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/page-reuse/[category]/[item]/layout.tsx",
"language": "tsx",
"file_size": 1171,
"cut_index": 518,
"middle_length": 229
} |
kies, headers } from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
export const unstable_instant = {
unstable_samples: [
{
cookies: [{ name: 'testCookie', value: 'testValue' }],
headers: [['x-test-header', 'test']],
searchParams: {},
},
],
}
expo... | ry">
<Suspense fallback={<p>Loading cookies...</p>}>
<CookiesContent />
</Suspense>
</div>
<div id="headers-boundary">
<Suspense fallback={<p>Loading headers...</p>}>
<HeadersContent />
</Susp | />
<div id="search-params-boundary">
<Suspense fallback={<p>Loading search params...</p>}>
<SearchParamsContent searchParams={searchParams} />
</Suspense>
</div>
<div id="cookies-bounda | {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/runtime-prefetchable/page.tsx",
"language": "tsx",
"file_size": 2351,
"cut_index": 563,
"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/runtime-prefetchable-layout/two/page.tsx",
"language": "tsx",
"file_size": 1071,
"cut_index": 515,
"middle_length": 229
} |
layout for the root params test.
*
* This layout is the first layout in its route tree (no app/layout.tsx above it),
* which makes `rootParam` a "root param" accessible via `next/root-params`.
*
* The layout accesses rootParam via the next/root-params API to verify that
* root param access is properly tracked in... | st param = await rootParam()
return (
<html>
<body>
<div data-root-params-layout="true">
<div data-root-param={param}>
{`Root param layout - param: ${param}`}
</div>
{children}
</div>
| hildren,
}: {
children: React.ReactNode
}) {
con | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/[rootParam]/layout.tsx",
"language": "tsx",
"file_size": 945,
"cut_index": 606,
"middle_length": 52
} |
kAccordion } from '../../../components/link-accordion'
/**
* Index page for the root params vary test.
*
* This page links to routes that use the rootParams() API from next/navigation.
* The target routes are at /aaa and /bbb which have their own root layout
* (no shared app/layout.tsx above them), making `rootPa... | d
* 2. Click checkbox for "bbb" β should also fetch (not cached)
*/
export default function RootParamsIndexPage() {
return (
<div id="root-params-index">
<h1>Root Params Vary Test</h1>
<p>
Tests that root param access via rootPa | hing /aaa fetches the content
* - Prefetching /bbb triggers a NEW request (not a cache hit)
* because rootParam is tracked in varyParams
*
* Manual testing:
* 1. Click checkbox for "aaa" β triggers prefetch, content fetche | {
"filepath": "test/e2e/app-dir/segment-cache/vary-params/app/(main)/root-params/page.tsx",
"language": "tsx",
"file_size": 1301,
"cut_index": 524,
"middle_length": 229
} |
{ cacheLife } from 'next/cache'
import { connection } from 'next/server'
import { Suspense } from 'react'
export default function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
return (
<main>
<CachedContent />
<div id="params-boundary">
<Suspense fallback={<p>Loading params.... | }
async function ParamsContent({
params,
}: {
params: Promise<{ slug: string }>
}) {
// When the param is a fallback param (not in generateStaticParams), the
// await is deferred to the runtime stage, so this content won't appear
// in the stati | <ConnectionContent />
</Suspense>
</div>
</main>
)
}
async function CachedContent() {
'use cache'
cacheLife({ stale: 120 })
return <p id="cached-content">Cached content ({new Date().toISOString()})</p>
| {
"filepath": "test/e2e/app-dir/segment-cache/cached-navigations/app/with-fallback-params/[slug]/page.tsx",
"language": "tsx",
"file_size": 1198,
"cut_index": 518,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../../shared'
import { connection } from 'next/server'
import { lang } from 'next/root-params'
export const unstable_instant = {
unstable_samples: [{ params: { lang: 'en' } }],
}
export const unstable_prefetch = 'force-runtime'
export default a... | <RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
const currentLang = await privateCache()
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="root-param-value">{`Lan | ly rendered during runtime prefetches and
navigation requests, so they won't be part of a static prefetch, but
they should be part of a runtime prefetch.
</p>
<Suspense fallback="Loading 1...">
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/with-root-param/[lang]/in-private-cache/root-params/page.tsx",
"language": "tsx",
"file_size": 1559,
"cut_index": 537,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../../shared'
import { connection } from 'next/server'
import { lang } from 'next/root-params'
export const unstable_instant = {
unstable_samples: [{ params: { lang: 'en' } }],
}
export const unstable_prefetch = 'force-runtime'
export default a... | hable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
const currentLang = await publicCache(lang())
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="root-param-value">{`Lang: ${curren | always be available in static prerenders, so a
runtime prefetch should have them too, and they should not be considered
a hanging input.
</p>
<Suspense fallback="Loading 1...">
<RuntimePrefetc | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/with-root-param/[lang]/passed-to-public-cache/root-params/page.tsx",
"language": "tsx",
"file_size": 1585,
"cut_index": 537,
"middle_length": 229
} |
he'
import { setTimeout } from 'timers/promises'
export async function uncachedIO() {
await setTimeout(0)
}
export async function cachedDelay(key: any) {
'use cache'
cacheLife('minutes')
await setTimeout(1)
}
export function DebugRenderKind() {
const { workUnitAsyncStorage } =
require('next/dist/server... | re.type}
{(() => {
switch (workUnitStore.type) {
case 'prerender':
return '(static prefetch)'
case 'prerender-runtime':
return '(runtime prefetch)'
default:
return null
| n (
<div>
workUnitStore.type: {workUnitSto | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/shared.tsx",
"language": "tsx",
"file_size": 887,
"cut_index": 547,
"middle_length": 52
} |
pense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../../shared'
import { connection } from 'next/server'
import { lang } from 'next/root-params'
import { cookies } from 'next/headers'
export const unstable_instant = {
unstable_samples: [{ params: { lang: 'en' } }],
}
export const u... | in>
)
}
async function RuntimePrefetchable() {
await cookies()
const currentLang = await lang()
await cachedDelay([__filename, currentLang])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="root-param-value | ot params should
always be available in static prerenders, so a runtime prefetch should
have them too.
</p>
<Suspense fallback="Loading 1...">
<RuntimePrefetchable />
</Suspense>
</ma | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/with-root-param/[lang]/in-page/root-params/page.tsx",
"language": "tsx",
"file_size": 1392,
"cut_index": 524,
"middle_length": 229
} |
<li>
cookies + dynamic content
<ul>
<li>
<DebugLinkAccordion href="/in-page/cookies" />
</li>
</ul>
</li>
<li>
headers + dynamic content
<ul>
<li>
<DebugLinkAccordion href="/in-page/header... | params + dynamic content
<ul>
<li>
<DebugLinkAccordion href="/in-page/dynamic-params/123" />
</li>
<li>
<DebugLinkAccordion href="/in-page/dynamic-params/456" />
</li>
| earch-params?searchParam=123" />
</li>
<li>
<DebugLinkAccordion href="/in-page/search-params?searchParam=456" />
</li>
</ul>
</li>
<li>
dynamic | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/page.tsx",
"language": "tsx",
"file_size": 5915,
"cut_index": 716,
"middle_length": 229
} |
t/root-params'
import { DebugLinkAccordion } from '../../../components/link-accordion'
export default async function Page() {
const currentLang = await lang()
const otherLang = currentLang === 'en' ? 'de' : 'en'
return (
<main>
<h1>Home - with root param ({currentLang})</h1>
<h2>directly in a pa... | </ul>
</li>
</ul>
<h2>
<code>use cache: private</code>
</h2>
<ul>
<li>
root params + dynamic content
<ul>
<li>
<DebugLinkAccordion
href={`/with-r | /in-page/root-params`}
/>
</li>
<li>
<DebugLinkAccordion
href={`/with-root-param/${otherLang}/in-page/root-params`}
/>
</li>
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/with-root-param/[lang]/page.tsx",
"language": "tsx",
"file_size": 1894,
"cut_index": 537,
"middle_length": 229
} |
import { Suspense } from 'react'
type Params = {
pageNumber: string
}
export async function generateViewport({
params,
}: {
params: Promise<Params>
}) {
const { pageNumber } = await params
return {
// Put the page number into the media query. This is just a trick to allow
// the test to detect when ... | oading...">
<Content params={params} />
</Suspense>
)
}
export async function generateStaticParams(): Promise<Array<Params>> {
const result: Array<Params> = []
for (let n = 1; n <= 10; n++) {
result.push({ pageNumber: n.toString() })
| }) {
const { pageNumber } = await params
return 'Content of page ' + pageNumber
}
export default async function LinkCancellationTargetPage({
params,
}: {
params: Promise<Params>
}) {
return (
<Suspense fallback="L | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-scheduling/app/cancellation/[pageNumber]/page.tsx",
"language": "tsx",
"file_size": 1018,
"cut_index": 512,
"middle_length": 229
} |
ould throw, without swallowing the error.
*
* It calls `callback` and checks if it throws.
* If it did, we rethrow the error.
* If it didn't throw, we throw a AssertionError/ClientAssertionError.
* */
export function ensureThrows(callback: () => any, message?: string): never {
let thrown: { value: unknown } | nu... | ail(message)
} else {
throw new Error('This code should never run in the browser')
}
}
// For some reason, typescript doesn't believe that all codepaths above throw
throw new Error('Unreachable')
}
/**
* This helper is used for testi | k didn't throw like it should have.
message ??= 'Expected callback to throw'
if (typeof window === 'undefined') {
const { fail } =
require('node:assert/strict') as typeof import('node:assert/strict')
f | {
"filepath": "test/e2e/app-dir/instant-validation-build/ensure-error.ts",
"language": "typescript",
"file_size": 2067,
"cut_index": 563,
"middle_length": 229
} |
describe('invalid - missing suspense around runtime', () => {
it('should fail build when cookies are outside Suspense', async () => {
const result = await prerender(
'/(default)/invalid-missing-suspense-around-runtime'
)
expect(extractBuildValidationError(result.cliOutput))
... | access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/bloc | or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this:
- Cache the data | {
"filepath": "test/e2e/app-dir/instant-validation-build/instant-validation-build.test.ts",
"language": "typescript",
"file_size": 49773,
"cut_index": 2151,
"middle_length": 229
} |
import { lang } from 'next/root-params'
import { ensureRejects } from '../../../../ensure-error'
export const unstable_instant: Instant = {
level: 'experimental-error',
// no samples
unstable_samples: [{}],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
// Guard behi... | he error. It should still be reported and fail the validation.
}
return (
<main>
<p>
This page uses a root param. It's missing a sample for it, so we can't
validate it. It catches the error thrown by the rootparam call, but
| not provided`
)
} catch {
// We swallow t | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/root-params/[lang]/invalid-root-param-not-provided-caught/page.tsx",
"language": "tsx",
"file_size": 956,
"cut_index": 582,
"middle_length": 52
} |
} from 'next'
import { cookies } from 'next/headers'
import { lang } from 'next/root-params'
import assert from 'node:assert/strict'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [{ params: { lang: 'en-from-samples' } }],
}
export const unstable_prefetch = 'force-runtime... | es`
const currentLang = await lang()
assert.equal(currentLang, 'en-from-samples', `Unexpected \`lang()\``)
return (
<main>
<p>
This page uses a root param. It should get it from samples, not
generateStaticParams.
</p> | on, so we should only observe the `lang` from `sampl | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/root-params/[lang]/valid-root-param-in-samples/runtime/page.tsx",
"language": "tsx",
"file_size": 856,
"cut_index": 529,
"middle_length": 52
} |
mport assert from 'node:assert/strict'
import { Suspense } from 'react'
// No unstable_instant here β should inherit samples from the layout.
export default async function Page({
params,
}: {
params: Promise<Record<string, string>>
}) {
return (
<main>
<p>
This page does not define unstable_in... | in>
)
}
async function TestParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
const p = await params
assert.equal(
p.slug,
'from-layout',
`Expected param 'slug' to be 'from-layout', got '${p.slug}'`
)
return null
| ense>
</ma | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/samples-precedence/[slug]/page-inherits/page.tsx",
"language": "tsx",
"file_size": 787,
"cut_index": 513,
"middle_length": 14
} |
import assert from 'node:assert/strict'
import { Suspense } from 'react'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
params: {
slug: 'from-page',
},
},
],
}
export default async function Page({
params,
}: {
params: Promise<Record... | <TestParams params={params} />
</Suspense>
</main>
)
}
async function TestParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
const p = await params
assert.equal(
p.slug,
'from-page',
`Expected param 'slug | <Suspense fallback={<div>Loading...</div>}>
| {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/samples-precedence/[slug]/page-overrides/page.tsx",
"language": "tsx",
"file_size": 913,
"cut_index": 547,
"middle_length": 52
} |
rom 'next'
import assert from 'node:assert/strict'
import { Suspense } from 'react'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
searchParams: {
// TODO(instant-validation-build): specify and test escaping behavior for spaces etc
single: '... | ecified in the sample.
</p>
<Suspense fallback={<div>Loading...</div>}>
<TestSearchParams searchParams={searchParams} />
</Suspense>
</main>
)
}
async function TestSearchParams({
searchParams,
}: {
searchParams: Promise | rt default async function Page({
searchParams,
}: {
searchParams: Promise<{ foo?: string | string[] }>
}) {
return (
<main>
<p>
When validated in build, the page should receive the search params
sp | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/search-params/valid-search-params-in-samples/page.tsx",
"language": "tsx",
"file_size": 1549,
"cut_index": 537,
"middle_length": 229
} |
rict'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
searchParams: {
single: 'test',
multiple: ['a', 'b'],
},
},
],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page({
searchParams,
}: {
se... | | string[]>
}) {
'use cache'
assert.equal(
searchParams.single,
'test',
`Expected searchParams.single to be 'test', got '${searchParams.single}'`
)
assert.deepStrictEqual(
searchParams.multiple,
['a', 'b'],
`Unexpected valu | chParams,
}: {
searchParams: Record<string, string | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/search-params/valid-search-params-passed-to-cache/page.tsx",
"language": "tsx",
"file_size": 968,
"cut_index": 582,
"middle_length": 52
} |
rict'
import { ClientChild } from './client'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
searchParams: {
single: 'test',
multiple: ['a', 'b'],
},
},
],
}
export const unstable_prefetch = 'force-runtime'
export default async f... | ,
}: {
searchParams: Promise<Record<string, string | string[]>>
}) {
const sp = await searchParams
assert.equal(
sp.single,
'test',
`Expected 'single' to be 'test', got '${sp.single}'`
)
assert.deepStrictEqual(
sp.multiple,
[' |
}
async function TestSearchParams({
searchParams | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/search-params/valid-search-params-passed-to-client/page.tsx",
"language": "tsx",
"file_size": 987,
"cut_index": 582,
"middle_length": 52
} |
e-error'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ q?: string; undeclared?: string }>
}) {
return (
... | c function SearchResult({
searchParams,
}: {
searchParams: Promise<{ q?: string; undeclared?: string }>
}) {
const sp = await searchParams
ensureThrows(
() => sp.undeclared,
`Expected accessing an undeclared search param to throw`
)
ret | archParams={searchParams} />
</main>
)
}
asyn | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/search-params/invalid-undeclared-search-param/page.tsx",
"language": "tsx",
"file_size": 878,
"cut_index": 559,
"middle_length": 52
} |
{ ensureThrows } from '../../../../ensure-error'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ searchParams: { q: 'test' } }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ q?: string; u... | rchParams,
}: {
searchParams: Promise<{ q?: string; undeclared?: string }>
}) {
const sp = await searchParams
try {
ensureThrows(
() => sp.undeclared,
`Expected accessing an undeclared search param to throw`
)
} catch (err) {
| error. It catches the
error thrown by the searchParam access, but validation should still
fail.
</p>
<SearchResult searchParams={searchParams} />
</main>
)
}
async function SearchResult({
sea | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/search-params/invalid-undeclared-search-param-caught/page.tsx",
"language": "tsx",
"file_size": 1144,
"cut_index": 518,
"middle_length": 229
} |
{ Instant } from 'next'
import assert from 'node:assert/strict'
import { ensureThrows } from '../../../../../../ensure-error'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
params: {
one: '123',
// two: <missing>
},
},
],
}
export... | stParams params={params} />
</main>
)
}
async function TestParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
const p = await params
assert.equal(p.one, '123', `Unexpected value for param 'one'`)
try {
// We're not al | reads a param that is not declared in the sample, so it should
fail validation with an exhaustiveness error. It catches the error
thrown by the param access, but validation should still fail.
</p>
<Te | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/params/invalid-param-not-provided-caught/[one]/[two]/page.tsx",
"language": "tsx",
"file_size": 1464,
"cut_index": 524,
"middle_length": 229
} |
ort type { Instant } from 'next'
import assert from 'node:assert/strict'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
params: {
one: '123',
two: '456',
},
},
],
}
export const unstable_prefetch = 'force-runtime'
export default ... | p
assert.equal(one, '123', `Unexpected value for param 'one'`)
assert.equal(two, '456', `Unexpected value for param 'two'`)
assert.equal('three' in p, false)
assert.equal(p.three, undefined)
assert.deepStrictEqual(
{ ...p },
{ one: '12 | d in
the sample.
</p>
<TestParams params={params} />
</main>
)
}
async function TestParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
const p = await params
const { one, two } = | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/params/valid-params-in-samples/[one]/[two]/page.tsx",
"language": "tsx",
"file_size": 1096,
"cut_index": 515,
"middle_length": 229
} |
{ Instant } from 'next'
import assert from 'node:assert/strict'
import { ensureThrows } from '../../../../../../ensure-error'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
params: {
one: '123',
// two: <missing>
},
},
],
}
export... | params: Promise<Record<string, string>>
}) {
const p = await params
assert.equal(p.one, '123', `Unexpected value for param 'one'`)
// We're allowed to access names that don't correspond to a param.
assert.equal('three' in p, false)
assert.equa | reads a param that is not declared in the sample, so it should
fail validation with an exhaustiveness error.
</p>
<TestParams params={params} />
</main>
)
}
async function TestParams({
params,
}: {
| {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/params/invalid-param-not-provided/[one]/[two]/page.tsx",
"language": "tsx",
"file_size": 1321,
"cut_index": 524,
"middle_length": 229
} |
'../../../../client-assertion-error'
/**
* Asserts that client hooks receive sample params during instant validation,
* not the values from generateStaticParams. This component is inside a Suspense
* boundary gated by `await cookies()`, so it only renders during validation.
*/
export function AssertParamsClient() ... | `Expected useParams().slug === 'hello' (from sample), got '${params.slug}'`
)
// usePathname() should reflect the sample param value too.
assert(
pathname === '/gsp/hello',
`Expected usePathname() === '/gsp/hello', got '${pathname}'`
)
| or 'bar').
assert(
params.slug === 'hello',
| {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/gsp/[slug]/client.tsx",
"language": "tsx",
"file_size": 931,
"cut_index": 606,
"middle_length": 52
} |
rom 'next'
import assert from 'node:assert/strict'
import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { AssertParamsClient } from './client'
// samples use 'hello', but generateStaticParams uses 'foo'/'bar'.
// During validation, the sample params should be used, not the GSP values.
export ... | <Suspense fallback={<div>Loading...</div>}>
<AssertSampleParams params={params} />
</Suspense>
</main>
)
}
async function AssertSampleParams({
params,
}: {
params: Promise<Record<string, string>>
}) {
// Gate behind cookies() so | orce-runtime'
export function generateStaticParams() {
return [{ slug: 'foo' }, { slug: 'bar' }]
}
export default async function Page({
params,
}: {
params: Promise<Record<string, string>>
}) {
return (
<main>
| {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/gsp/[slug]/page.tsx",
"language": "tsx",
"file_size": 1694,
"cut_index": 537,
"middle_length": 229
} |
type { Instant } from 'next'
import { cookies } from 'next/headers'
import assert from 'node:assert'
import { Suspense } from 'react'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
cookies: [
{ name: 'testCookie', value: 'testValue' },
{ na... | stCookies() {
const cookieStore = await cookies()
const testCookie = cookieStore.get('testCookie')
assert.deepStrictEqual(testCookie, {
name: 'testCookie',
value: 'testValue',
})
const missingCookie = cookieStore.get('missingCookie')
| validated in build, the page should receive the cookies specified
in the sample.
</p>
<Suspense fallback={<div>Loading...</div>}>
<TestCookies />
</Suspense>
</main>
)
}
async function Te | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/cookies/valid-cookies-in-samples/page.tsx",
"language": "tsx",
"file_size": 1218,
"cut_index": 518,
"middle_length": 229
} |
'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = { level: 'experimental-error' }
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<p>
This page reads a cookie that is not declared in the sample, so it
... | /Suspense>
</main>
)
}
async function TestCookies() {
const cookieStore = await cookies()
try {
ensureThrows(
() => cookieStore.get('undeclaredCookie'),
`Expected get() to throw for undeclared cookies`
)
} catch (err) {
| v>Loading...</div>}>
<TestCookies />
< | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/cookies/invalid-undeclared-cookie-get-caught/page.tsx",
"language": "tsx",
"file_size": 991,
"cut_index": 582,
"middle_length": 52
} |
eaders } from 'next/headers'
import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
retu... | ading...</div>}>
<TestHeaders />
</Suspense>
</main>
)
}
async function TestHeaders() {
const headerStore = await headers()
ensureThrows(
() => headerStore.has('undeclaredHeader'),
`Expected has() to throw for undeclared he | lback={<div>Lo | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/headers/invalid-undeclared-header-has/page.tsx",
"language": "tsx",
"file_size": 819,
"cut_index": 522,
"middle_length": 14
} |
ort type { Instant } from 'next'
import { headers } from 'next/headers'
import assert from 'node:assert'
import { Suspense } from 'react'
export const unstable_instant: Instant = {
level: 'experimental-error',
unstable_samples: [
{
headers: [
['testHeader', 'testValue'],
['missingHeader'... | rStore = await headers()
const testHeader = headerStore.get('testHeader')
assert.equal(testHeader, 'testValue')
const missingHeader = headerStore.get('missingHeader')
assert.equal(missingHeader, undefined)
assert.equal(headerStore.has('missingH | ge should receive the headers specified
in the sample.
</p>
<Suspense fallback={<div>Loading...</div>}>
<TestHeaders />
</Suspense>
</main>
)
}
async function TestHeaders() {
const heade | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/headers/valid-headers-in-samples/page.tsx",
"language": "tsx",
"file_size": 1086,
"cut_index": 515,
"middle_length": 229
} |
mport { headers } from 'next/headers'
import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page()... | st headerStore = await headers()
try {
ensureThrows(
() => headerStore.get('undeclaredHeader'),
`Expected get() to throw for undeclared headers`
)
} catch (err) {
// We swallow the error. It should still be reported and fail th | error thrown by the header access, but validation should still fail.
</p>
<Suspense fallback={<div>Loading...</div>}>
<TestHeaders />
</Suspense>
</main>
)
}
async function TestHeaders() {
con | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/headers/invalid-undeclared-header-get-caught/page.tsx",
"language": "tsx",
"file_size": 1033,
"cut_index": 513,
"middle_length": 229
} |
mport { headers } from 'next/headers'
import { Suspense } from 'react'
import { ensureThrows } from '../../../../ensure-error'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ headers: [] }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page()... | tHeaders />
</Suspense>
</main>
)
}
async function TestHeaders() {
const headersStore = await headers()
ensureThrows(
() => headersStore.get('undeclaredHeader'),
`Expected get() to throw for undeclared headers`
)
return null
}
| pense fallback={<div>Loading...</div>}>
<Tes | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/headers/invalid-undeclared-header-get/page.tsx",
"language": "tsx",
"file_size": 821,
"cut_index": 513,
"middle_length": 52
} |
nse } from 'react'
export const unstable_instant = {
level: 'experimental-error',
unstable_samples: [{ cookies: [{ name: 'auth', value: '1' }] }],
}
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<p>
This page wraps all runtime/dynamic c... | se>
</main>
)
}
async function Runtime() {
const c = await cookies()
return <div id="runtime-content">cookie: {c.get('auth')?.value}</div>
}
async function Dynamic() {
await connection()
return <div id="dynamic-content">Dynamic content</div | oading...</div>}>
<Dynamic />
</Suspen | {
"filepath": "test/e2e/app-dir/instant-validation-build/app/(default)/valid-suspense-around-runtime/page.tsx",
"language": "tsx",
"file_size": 918,
"cut_index": 606,
"middle_length": 52
} |
('preferred-region', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
})
it('should return success from Node.js API route', async () => {
const res = await next.fetch('/api/test')
expect(res.status).toBe(200)
const data = await res.json()
expect(data).toEqual({ status:... | igManifest
let middlewareManifest
try {
// Check Functions Config Manifest (for Node.js runtime)
functionsConfigManifest = JSON.parse(
await next.readFile('.next/server/functions-config-manifest.json')
)
| res.json()
expect(data).toEqual({ status: 'success', runtime: 'edge' })
})
it('should include preferredRegion in functions config manifest for nodejs runtime', async () => {
if (isNextStart) {
let functionsConf | {
"filepath": "test/e2e/app-dir/preferred-region/preferred-region.test.ts",
"language": "typescript",
"file_size": 2735,
"cut_index": 563,
"middle_length": 229
} |
rs'
import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared'
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_disableValidation: true,
unstable_samples: [{ cookies: [] }],
}
e... | the error in a runtime prefetch
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await cookies()
retur | after a cookies() call, so we should only see
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/cookies/page.tsx",
"language": "tsx",
"file_size": 909,
"cut_index": 547,
"middle_length": 52
} |
from 'next/link'
import { useState } from 'react'
type PaginationConfig = {
start: number
end: number
}
export default function LinkCancellationPage() {
const [areLinksVisible, setLinksVisibility] = useState(false)
const [showMoreLinks, setShowMoreLinks] = useState(false)
return (
<>
<p>
... | !areLinksVisible)}
/>
{areLinksVisible ? 'Hide' : 'Show'} Links
</label>
<ul id="links-container" hidden={!areLinksVisible}>
<Links start={1} end={7} />
{showMoreLinks ? (
<Links start={8} end={10} />
| re mounted, only whether they are
visible (using the `hidden` attribute).
</p>
<label>
<input
type="checkbox"
checked={areLinksVisible}
onChange={() => setLinksVisibility( | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-scheduling/app/cancellation/page.tsx",
"language": "tsx",
"file_size": 1679,
"cut_index": 537,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ params: { id: 'test' } }],
}
export const unstable_prefetch = 'force-runtime'
type Params = { id: string }
export default async funct... | ync function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
const id = await privateCache(params)
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="param-value">{`Param: ${id}`}</div>
<Suspense | so parts of it should be runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable params={params} />
</Suspense>
</main>
)
}
as | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/dynamic-params/[id]/page.tsx",
"language": "tsx",
"file_size": 1518,
"cut_index": 537,
"middle_length": 229
} |
pense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p... | dding: '1em' }}>
<div id="timestamp">{`Timestamp: ${now}`}</div>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 2...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
async function privateCache() {
'use cache: priva | rey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
const now = await privateCache()
return (
<div style={{ border: '1px solid blue', pa | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/date-now/page.tsx",
"language": "tsx",
"file_size": 1304,
"cut_index": 524,
"middle_length": 229
} |
next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force... | ormData: FormData) => {
'use server'
const cookieStore = await cookies()
const cookieValue = formData.get('cookie') as string | null
if (cookieValue) {
cookieStore.set('testCookie', cookieValue)
| IO, so parts of it should be runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
<form
action={async (f | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/cookies/page.tsx",
"language": "tsx",
"file_size": 1973,
"cut_index": 537,
"middle_length": 229
} |
next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ headers: [['host', 'test-host']] }],
}
export const unstable_prefetch = 'force-runtime'
export def... |
const headerValue = await privateCache()
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="header-value">{`Header: ${headerValue}`}</div>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 2...</div>} | should be runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() { | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/headers/page.tsx",
"language": "tsx",
"file_size": 1541,
"cut_index": 537,
"middle_length": 229
} |
import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force-runtime'
export default as... | = 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">{`Cookie: ${cookieVal | e prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
const cookieStore | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-page/cookies-only/page.tsx",
"language": "tsx",
"file_size": 1026,
"cut_index": 512,
"middle_length": 229
} |
ders } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ headers: [['host', 'test-host']] }],
}
export const unstable_prefetch = 'force-runtime... | tore = await headers()
const headerValue = headersStore.get('host') === null ? 'missing' : 'present'
await cachedDelay([__filename, headerValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="header-value">{`H | e-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
const headersS | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-page/headers/page.tsx",
"language": "tsx",
"file_size": 1389,
"cut_index": 524,
"middle_length": 229
} |
kies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force-runtime'
export default async function... | ookies() // Guard from being statically prerendered, which would make the cache hang
// We've already awaited cookies, but we still want to make sure
// that the cache doesn't consider them a hanging promise
const cookieValue = await publicCache(
| th a runtime prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await c | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/passed-to-public-cache/cookies-only/page.tsx",
"language": "tsx",
"file_size": 1453,
"cut_index": 524,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared'
import { connection } from 'next/server'
import { cookies } from 'next/headers'
export const unstable_instant = {
unstable_samples: [{ params: { id: 'test' } }],
}
export const unstable_prefetch = 'force-runtime'
type Params = { id: string }
... | arams={params} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
await cookies() // Guard from being statically prerendered, which would make the cache hang
const id = await publicCac | he, and uses some
uncached IO, so parts of it should be prefetchable with a runtime
prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable p | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/passed-to-public-cache/dynamic-params/[id]/page.tsx",
"language": "tsx",
"file_size": 1638,
"cut_index": 537,
"middle_length": 229
} |
mport { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id... | ense>
</main>
)
}
async function ShortLivedCache() {
'use cache: private'
cacheLife('seconds')
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
Short-lived cached content
<d | prefetch, because it has a long enough stale time
(≥ RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading...</div>}>
<ShortLivedCache />
</Susp | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/private-seconds/page.tsx",
"language": "tsx",
"file_size": 1055,
"cut_index": 513,
"middle_length": 229
} |
{ Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id="int... | pense>
</main>
)
}
async function ShortLivedCache() {
'use cache'
cacheLife({
stale: 60, // > RUNTIME_PREFETCH_DYNAMIC_STALE
revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE
})
await cachedDelay([__filename])
return (
| e prefetch, because it has a long enough stale time
(≥ RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading...</div>}>
<ShortLivedCache />
</Sus | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/public-short-expire-long-stale/page.tsx",
"language": "tsx",
"file_size": 1163,
"cut_index": 518,
"middle_length": 229
} |
ort { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id="... | stale: 5,
// the rest of the settings don't matter for private caches,
// because they are not persisted server-side
})
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
Short-l | </p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading...</div>}>
<CachedButShortLived />
</Suspense>
</main>
)
}
async function CachedButShortLived() {
'use cache: private'
cacheLife({
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/private-short-stale/page.tsx",
"language": "tsx",
"file_size": 1085,
"cut_index": 515,
"middle_length": 229
} |
{ cookies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { ErrorBoundary } from '../../../../components/error-boundary'
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation... | tion (and not during prerendering /
prefetching)
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<ErrorBoundary>
<One />
</ErrorBoundary>
</Suspense>
</main>
)
}
async |
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id="intro">
This page errors after a cookies call, so we should only see the error
in a runtime prefetch or a naviga | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/error-after-cookies/page.tsx",
"language": "tsx",
"file_size": 1176,
"cut_index": 518,
"middle_length": 229
} |
} from '../../../../shared'
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_disableValidation: true,
unstable_samples: [{ cookies: [] }],
}
export const unstable_prefetch = 'force-runtime'
export defau... | uspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await privateCache()
return <div id="timestamp">Timestamp: {Date.now()}</d | the error in a runtime prefetch
</p>
<S | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/private-cache/page.tsx",
"language": "tsx",
"file_size": 987,
"cut_index": 582,
"middle_length": 52
} |
./../../../shared'
type Params = { id: string }
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_disableValidation: true,
unstable_samples: [{ cookies: [] }],
}
export const unstable_prefetch = 'force-ru... | he error in a runtime prefetch
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable params={params} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({ params }: { pa | ter awaiting params, so we should only see
t | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/dynamic-params/[id]/page.tsx",
"language": "tsx",
"file_size": 993,
"cut_index": 582,
"middle_length": 52
} |
ver', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/cancellation', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
})
const checkbox = await browser.elementByCss('input[type="checkbox"]')
await act(
async ... | .
const link2 = await browser.elementByCss('a[href="/cancellation/2"]')
await link2.hover()
// Hover over a different link to increase its relative priority.
const link5 = await browser.elementByCss('a[href="/cancellation/5 | t start prefetching any segment data yet until the
// trees have loaded.
await act(async () => {
await checkbox.click()
}, 'block')
// Hover over a link to increase its relative priority | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-scheduling/prefetch-scheduling.test.ts",
"language": "typescript",
"file_size": 10171,
"cut_index": 921,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ searchParams: { searchParam: 'value' } }],
}
export const unstable_prefetch = 'force-runtime'
type AnySearchParams = { [key: string]: str... | >
<RuntimePrefetchable searchParams={searchParams} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({
searchParams,
}: {
searchParams: Promise<AnySearchParams>
}) {
const searchParam = await privateCache(searchParams | This page uses search params (passed to a private cache) and some
uncached IO, so parts of it should be runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>} | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/search-params/page.tsx",
"language": "tsx",
"file_size": 1731,
"cut_index": 537,
"middle_length": 229
} |
{ cookies } from 'next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force-runtime'
export default async fu... | onst cookieValue = await privateCache()
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value">{`Cookie: ${cookieValue}`}</div>
</div>
)
}
async function privateCache() {
'use cache: private'
const | ble with a runtime prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
c | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-private-cache/cookies-only/page.tsx",
"language": "tsx",
"file_size": 1171,
"cut_index": 518,
"middle_length": 229
} |
next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force... | 'use server'
const cookieStore = await cookies()
const cookieValue = formData.get('cookie') as string | null
if (cookieValue) {
cookieStore.set('testCookie', cookieValue)
}
}}
>
| runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
<form
action={async (formData: FormData) => {
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-page/cookies/page.tsx",
"language": "tsx",
"file_size": 1821,
"cut_index": 537,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { connection } from 'next/server'
import { cookies } from 'next/headers'
export const unstable_instant = {
unstable_samples: [{ searchParams: { searchParam: 'value' } }],
}
export const unstable_prefetch = 'force-runtime'
type AnySearchPa... | e={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable searchParams={searchParams} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({
searchParams,
}: {
searchParams: Promise<AnySearchParams>
}) {
await cook | bugRenderKind />
<p>
This page passes search params to a public cache, and uses some uncached
IO, so parts of it should be prefetchable with a runtime prefetch.
</p>
<Suspense fallback={<div styl | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/passed-to-public-cache/search-params/page.tsx",
"language": "tsx",
"file_size": 1835,
"cut_index": 537,
"middle_length": 229
} |
mport { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id... | nse>
</main>
)
}
async function ShortLivedCache() {
'use cache'
cacheLife('seconds')
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
Short-lived cached content
<div id="cac | prefetch, because it has a long enough stale time
(≥ RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading...</div>}>
<ShortLivedCache />
</Suspe | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/public-seconds/page.tsx",
"language": "tsx",
"file_size": 1045,
"cut_index": 513,
"middle_length": 229
} |
ort { DebugLinkAccordion } from '../../../components/link-accordion'
export default async function Page() {
return (
<main>
<h1>Errors</h1>
<h2>thrown errors</h2>
<ul>
<li>
<DebugLinkAccordion href="/errors/error-after-cookies" />
</li>
</ul>
<h2>sync IO<... | ter-runtime-api/search-params?foo=bar" />
</li>
<li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/private-cache" />
</li>
<li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/qu | ter-runtime-api/headers" />
</li>
<li>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/dynamic-params/123" />
</li>
<li>
<DebugLinkAccordion href="/errors/sync-io-af | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/page.tsx",
"language": "tsx",
"file_size": 1076,
"cut_index": 515,
"middle_length": 229
} |
ort { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared'
type AnySearchParams = { [key: string]: string | string[] | undefined }
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_d... | /p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable searchParams={searchParams} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({
searchParams,
}: {
searchParams: Pro | mise<AnySearchParams>
}) {
return (
<main>
<DebugRenderKind />
<p id="intro">
This page performs sync IO after awaiting searchParams, so we should
only see the error in a runtime prefetch
< | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/search-params/page.tsx",
"language": "tsx",
"file_size": 1109,
"cut_index": 515,
"middle_length": 229
} |
pense } from 'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ params: { id: 'test' } }],
}
export const unstable_prefetch = 'force-runtime'
type Params = { id: string }
export defaul... | ntimePrefetchable({ params }: { params: Promise<Params> }) {
const { id } = await params
await cachedDelay([__filename, id])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="param-value">{`Param: ${id}`}</div>
| ould be
runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable params={params} />
</Suspense>
</main>
)
}
async function Ru | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-page/dynamic-params/[id]/page.tsx",
"language": "tsx",
"file_size": 1357,
"cut_index": 524,
"middle_length": 229
} |
pense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ cookies: [{ name: 'testCookie', value: 'testValue' }] }],
}
export const unstable_prefetch = 'force-runtime'
export default async functi... | 'use server'
const cookieStore = await cookies()
const cookieValue = formData.get('cookie') as string | null
if (cookieValue) {
cookieStore.set('testCookie', cookieValue)
}
}}
>
| le with a runtime prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
<form
action={async (formData: FormData) => {
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/passed-to-public-cache/cookies/page.tsx",
"language": "tsx",
"file_size": 2234,
"cut_index": 563,
"middle_length": 229
} |
{ Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = true
export const unstable_prefetch = 'force-runtime'
export default async function Page() {
return (
<main>
<DebugRenderKind />
<p id="int... | </Suspense>
</main>
)
}
async function ShortLivedCache() {
'use cache'
cacheLife({
stale: 20, // < RUNTIME_PREFETCH_DYNAMIC_STALE
revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE
})
await cachedDelay([__filename])
| a runtime prefetch, because it has a short
enough stale time (< RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading...</div>}>
<ShortLivedCache />
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/public-short-expire-short-stale/page.tsx",
"language": "tsx",
"file_size": 1173,
"cut_index": 518,
"middle_length": 229
} |
rs'
import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared'
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_disableValidation: true,
unstable_samples: [{ cookies: [] }],
}
e... | the error in a runtime prefetch
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await headers()
retur | after a headers() call, so we should only see
| {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/headers/page.tsx",
"language": "tsx",
"file_size": 909,
"cut_index": 547,
"middle_length": 52
} |
next/headers'
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ headers: [['host', 'test-host']] }],
}
export const unstable_prefetch = 'force-runtime'
export default async f... |
await headers() // Guard from being statically prerendered, which would make the cache hang
// We've already awaited headers, but we still want to make sure
// that the cache doesn't consider them a hanging promise
const headerValue = await publi | tchable with a runtime prefetch.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() { | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/passed-to-public-cache/headers/page.tsx",
"language": "tsx",
"file_size": 1794,
"cut_index": 537,
"middle_length": 229
} |
'react'
import { cachedDelay, DebugRenderKind, uncachedIO } from '../../../shared'
import { connection } from 'next/server'
export const unstable_instant = {
unstable_samples: [{ searchParams: { searchParam: 'value' } }],
}
export const unstable_prefetch = 'force-runtime'
type AnySearchParams = { [key: string]: str... | le searchParams={searchParams} />
</Suspense>
</main>
)
}
async function RuntimePrefetchable({
searchParams,
}: {
searchParams: Promise<AnySearchParams>
}) {
const { searchParam } = await searchParams
await cachedDelay([__filename, sea | This page uses search params and some uncached IO, so parts of it should
be runtime-prefetchable.
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Loading 1...</div>}>
<RuntimePrefetchab | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/in-page/search-params/page.tsx",
"language": "tsx",
"file_size": 1531,
"cut_index": 537,
"middle_length": 229
} |
mport { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_instant = {
// We're intentionally testing error behavior at runtime.
// Build-time validation catches it and prevents that.
unstable_disableValidation: t... | ing 1...</div>}>
<RuntimePrefetchable />
</Suspense>
</main>
)
}
async function RuntimePrefetchable() {
await publicCache()
return <div id="timestamp">Timestamp: {Date.now()}</div>
}
async function publicCache() {
'use cache'
| id="intro">
This page performs sync IO after awaiting a quickly-expiring public
cache, so we should only see the error in a runtime prefetch
</p>
<Suspense fallback={<div style={{ color: 'grey' }}>Load | {
"filepath": "test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/errors/sync-io-after-runtime-api/quickly-expiring-public-cache/page.tsx",
"language": "tsx",
"file_size": 1054,
"cut_index": 513,
"middle_length": 229
} |
{import('next').NextConfig}
*/
const nextConfig = {
turbopack: {
rules: {
'*': [
{
// Exact match for text/javascript content type
condition: { contentType: 'text/javascript' },
loaders: [require.resolve('./js-loader.js')],
as: '*.js',
},
{
... | image-loader.js')],
as: '*.js',
},
],
},
},
webpack: (config) => {
config.module.rules.push(
{
mimetype: 'text/javascript',
use: [{ loader: require.resolve('./js-loader.js') }],
type: 'javas | loaders: [require.resolve('./text-loader.js')],
as: '*.js',
},
{
// Regex match for image content types
condition: { contentType: /^image\// },
loaders: [require.resolve('./ | {
"filepath": "test/e2e/app-dir/turbopack-loader-content-type/next.config.js",
"language": "javascript",
"file_size": 1393,
"cut_index": 524,
"middle_length": 229
} |
pense } from 'react'
import { cacheLife, cacheTag, revalidatePath, updateTag } from 'next/cache'
import { redirect } from 'next/navigation'
import { connection } from 'next/server'
import React from 'react'
async function getData() {
'use cache'
cacheLife({ revalidate: 6 })
cacheTag('modern')
return new Date... | teTag('modern')
}}
>
Revalidate Tag
</button>{' '}
<button
id="revalidate-path"
formAction={async () => {
'use server'
revalidatePath('/')
}}
>
| main>
<Suspense fallback={<p>Loading...</p>}>
<AsyncComp />
</Suspense>
<form>
<button
id="revalidate-tag"
formAction={async () => {
'use server'
upda | {
"filepath": "test/e2e/app-dir/use-cache-custom-handler/app/page.tsx",
"language": "tsx",
"file_size": 1333,
"cut_index": 524,
"middle_length": 229
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.