prefix stringlengths 512 512 | suffix stringlengths 256 256 | middle stringlengths 14 229 | meta dict |
|---|---|---|---|
t: true,
})
if (skipped) {
return
}
if (isNextDev) {
// In next dev there really isn't a prospective render but we still assert we error on the first visit to each page
it('should error on the first visit to each page', async () => {
let res
res = await next.fetch('/error')
expe... | res = await next.fetch('/null')
expect(res.status).toBe(500)
res = await next.fetch('/null')
expect(res.status).toBe(200)
res = await next.fetch('/null')
expect(res.status).toBe(200)
// To make disambiguating cli out | next.fetch('/routes/error')
expect(res.status).toBe(500)
res = await next.fetch('/routes/error')
expect(res.status).toBe(200)
res = await next.fetch('/routes/error')
expect(res.status).toBe(200)
| {
"filepath": "test/e2e/app-dir/cache-components-errors/cache-components-errors.prospective-errors.test.ts",
"language": "typescript",
"file_size": 10912,
"cut_index": 921,
"middle_length": 229
} |
the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at a (<ne... | anonymous>)
at body (<anonymous>)
at html (<anonymous>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at m (<next-dist-dir>)
at n (<next-dist- | at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at main (< | {
"filepath": "test/e2e/app-dir/cache-components-errors/cache-components-errors.test.ts",
"language": "typescript",
"file_size": 421848,
"cut_index": 13624,
"middle_length": 229
} |
{ isNextDev, nextTestSetup } from 'e2e-utils'
describe('Cache Components Errors', () => {
const { next, skipped } = nextTestSetup({
files: __dirname + '/fixtures/unstable-deprecations',
})
if (skipped) {
return
}
describe('Deprecating `unstable` prefix for `cacheLife` and `cacheTag`', () => {
... | use `cacheTag` through `unstable_cacheTag`', async () => {
if (isNextDev) {
await next.browser('/tag')
expect(next.cliOutput).toContain(
'Error: `unstable_cacheTag` was recently stabilized'
)
} else {
| rror: `unstable_cacheLife` was recently stabilized'
)
} else {
expect(next.cliOutput).toContain(
'Error: `unstable_cacheLife` was recently stabilized'
)
}
})
it('warns if you | {
"filepath": "test/e2e/app-dir/cache-components-errors/cache-components-unstable-deprecations.test.ts",
"language": "typescript",
"file_size": 1133,
"cut_index": 518,
"middle_length": 229
} |
nopqrstuvwxyz'
const hostElementsUsedInFixtures = ['html', 'body', 'main', 'div']
const ignoredLines = [
'Generating static pages',
'Inlining static env',
'Finalizing page optimization',
]
/**
* Converts a module function sequence expression, e.g.:
* - (0 , __TURBOPACK__imported__module__1836__.cookies)(...)
... | boolean; startingLineMatch?: string }
): string {
const lines: string[] = []
// If no starting line match is provided, we start from the beginning.
let foundStartingLine = !startingLineMatch
let a = 0
let n = 0
const replaceNextDistStackFram | tput: string
): string {
return output.replace(/\(0 , \w+\.(\w+)\)\(\.\.\.\)/, '<module-function>()')
}
export function getDeterministicOutput(
cliOutput: string,
{
isMinified,
startingLineMatch,
}: { isMinified: | {
"filepath": "test/e2e/app-dir/cache-components-errors/utils.ts",
"language": "typescript",
"file_size": 3924,
"cut_index": 614,
"middle_length": 229
} |
ionOne, IndirectionTwo } from './indirection'
import { cookies } from 'next/headers'
export default async function Page() {
return (
<>
<p>
This page calls fetches eight times. Four are cached and Four are not.
In each set of Four, two are wrapped in Suspense. This leaves two
fetche... | </IndirectionOne>
<IndirectionTwo>
<FetchingComponent nonce="c" />
<Suspense fallback="loading...">
<FetchingComponent nonce="d" />
</Suspense>
</IndirectionTwo>
<FetchingComponent nonce="e" />
<Su | o the offending IO
</p>
<IndirectionOne>
<FetchingComponent nonce="a" cached={true} />
<Suspense fallback="loading...">
<FetchingComponent nonce="b" cached={true} />
</Suspense>
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/dynamic-root/page.tsx",
"language": "tsx",
"file_size": 2103,
"cut_index": 563,
"middle_length": 229
} |
se
export async function generateMetadata() {
await new Promise((r) => setTimeout(r, 0))
return { title: 'Dynamic Metadata' }
}
export default async function Page() {
return (
<>
<p>
This page is static except for `generateMetadata`. It opts into a fully
dynamic, blocking route via `ex... | teMetadata`. So even with the
opt-in, we still expect the dynamic-metadata error to be shown to nudge
users back toward making `generateMetadata` static (or, secondarily,
making the page partially dynamic).
</p>
<span id | a
documented mitigation for dynamic `genera | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/dynamic-metadata-static-with-instant-false/page.tsx",
"language": "tsx",
"file_size": 901,
"cut_index": 547,
"middle_length": 52
} |
from 'react'
import { IndirectionOne, IndirectionTwo, IndirectionThree } from './indirection'
type SearchParams = { foo: string | string[] | undefined }
export default async function Page(props: {
searchParams: Promise<SearchParams>
}) {
return (
<>
<p>
This page accesses Math.random() while pre... | </IndirectionThree>
</>
)
}
function getRandomNumber() {
return Math.random()
}
function RandomReadingComponent() {
if (typeof window === 'undefined') {
use(new Promise((r) => process.nextTick(r)))
}
const random = getRandomNumber() | nOne>
<RandomReadingComponent />
</IndirectionOne>
</Suspense>
<IndirectionTwo>
<LongRunningComponent />
</IndirectionTwo>
<IndirectionThree>
<ShortRunningComponent />
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-random-without-fallback/page.tsx",
"language": "tsx",
"file_size": 1800,
"cut_index": 537,
"middle_length": 229
} |
{ draftMode } from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
export default async function Page() {
return (
<>
<p>
This page accesses draftMode.isEnabled synchronously. This does not
trigger dynamic, and the build should succeed. In dev mode,... | rn (
<div>
this component read the draftMode isEnabled status synchronously:{' '}
<span id="draft-mode">{String(isEnabled)}</span>
</div>
)
}
// This component ensures that we're creating a partially prerendered page, so
// that we a | tModeReadingComponent() {
await new Promise((r) => process.nextTick(r))
// Cast to any as we removed UnsafeUnwrapped types, but still need to test with the sync access
const isEnabled = (draftMode() as any).isEnabled
retu | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-draft-mode/page.tsx",
"language": "tsx",
"file_size": 1136,
"cut_index": 518,
"middle_length": 229
} |
tion generateMetadata() {
await new Promise((r) => setTimeout(r, 0))
return { title: 'Dynamic Metadata' }
}
export default async function Page() {
return (
<>
<p>
This page is static except for `generateMetadata`. The root layout wraps
the document body in a Suspense boundary. Wrapping ... | ove
body, we still expect the dynamic-metadata error to be shown to nudge
users back toward making `generateMetadata` static (or, secondarily,
making the page partially dynamic).
</p>
<span id="sentinel">sentinel</span>
| dynamic `generateMetadata`. So even with Suspense ab | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/dynamic-metadata-static-with-suspense-above-body/page.tsx",
"language": "tsx",
"file_size": 851,
"cut_index": 529,
"middle_length": 52
} |
'next/cache'
async function innerCache() {
'use cache'
cacheLife({ expire: 60 }) // 1 minute, under the 5 minute threshold
return Math.random()
}
async function outerCache() {
'use cache'
// Explicitly not setting a `cacheLife` here means this will use the implicit
// default cache life, i.e. the shortes... | cacheLife throws an error during
prerendering.
</p>
<p>
The inner cache function is cached with a 60 second expire time. Such a
short-lived cache would normally create a dynamic hole and be excluded
from prerend | sult: number | undefined
try {
result = await outerCache()
} catch {}
return (
<>
<p>
This page tests that a nested "use cache" with low expire time inside
another "use cache" without explicit | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/use-cache-low-expire/nested/page.tsx",
"language": "tsx",
"file_size": 1984,
"cut_index": 537,
"middle_length": 229
} |
se((r) => setTimeout(r, 0))
return { themeColor: 'black' }
}
export default async function Page() {
return (
<>
<p>
This page is dynamic and also has dynamic `generateViewport`. This is a
build error because anything dynamic must be wrapped in a Suspense
boundary. While you aren't... | /p>
<Suspense fallback={<Fallback />}>
<Dynamic />
</Suspense>
</>
)
}
function Fallback() {
return <div data-fallback="">loading...</div>
}
async function Dynamic() {
await new Promise((r) => setTimeout(r))
return <p id=" | llowing dynamic
in generateViewport.
< | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/dynamic-viewport-dynamic-route/page.tsx",
"language": "tsx",
"file_size": 937,
"cut_index": 606,
"middle_length": 52
} |
connection } from 'next/server'
import { Suspense } from 'react'
export default async function Page() {
return (
<>
<p>
This page accesses headers synchronously at runtime. This triggers a
type error. In dev mode, we also log an explicit error that `headers()`
should be awaited.
... | ast to any as we removed UnsafeUnwrapped types, but still need to test with the sync access
const userAgent = (headers() as any).get('user-agent')
return (
<div>
this component reads the `user-agent` header synchronously: {userAgent}
</di | aders access at runtime.
await connection()
// C | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-headers-runtime/page.tsx",
"language": "tsx",
"file_size": 876,
"cut_index": 559,
"middle_length": 52
} |
e SearchParams = { foo: string | string[] | undefined }
export default function Page(props: { searchParams: Promise<SearchParams> }) {
return (
<>
<p>
This page accesses searchParams synchronously. This does not trigger
dynamic, and the build should succeed. In dev mode, we do log an error
... | ast to any as we removed UnsafeUnwrapped types, but still need to test with the sync access
const fooParam = (searchParams as any).foo
return (
<div>
this component reads the `foo` search param:{' '}
<span id="foo-param">{String(fooPara | {
searchParams: Promise<SearchParams>
}) {
// C | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-client-search/page.tsx",
"language": "tsx",
"file_size": 865,
"cut_index": 529,
"middle_length": 52
} |
'next/cache'
async function innerCache() {
'use cache'
cacheLife({ revalidate: 0 })
return Math.random()
}
async function outerCache() {
'use cache'
// Explicitly not setting a `cacheLife` here means this will use the implicit
// default cache life, i.e. the shortest cache life of any nested 'use cache'
... | prerendering.
</p>
<p>
The inner cache function is cached with a zero revalidate time. Such a
short-lived cache would normally create a dynamic hole and be excluded
from prerenders. However, when nested inside another | sult = await outerCache()
} catch {}
return (
<>
<p>
This page tests that a nested "use cache" with zero revalidate inside
another "use cache" without explicit cacheLife throws an error during
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/use-cache-revalidate-0/nested/page.tsx",
"language": "tsx",
"file_size": 1944,
"cut_index": 537,
"middle_length": 229
} |
import { cookies } from 'next/headers'
import { SyncIO } from './client'
export default async function Page() {
return (
<main>
<section>
<p>
In this test we have two components. One reads `new Date()`
synchronously in a client component render. The other awaits cookies
... | <section>
<RequestData />
</section>
</main>
)
}
async function RequestData() {
;(await cookies()).get('foo')
return (
<div>
<h2>Request Data Access</h2>
<p>This component accesses request data without a Suspense bo | more "valid" than
another but with the current implementation we report the `new Date()`
reason when failing the build.
</p>
</section>
<section>
<SyncIO />
</section>
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-attribution/unguarded-async-unguarded-clientsync/page.tsx",
"language": "tsx",
"file_size": 1026,
"cut_index": 512,
"middle_length": 229
} |
mport { cookies } from 'next/headers'
import { Suspense } from 'react'
import { SyncIO } from './client'
export default async function Page() {
return (
<main>
<section>
<p>
In this test we have two components. One reads `new Date()`
synchronously in a client component render. ... | >
<RequestData />
</Suspense>
</section>
</main>
)
}
async function RequestData() {
;(await cookies()).get('foo')
return (
<div>
<h2>Request Data Access</h2>
<p>This component accesses request data without | s to be a build failure with the reason
pointing to the line where `new Date()` was called.
</p>
</section>
<section>
<SyncIO />
</section>
<section>
<Suspense fallback="" | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-attribution/guarded-async-unguarded-clientsync/page.tsx",
"language": "tsx",
"file_size": 1041,
"cut_index": 513,
"middle_length": 229
} |
mport { cookies } from 'next/headers'
import { Suspense } from 'react'
import { SyncIO } from './client'
export default async function Page() {
return (
<main>
<section>
<p>
In this test we have two components. One reads `new Date()`
synchronously in a client component render. ... | <RequestData />
</Suspense>
</section>
</main>
)
}
async function RequestData() {
;(await cookies()).get('foo')
return (
<div>
<h2>Request Data Access</h2>
<p>This component accesses request data without a | erender with fallbacks around both components
</p>
</section>
<section>
<Suspense fallback="">
<SyncIO />
</Suspense>
</section>
<section>
<Suspense fallback="">
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-attribution/guarded-async-guarded-clientsync/page.tsx",
"language": "tsx",
"file_size": 1038,
"cut_index": 513,
"middle_length": 229
} |
ort { cookies } from 'next/headers'
import { SyncIO } from './client'
import { Suspense } from 'react'
export default async function Page() {
return (
<main>
<section>
<p>
In this test we have two components. One reads `new Date()`
synchronously in a client component render. Th... | </Suspense>
</section>
<section>
<RequestData />
</section>
</main>
)
}
async function RequestData() {
;(await cookies()).get('foo')
return (
<div>
<h2>Request Data Access</h2>
<p>This component | uild to error with the reason referencing
some dynamic data access. It should not mention `new Date()`.
</p>
</section>
<section>
<Suspense fallback={<p>Loading...</p>}>
<SyncIO />
| {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-attribution/unguarded-async-guarded-clientsync/page.tsx",
"language": "tsx",
"file_size": 1072,
"cut_index": 515,
"middle_length": 229
} |
'react'
import { IndirectionOne, IndirectionTwo, IndirectionThree } from './indirection'
export default async function Page() {
return (
<>
<p>
This page calls fetch three times. One is cached and outside of a
Suspense boundary. The other two are uncached but inside Suspense
bounda... | >
<IndirectionThree>
<Suspense fallback={<Fallback />}>
<FetchingComponent nonce="c" />
</Suspense>
</IndirectionThree>
</>
)
}
async function FetchingComponent({
nonce,
cached,
}: {
nonce: string
cached |
<FetchingComponent nonce="a" cached={true} />
</IndirectionOne>
<IndirectionTwo>
<Suspense fallback={<Fallback />}>
<FetchingComponent nonce="b" />
</Suspense>
</IndirectionTwo | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/dynamic-boundary/page.tsx",
"language": "tsx",
"file_size": 1666,
"cut_index": 537,
"middle_length": 229
} |
from 'react'
import { IndirectionOne, IndirectionTwo, IndirectionThree } from './indirection'
type SearchParams = { foo: string | string[] | undefined }
export default async function Page(props: {
searchParams: Promise<SearchParams>
}) {
return (
<>
<p>
This page accesses Math.random() while pre... | unningComponent />
</IndirectionTwo>
</Suspense>
<IndirectionThree>
<ShortRunningComponent />
</IndirectionThree>
</>
)
}
function RandomReadingComponent() {
if (typeof window === 'undefined') {
use(new Promis | <Suspense fallback={<Fallback />}>
<IndirectionOne>
<RandomReadingComponent />
</IndirectionOne>
</Suspense>
<Suspense fallback={<Fallback />}>
<IndirectionTwo>
<LongR | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-random-with-fallback/page.tsx",
"language": "tsx",
"file_size": 1864,
"cut_index": 537,
"middle_length": 229
} |
rver'
import { Suspense } from 'react'
export default async function Page() {
return (
<>
<p>
This page uses `connection()` inside `'use cache: private'`, which
triggers an error at runtime.
</p>
<Suspense fallback={<p>Loading...</p>}>
<Private />
</Suspense>
<... | ise((resolve) => setTimeout(resolve))
// Calling connection() in a cache context is not allowed. We're try/catching
// here to ensure that, in dev mode, this error is shown even when it's caught
// in userland.
try {
await connection()
} cat | g it as as a console error instead.
await new Prom | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/use-cache-private-connection/page.tsx",
"language": "tsx",
"file_size": 901,
"cut_index": 547,
"middle_length": 52
} |
{ connection } from 'next/server'
import { Suspense } from 'react'
type SearchParams = { foo: string | string[] | undefined }
export default async function Page(props: {
searchParams: Promise<SearchParams>
}) {
return (
<>
<p>
This page accesses searchParams synchronously. This does not trigger
... | pped types, but still need to test with the sync access
const fooParam = (searchParams as any).foo
return (
<div>
this component reads the `foo` search param:{' '}
<span id="foo-param">{String(fooParam)}</span>
</div>
)
}
// This | ms} />
<Suspense>
<Dynamic />
</Suspense>
</>
)
}
async function SearchParamsReadingComponent({
searchParams,
}: {
searchParams: Promise<SearchParams>
}) {
// Cast to any as we removed UnsafeUnwra | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-server-search/page.tsx",
"language": "tsx",
"file_size": 1228,
"cut_index": 518,
"middle_length": 229
} |
xtTestSetup } from 'e2e-utils'
describe('app-dir - fetch warnings', () => {
const { next, skipped, isNextDev } = nextTestSetup({
skipDeployment: true,
files: __dirname,
})
if (skipped) {
return
}
beforeAll(async () => {
// we don't need verbose logging (enabled by default in this Next app) ... | xpect(next.cliOutput).toInclude(`
│ GET https://next-data-api-endpoint.vercel.app/api/random?request-string
│ │ ⚠ Specified "cache: force-cache" and "revalidate: 0", only one should be specified.`)
})
})
it('should log when request i |
await next.fetch('/cache-revalidate')
})
if (isNextDev) {
describe('force-cache and revalidate: 0', () => {
it('should log when request input is a string', async () => {
await retry(() => {
e | {
"filepath": "test/e2e/app-dir/logging/fetch-warning.test.ts",
"language": "typescript",
"file_size": 2736,
"cut_index": 563,
"middle_length": 229
} |
t fetchCache = 'default-cache'
async function AnotherRsc() {
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?another-no-cache',
{
cache: 'no-cache',
}
).then((res) => res.text())
return <p id="another-no-cache">"another-no-cache" {data}</p>
}
async function Fir... | ata-api-endpoint.vercel.app/api/random?revalidate-0',
{
next: {
revalidate: 0,
},
}
).then((res) => res.text())
const dataRevalidateCache = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?revalidate-3 | taForceCache = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?force-cache',
{
cache: 'force-cache',
}
).then((res) => res.text())
const dataRevalidate0 = await fetch(
'https://next-d | {
"filepath": "test/e2e/app-dir/logging/app/default-cache/page.js",
"language": "javascript",
"file_size": 2469,
"cut_index": 563,
"middle_length": 229
} |
const fetchCache = 'default-cache'
export default async function Page() {
await fetch(
new Request(
'https://next-data-api-endpoint.vercel.app/api/random?request-input'
),
{
next: {
revalidate: 0,
},
}
)
await fetch(
new Request(
'https://next-data-api-endpoi... | t.vercel.app/api/random?no-store-request-input-cache-override',
{
cache: 'no-store',
}
),
{
next: {
revalidate: 3,
},
}
)
await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?no-sto | https://next-data-api-endpoint.vercel.app/api/random?request-string',
{
next: {
revalidate: 0,
},
cache: 'force-cache',
}
)
await fetch(
new Request(
'https://next-data-api-endpoin | {
"filepath": "test/e2e/app-dir/logging/app/cache-revalidate/page.js",
"language": "javascript",
"file_size": 1146,
"cut_index": 518,
"middle_length": 229
} |
ort { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app-dir - server-actions-redirect-middleware-rewrite.test', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should redirect correctly in nodejs runtime with middleware rewrite', async () => {
const... | ser = await next.browser('/server-action/edge')
await browser.waitForElementByCss('button').click()
await retry(async () => {
expect(await browser.waitForElementByCss('#redirected').text()).toBe(
'Redirected'
)
expect(aw | irected').text()).toBe(
'Redirected'
)
})
expect(await browser.url()).toBe(`${next.url}/redirect`)
})
it('should redirect correctly in edge runtime with middleware rewrite', async () => {
const brow | {
"filepath": "test/e2e/app-dir/server-actions-redirect-middleware-rewrite/server-actions-redirect-middleware-rewrite.test.ts",
"language": "typescript",
"file_size": 1063,
"cut_index": 515,
"middle_length": 229
} |
on ShallowLayout({ children }) {
return (
<>
<h1>Shallow Routing</h1>
<div>
<div>
<a href="#content" id="hash-navigation">
Hash Navigation (non-Link)
</a>
</div>
<div>
<Link href="/a" id="to-a">
To A
</Link>
... | ynamic 1
</Link>
</div>
<div>
<Link href="/dynamic/2" id="to-dynamic-2">
To Dynamic 2
</Link>
</div>
<div>
<Link href="/pushstate-data" id="to-pushstate-data">
| </Link>
</div>
<div>
<a href="/b" id="to-b-mpa">
To B MPA Navigation
</a>
</div>
<div>
<Link href="/dynamic/1" id="to-dynamic-1">
To D | {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/layout.tsx",
"language": "tsx",
"file_size": 2444,
"cut_index": 563,
"middle_length": 229
} |
ent'
import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
<h1 id="pushstate-searchparams">PushState SearchParams</h1>
<pre id="my-data">{searchParams.get('query')}</pre>
<button
on... | )
window.history.pushState({}, '', url)
}}
id="push-searchparams"
>
Push searchParam
</button>
</>
)
}
export default function Page() {
return (
<Suspense>
<InnerPage />
</Suspen | previousQuery ? previousQuery + '-added' : 'foo'
| {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/pushstate-new-searchparams/page.tsx",
"language": "tsx",
"file_size": 838,
"cut_index": 520,
"middle_length": 52
} |
use client'
import { useEffect, useState } from 'react'
export default function Page() {
const [data, setData] = useState(null)
const [updated, setUpdated] = useState(false)
useEffect(() => {
setData(window.history.state.myData)
}, [])
return (
<>
<h1 id="pushstate-data">PushState Data</h1>
... | et latest data
</button>
<button
onClick={() => {
window.history.pushState({ myData: { foo: 'bar' } }, '')
setUpdated(true)
}}
id="push-state"
>
Push state
</button>
</>
)
}
| }}
id="get-latest"
>
G | {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/pushstate-data/page.tsx",
"language": "tsx",
"file_size": 821,
"cut_index": 513,
"middle_length": 52
} |
spense } from 'react'
import { useSearchParams } from 'next/navigation'
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
<h1 id="pushstate-string-url">PushState String Url</h1>
<pre id="my-data">{searchParams.get('query')}</pre>
<button
onClick={() => {
... | st previousQuery = new URL(window.location.href).searchParams.get(
'query'
)
const url = `?query=${
previousQuery ? previousQuery + '-added' : 'foo'
}`
window.history.pushState(null, '', url) | : 'foo'
}`
window.history.pushState({}, '', url)
}}
id="push-string-url"
>
Push searchParam using string url
</button>
<button
onClick={() => {
con | {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/pushstate-string-url/page.tsx",
"language": "tsx",
"file_size": 1697,
"cut_index": 537,
"middle_length": 229
} |
ageSize from 'image-size'
import path from 'path'
describe('app dir - Metadata API on the Edge runtime', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
})
describe('OG image route', () => {
if (isNextStart) {
it('should not bundle `ImageResponse` into the page worker', asy... | ', file))
.includes('loadAdditionalAsset')
}
)
expect(pageFilesThatHaveImageResponse).not.toBeEmpty()
const uniqueAnotherFiles = [
...new Set<string>(
middlewareManifest.functions['/ano | et<string>(middlewareManifest.functions['/page'].files),
]
const pageFilesThatHaveImageResponse = uniquePageFiles.filter(
(file) => {
return next
.readFileSync(path.join('.next | {
"filepath": "test/e2e/app-dir/metadata-edge/index.test.ts",
"language": "typescript",
"file_size": 2344,
"cut_index": 563,
"middle_length": 229
} |
from 'react'
// Validation level is 'experimental-manual-error' (set in next.config.ts).
// No implicit validation — only segments that explicitly opt in via
// `unstable_instant` are validated. When validated, the level is error,
// applying in dev AND build (build fails on violations).
//
// Children are wrapped in... | an
// instant-specific violation when it runs.
export const unstable_instant = false
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<Suspense fallback={<p>loading…</p>}>{children}</Su | flags "Suspense too high for instant navigation" as | {
"filepath": "test/e2e/app-dir/instant-validation-level-manual-error/app/layout.tsx",
"language": "tsx",
"file_size": 899,
"cut_index": 547,
"middle_length": 52
} |
('next/dynamic with CSP nonce', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should include nonce attribute on preload links generated by next/dynamic', async () => {
const $ = await next.render$('/')
// Check that preload links have the nonce attribute
const preloadLinks = ... | > {
const $element = $(element)
const href = $element.attr('href')
// Only check preload links for dynamic chunks
if (href && /_next\/static\/(immutable\/)?chunks\//.test(href)) {
expect($element.attr('nonce')).toBe('test-n | /_next\/static\/(immutable\/)?chunks\//.test(href)
})
// There should be at least one preload link for dynamic chunks
expect(dynamicPreloadLinks.length).toBeGreaterThan(0)
dynamicPreloadLinks.each((_, element) = | {
"filepath": "test/e2e/app-dir/next-dynamic-csp-nonce/next-dynamic-csp-nonce.test.ts",
"language": "typescript",
"file_size": 2089,
"cut_index": 563,
"middle_length": 229
} |
xSource,
openRedbox,
} from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('use-cache-close-over-function', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (skipp... | shot(`
"Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
[function fn]
^^^^^^^^^^^"
| xt.browser('/client')
await openRedbox(browser)
const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser)
expect(errorDescription).toMatchInlineSnap | {
"filepath": "test/e2e/app-dir/use-cache-close-over-function/use-cache-close-over-function.test.ts",
"language": "typescript",
"file_size": 4867,
"cut_index": 614,
"middle_length": 229
} |
error happens during rendering', async () => {
const browser = await next.browser('/client')
await browser
.waitForElementByCss('#error-trigger-button')
.elementByCss('#error-trigger-button')
.click()
if (isNextDev) {
await expect(browser).toDisplayRedbox(`
{
"descr... | nt error'
)
})
it('should render global error for error in server components', async () => {
const browser = await next.browser('/rsc')
expect(await browser.elementByCss('h1').text()).toBe('Global Error')
if (isNextDev) {
await | ror')
| ^",
"stack": [
"Page app/client/page.js (8:11)",
],
}
`)
}
expect(await browser.elementByCss('#error').text()).toBe(
'Global error: Error: Clie | {
"filepath": "test/e2e/app-dir/global-error/basic/index.test.ts",
"language": "typescript",
"file_size": 7403,
"cut_index": 716,
"middle_length": 229
} |
tForRedbox, getRedboxHeader } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'
async function testDev(browser, errorRegex) {
await waitForRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch(errorRegex)
}
describe('app dir - global error - with style import', () => {
const { next, isNe... | er = await next.browser('/')
if (isNextDev) {
await testDev(browser, /Root Layout Error/)
return
}
const h2 = await browser.elementByCss('h2')
expect(await h2.getComputedCss('color')).toBe('rgb(255, 255, 0)') // yellow
})
}) | const brows | {
"filepath": "test/e2e/app-dir/global-error/with-style-import/index.test.ts",
"language": "typescript",
"file_size": 795,
"cut_index": 524,
"middle_length": 14
} |
waitForRedbox } from 'next-test-utils'
describe('app dir - global-error - error-in-global-error', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('should be able to use nextjs navigation hook in global-error', async () => {
const browser = await next.browser('/')
const te... | | ^",
"stack": [
"Page.useEffect app/page.js (7:11)",
],
}
`)
}
})
it('should render fallback UI when error occurs in global-error', async () => {
const browser = await next.browse |
{
"description": "error in page",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/page.js (7:11) @ Page.useEffect
> 7 | throw new Error('error in page')
| {
"filepath": "test/e2e/app-dir/global-error/error-in-global-error/error-in-global-error.test.ts",
"language": "typescript",
"file_size": 2298,
"cut_index": 563,
"middle_length": 229
} |
urn str.split(substr).length - 1
}
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-metadata-streaming', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
// No dynamic APIs used in metadata
describe('static metadata', () => {
it('should generate m... | await browser
.waitForElementByCss(`${rootSelector} title`, { state: 'attached' })
.text()
).toBe('fully static')
await assertNoConsoleErrors(browser)
})
it('should insert metadata in body when page is dynamic page | tor} title`).text()).toBe('fully static')
expect(countSubstring($.html(), '<title>')).toBe(1)
const browser = await next.browser('/fully-static', {
pushErrorAsConsoleLog: true,
})
expect(
| {
"filepath": "test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts",
"language": "typescript",
"file_size": 7262,
"cut_index": 716,
"middle_length": 229
} |
(cliOutput)
.split('\n')
.filter((log) => cacheReasonRegex.test(log) || log.includes('GET'))
return logs.reduce<ParsedLog[]>((parsedLogs, log) => {
if (cacheReasonRegex.test(log)) {
// cache miss/skip reason
// Example of `log`: "│ │ Cache skipped reason: (cache: no-cache)"
const reason... | ),
responseTime: parseInt(responseTime, 10),
cache: undefined,
})
}
return parsedLogs
}, [])
}
describe('app-dir - fetch logging', () => {
const { next, isNextDev } = nextTestSetup({
skipDeployment: true,
files: _ | const trimmedLog = log.replace(/^[^a-zA-Z]+/, '')
const [method, url, statusCode, responseTime] = trimmedLog.split(' ', 5)
parsedLogs.push({
method,
url,
statusCode: parseInt(statusCode, 10 | {
"filepath": "test/e2e/app-dir/logging/fetch-logging.test.ts",
"language": "typescript",
"file_size": 14977,
"cut_index": 921,
"middle_length": 229
} |
escribe(`mdx ${type}`, () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
'@next/mdx': 'canary',
'@mdx-js/loader': '^2.2.1',
'@mdx-js/react': '^2.2.1',
'recma-export-filepath': '1.2.0',
'rehype-katex': '7.0.1',
'rehype-slug': '6.0.0... | t('should work using browser', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('h1').text()).toBe('Hello World')
expect(await browser.elementByCss('p').text()).toBe('This is MDX!')
})
| ory', () => {
it('should work in initial html', async () => {
const $ = await next.render$('/')
expect($('h1').text()).toBe('Hello World')
expect($('p').text()).toBe('This is MDX!')
})
i | {
"filepath": "test/e2e/app-dir/mdx/mdx.test.ts",
"language": "typescript",
"file_size": 4833,
"cut_index": 614,
"middle_length": 229
} |
ck()
.waitForElementByCss('#pushstate-data')
.text()
).toBe('PushState Data')
await browser
.elementByCss('#push-state')
.click()
.waitForElementByCss('#state-updated', { state: 'attached' })
.elementByCss('#get-latest')
.click()
await check(... | ).toBe('PushState Pathname')
await browser.elementByCss('#push-pathname').click()
// Check usePathname value is the new pathname
await check(
() => browser.elementByCss('#my-data').text(),
'/my-non-existent-path'
| const browser = await next.browser('/a')
expect(
await browser
.elementByCss('#to-pushstate-new-pathname')
.click()
.waitForElementByCss('#pushstate-pathname')
.text()
| {
"filepath": "test/e2e/app-dir/shallow-routing/shallow-routing.test.ts",
"language": "typescript",
"file_size": 16041,
"cut_index": 921,
"middle_length": 229
} |
spense } from 'react'
import { useSearchParams } from 'next/navigation'
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
<h1 id="replacestate-string-url">ReplaceState String Url</h1>
<pre id="my-data">{searchParams.get('query')}</pre>
<button
onClick={() => {
... | {
const previousQuery = new URL(window.location.href).searchParams.get(
'query'
)
const url = `?query=${
previousQuery ? previousQuery + '-added' : 'foo'
}`
window.history.replaceSt | dded' : 'foo'
}`
window.history.replaceState({}, '', url)
}}
id="replace-string-url"
>
Replace searchParam using string url
</button>
<button
onClick={() => | {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/replacestate-string-url/page.tsx",
"language": "tsx",
"file_size": 1727,
"cut_index": 537,
"middle_length": 229
} |
ent'
import { useEffect, useState } from 'react'
export default function Page() {
const [data, setData] = useState(null)
const [updated, setUpdated] = useState(false)
useEffect(() => {
setData(window.history.state.myData)
}, [])
return (
<>
<h1 id="replacestate-data">ReplaceState Data</h1>
... | t latest data
</button>
<button
onClick={() => {
window.history.replaceState({ myData: { foo: 'bar' } }, '')
setUpdated(true)
}}
id="replace-state"
>
Replace state
</button>
</ | }}
id="get-latest"
>
Ge | {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/replacestate-data/page.tsx",
"language": "tsx",
"file_size": 836,
"cut_index": 520,
"middle_length": 52
} |
retry } from 'next-test-utils'
describe('interception-segments-two-levels-above', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should work when interception route is paired with segments two levels above', async () => {
const browser = await next.browser('/foo/bar')
await brows... | ion
await browser.elementByCss('[href="/hoge"]').click()
await retry(async () => {
expect(await browser.elementById('intercepted').text()).toMatch(
/intercepted/
)
})
// Go back
await browser.back()
await retry( | should intercept consistently with back/forward navigation', async () => {
// Test that interception works correctly with browser back/forward
const browser = await next.browser('/foo/bar')
// Navigate with intercept | {
"filepath": "test/e2e/app-dir/interception-segments-two-levels-above/interception-segments-two-levels-above.test.ts",
"language": "typescript",
"file_size": 2054,
"cut_index": 563,
"middle_length": 229
} |
{ nextTestSetup } from 'e2e-utils'
describe('app dir - global error - layout error', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should render global error for error in server components', async () => {
... | ],
}
`)
}
expect(await browser.elementByCss('h1').text()).toBe('Global Error')
expect(await browser.elementByCss('#error').text()).toBe(
isNextDev
? 'Global error: layout error'
: 'Global error: Minified Re | er",
"label": "Runtime Error",
"source": "app/layout.js (2:9) @ layout
> 2 | throw new Error('layout error')
| ^",
"stack": [
"layout app/layout.js (2:9)",
| {
"filepath": "test/e2e/app-dir/global-error/layout-error/index.test.ts",
"language": "typescript",
"file_size": 1251,
"cut_index": 518,
"middle_length": 229
} |
waitForRedbox,
getRedboxDescription,
getRedboxSource,
} from 'next-test-utils'
describe('cache-components-route-handler-errors', () => {
const { next, skipped, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
... | escription: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}
if (isTurbopack) {
expect(redbox.description).toMatchInlineSnapshot(
`"Route segment config "dynamic" is not compatible with \ | d to fail
}
if (isNextDev) {
// Test the first route handler with "dynamic" config
const browser = await next.browser('/route-with-dynamic')
await waitForRedbox(browser)
const redbox = {
d | {
"filepath": "test/e2e/app-dir/cache-components-route-handler-errors/cache-components-route-handler-errors.test.ts",
"language": "typescript",
"file_size": 2211,
"cut_index": 563,
"middle_length": 229
} |
ge is suspended and being caught by the layout Suspense boundary
export default function Page() {
return (
<div className="container">
<SuspendedComponent />
</div>
)
}
async function SuspendedComponent() {
await connection()
await new Promise((resolve) => setTimeout(resolve, 500))
return (
... | spended component</div>
}
export async function generateMetadata() {
await connection()
await new Promise((resolve) => setTimeout(resolve, 3 * 1000))
return {
title: 'dynamic-metadata - partial',
description: `dynamic metadata - ${Math.rando | => setTimeout(resolve, 500))
return <div>nested su | {
"filepath": "test/e2e/app-dir/ppr-metadata-streaming/app/dynamic-metadata/partial/page.tsx",
"language": "tsx",
"file_size": 880,
"cut_index": 559,
"middle_length": 52
} |
('searchparams-static-bailout', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
dependencies: {
nanoid: '4.0.1',
},
})
describe('server component', () => {
it('should bailout when using searchParams', async () => {
const url = '/server-component-page?search=hel... | {
const url = '/server-component-without-searchparams?search=hello'
const $ = await next.render$(url)
expect($('h1').text()).toBe('No searchParams used')
// Check if the page is not statically generated.
if (isNextStart) {
| t id = $('#nanoid').text()
const $2 = await next.render$(url)
const id2 = $2('#nanoid').text()
expect(id).not.toBe(id2)
}
})
it('should not bailout when not using searchParams', async () => | {
"filepath": "test/e2e/app-dir/searchparams-static-bailout/searchparams-static-bailout.test.ts",
"language": "typescript",
"file_size": 2716,
"cut_index": 563,
"middle_length": 229
} |
ort { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'
function InnerPage() {
const searchParams = useSearchParams()
return (
<>
<h1 id="replacestate-searchparams">ReplaceState SearchParams</h1>
<pre id="my-data">{searchParams.get('query')}</pre>
<button
onCli... | )
window.history.replaceState({}, '', url)
}}
id="replace-searchparams"
>
Replace searchParam
</button>
</>
)
}
export default function Page() {
return (
<Suspense>
<InnerPage />
</ | reviousQuery ? previousQuery + '-added' : 'foo'
| {
"filepath": "test/e2e/app-dir/shallow-routing/app/(shallow)/replacestate-new-searchparams/page.tsx",
"language": "tsx",
"file_size": 853,
"cut_index": 529,
"middle_length": 52
} |
from 'e2e-utils'
import { waitForRedbox, getRedboxHeader } from 'next-test-utils'
const errorMessage =
'images.loaderFile detected but the file is missing default export.\nRead more: https://nextjs.org/docs/messages/invalid-images-config'
async function testDev(browser, errorRegex) {
await waitForRedbox(browser)
... | nc () => {
const browser = await next.browser('/')
await testDev(browser, errorMessage)
})
it('should show the error when using `getImageProps` method', async () => {
const browser = await next.browser('/get-img-props') | isNextDev } = nextTestSetup({
skipDeployment: true,
files: __dirname,
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should show the error when using `Image` component', asy | {
"filepath": "test/e2e/app-dir/loader-file-named-export-custom-loader-error/loader-file-named-export-custom-loader-error.test.ts",
"language": "typescript",
"file_size": 1586,
"cut_index": 537,
"middle_length": 229
} |
link'
export const fetchCache = 'default-cache'
export default function Layout({ children }) {
return (
<html>
<body>
<header>
<Link id="nav-link" href={'/link'}>
/link
</Link>
<br />
<Link id="nav-headers" href={'/headers'}>
/headers... | /cache-revalidate
</Link>
<br />
<Link id="nav-many-requests" href={'/many-requests'}>
/many-requests
</Link>
<br />
</header>
<div>{children}</div>
</body>
</html>
) | revalidate" href={'/cache-revalidate'}>
| {
"filepath": "test/e2e/app-dir/logging/app/layout.js",
"language": "javascript",
"file_size": 846,
"cut_index": 535,
"middle_length": 52
} |
kipDeployment: true,
env: {
NEXT_TEST_LOG_VALIDATION: '1',
},
})
if (skipped) return
if (isNextStart && !isTurbopack) {
it.skip('TODO: snapshot tests for webpack', () => {})
return
}
if (isNextStart) {
beforeAll(async () => {
await next.build({ args: ['--experimental-build-mo... | is 'experimental-manual-error'. Implicit validation
// does NOT fire on bare pages — only segments that explicitly opt in via
// `unstable_instant` are validated. When they are validated, the level is
// error (applies in dev AND build), unless de-es | name: string) => {
return await next.build({
args: [
'--experimental-build-mode',
'generate',
'--debug-build-paths',
`app${pathname}/page.tsx`,
],
})
}
// Validation level | {
"filepath": "test/e2e/app-dir/instant-validation-level-manual-error/instant-validation-level-manual-error.test.ts",
"language": "typescript",
"file_size": 10385,
"cut_index": 921,
"middle_length": 229
} |
{ nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app-dir - draft-mode-middleware', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should be able to enable draft mode with middleware pr... | t).toBe('draft')
})
it('should be able to disable draft mode with middleware present', async () => {
const browser = await next.browser('/api/disable-draft')
await retry(async () => {
expect(next.cliOutput).toContain(
'draftMode( | in(
'draftMode().isEnabled from middleware: true'
)
})
await browser.loadPage(new URL('/preview-page', next.url).toString())
const draftText = await browser.elementByCss('h1').text()
expect(draftTex | {
"filepath": "test/e2e/app-dir/draft-mode-middleware/draft-mode-middleware.test.ts",
"language": "typescript",
"file_size": 1234,
"cut_index": 518,
"middle_length": 229
} |
'use no memo'
import { useReducer, useState } from 'react'
import Image from 'next/image'
export default function Page() {
const [, setLoadEvent] = useState<unknown>(null)
const [showClientImage, setShowClientImage] = useState(false)
const [, rerender] = useReducer((i) => i + 1, 0)
return (
<>
<Im... | ender}>
rerender Page
</button>
<button type="button" onClick={() => setShowClientImage(true)}>
Show Client image
</button>
{showClientImage && (
<Image
alt="bar"
width={5}
heigh | 'hydrated image load')
// This doesn't really make sense. We just want to check rerendering
// doesn't infinitely loop
setLoadEvent(event)
}}
/>
<button type="button" onClick={rer | {
"filepath": "test/e2e/app-dir/next-image-events/app/fulfilled/page.tsx",
"language": "tsx",
"file_size": 1385,
"cut_index": 524,
"middle_length": 229
} |
'use no memo'
import { useReducer, useState } from 'react'
import Image from 'next/image'
export default function Page() {
const [, setErrorEvent] = useState<unknown>(null)
const [showClientImage, setShowClientImage] = useState(false)
const [, rerender] = useReducer((i) => i + 1, 0)
return (
<>
<I... | nder Page
</button>
<button type="button" onClick={() => setShowClientImage(true)}>
Show Client image
</button>
{showClientImage && (
<Image
alt="bar"
width={5}
height={5}
unop | )
// This doesn't really make sense. We just want to check rerendering
// doesn't infinitely loop
setErrorEvent(event)
}}
/>
<button type="button" onClick={rerender}>
rere | {
"filepath": "test/e2e/app-dir/next-image-events/app/rejected/page.tsx",
"language": "tsx",
"file_size": 1346,
"cut_index": 524,
"middle_length": 229
} |
from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('no-double-tailwind-execution', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: {
'@tailwindcss/postcss': '^4',
tailwindcss: '^4',
},
env: {
DEBUG... | s.css/g
),
].length
}
expect(getTailwindProcessingCount()).toBe(1) // initial
if (isNextDev) {
await next.patchFile(
'app/page.tsx',
(content) => content.replace('hello world', 'hello hmr'),
async ( | .browser('/')
expect(await browser.elementByCss('p').text()).toBe('hello world')
function getTailwindProcessingCount() {
return [
...next.cliOutput.matchAll(
/\[@tailwindcss\/postcss\] app\/global | {
"filepath": "test/e2e/app-dir/no-double-tailwind-execution/no-double-tailwind-execution.test.ts",
"language": "typescript",
"file_size": 1627,
"cut_index": 537,
"middle_length": 229
} |
ts
* and tracks them for later assertion.
*/
function createNavigationInterceptor() {
const navigationRequests: Request[] = []
const beforePageLoad = (page: Page) => {
page.on('request', (request) => {
if (request.resourceType() === 'document') {
navigationRequests.push(request)... | t,
initialUrl: string,
getNavigationRequests: () => Request[]
) {
const errorMessage =
'has blocked a javascript: URL as a security precaution.'
// Wait for the security error to appear in logs, confirming the click was processed
| L is blocked.
* Waits for the security error to appear in logs (confirming the click was processed),
* then asserts no navigation requests were made.
*/
async function expectJavascriptUrlBlocked(
browser: Playwrigh | {
"filepath": "test/e2e/app-dir/javascript-urls/javascript-urls.test.ts",
"language": "typescript",
"file_size": 12229,
"cut_index": 921,
"middle_length": 229
} |
ables gesture-driven navigation
* via React's Gesture Transitions feature.
*
* The test simulates a gesture by using two buttons:
* - "Start Gesture" calls experimental_gesturePush and begins an async
* transition that doesn't complete until "End Gesture" is clicked
* - "End Gesture" resolves the pending promis... | xt.browser('/')
// Verify we're on the home page
expect(
await browser.elementByCss('[data-testid="home-page"]').text()
).toContain('Home')
// Click "Start Gesture" to begin the optimistic navigation
await browser.elementByCss(' | e-utils'
describe('gesture-transitions', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('shows optimistic state during gesture, then canonical state after', async () => {
const browser = await ne | {
"filepath": "test/e2e/app-dir/gesture-transitions/gesture-transitions.test.ts",
"language": "typescript",
"file_size": 2113,
"cut_index": 563,
"middle_length": 229
} |
from 'react'
import { useRouter, usePathname } from 'next/navigation'
import Link from 'next/link'
const pendingResolvers = new Set<() => void>()
export default function Root({ children }: { children: ReactNode }) {
const router = useRouter()
const pathname = usePathname()
const isOnHomePage = pathname === '/'... | that takes time to complete.
await new Promise<void>((resolve) => {
pendingResolvers.add(resolve)
})
// After the gesture ends, perform the canonical navigation
router.push(href)
})
}
const endGesture = () => {
| gesture push to show prefetched content immediately
;(router as any).experimental_gesturePush(href)
// Create a promise that won't resolve until the "end gesture" button
// is clicked. This simulates a gesture | {
"filepath": "test/e2e/app-dir/gesture-transitions/app/layout.tsx",
"language": "tsx",
"file_size": 2158,
"cut_index": 563,
"middle_length": 229
} |
tTestSetup } from 'e2e-utils'
describe('app dir - not-found - conflict route', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
const runTests = () => {
it('should use the not-found page for non-matching routes', async () =... | d')
expect(html).toContain('I am still a valid page')
})
}
describe('with default runtime', () => {
runTests()
})
describe('with runtime = edge', () => {
let originalLayout = ''
beforeAll(async () => {
await next.stop | ntain root layout content
expect(await browser.elementByCss('#layout-nav').text()).toBe('Navbar')
})
it('should allow to have a valid /not-found route', async () => {
const html = await next.render('/not-foun | {
"filepath": "test/e2e/app-dir/not-found/conflict-route/index.test.ts",
"language": "typescript",
"file_size": 1342,
"cut_index": 524,
"middle_length": 229
} |
rt { nextTestSetup } from 'e2e-utils'
const isPPREnabled = process.env.__NEXT_CACHE_COMPONENTS === 'true'
describe('app dir - not-found - default', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
it('should has noindex in the head html', async () => {
... | next.readFile('.next/server/app/_not-found.html')
const rsc = isPPREnabled
? 'noindex'
: await next.readFile(`.next/server/app/_not-found.rsc`)
expect(html).toContain('noindex')
expect(rsc).toContain('noindex')
})
} | n the page', async () => {
const html = await | {
"filepath": "test/e2e/app-dir/not-found/default/default.test.ts",
"language": "typescript",
"file_size": 828,
"cut_index": 516,
"middle_length": 52
} |
iles: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it("should propagate notFound errors past a segment's error boundary", async () => {
let browser = await next.browser('/error-boundary')
await browser.elementByCss('button').click()
expect(await browser.elementByCss('h1').te... | /nested)'
)
})
it('should return 404 status code for custom not-found page', async () => {
const res = await next.fetch('/_not-found')
expect(res.status).toBe(404)
})
if (isNextStart) {
it('should include not found client referenc | ext()).toBe(
'Not Found (error-boundary/nested)'
)
browser = await next.browser('/error-boundary/nested/trigger-not-found')
expect(await browser.elementByCss('h1').text()).toBe(
'Not Found (error-boundary | {
"filepath": "test/e2e/app-dir/not-found/basic/index.test.ts",
"language": "typescript",
"file_size": 6352,
"cut_index": 716,
"middle_length": 229
} |
{ nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('not-found app dir css', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: {
sass: 'latest',
},
})
if (skipped) {
return
}
it('should load css... |
async () =>
await browser.eval(
`window.getComputedStyle(document.querySelector('#go-to-index')).backgroundColor`
),
'rgb(0, 128, 0)'
)
await browser.elementByCss('#go-to-index').click()
await browser.wait | putedStyle(document.querySelector('#go-to-404')).backgroundColor`
),
'rgb(0, 128, 0)'
)
await browser.elementByCss('#go-to-404').click()
await browser.waitForElementByCss('#go-to-index')
await check( | {
"filepath": "test/e2e/app-dir/not-found/css-precedence/index.test.ts",
"language": "typescript",
"file_size": 1234,
"cut_index": 518,
"middle_length": 229
} |
ort { nextTestSetup } from 'e2e-utils'
describe('app dir - not-found - group route', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
const runTests = () => {
it('should use the not-found page under group routes', async () ... | it next.stop()
originalLayout = await next.readFile('app/layout.js')
await next.patchFile(
'app/layout.js',
`export const runtime = 'edge'\n${originalLayout}`
)
await next.start()
})
afterAll(async () => {
| t()).toContain(
'Not found!'
)
})
}
describe('with default runtime', () => {
runTests()
})
describe('with runtime = edge', () => {
let originalLayout = ''
beforeAll(async () => {
awa | {
"filepath": "test/e2e/app-dir/not-found/group-route/index.test.ts",
"language": "typescript",
"file_size": 1089,
"cut_index": 515,
"middle_length": 229
} |
lient'
import { CacheProvider } from '@emotion/react'
import createCache from '@emotion/cache'
import { useServerInsertedHTML } from 'next/navigation'
import { useState } from 'react'
export default function RootStyleRegistry({ children }) {
const [{ cache, flush }] = useState(() => {
const cache = createCache(... | serted
}
return { cache, flush }
})
useServerInsertedHTML(() => {
const names = flush()
if (names.length === 0) return null
let styles = ''
for (const name of names) {
styles += cache.inserted[name]
}
return (
| nserted[serialized.name] === undefined) {
inserted.push(serialized.name)
}
return prevInsert(...args)
}
const flush = () => {
const prevInserted = inserted
inserted = []
return prevIn | {
"filepath": "test/e2e/app-dir/emotion-js/app/emotion-root-style-registry.js",
"language": "javascript",
"file_size": 1230,
"cut_index": 518,
"middle_length": 229
} |
outes with root not-found', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should render default 404 with root layout for non-existent page', async () => {
const browser = await next.browser('/non-existent')
expect... | r = await next.browser('/group-dynamic/123')
expect(await browser.elementByCss('p').text()).toBe('group-dynamic [id]')
await browser.loadPage(next.url + '/group-dynamic/404')
expect(await browser.elementByCss('p').text()).toBe('Not found place | p routes if hit 404', async () => {
const browse | {
"filepath": "test/e2e/app-dir/not-found/group-route-root-not-found/index.test.ts",
"language": "typescript",
"file_size": 979,
"cut_index": 582,
"middle_length": 52
} |
{ nextTestSetup } from 'e2e-utils'
describe('ppr-root-param-fallback', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should have use-cache content in fallback shells for all pregenerated locales', async () => {
// Setup: The app has a [locale] param with generateStaticParams returni... | next.render$(`/${locale}/blog/new-post`)
// The shell should have the locale-header with cached content,
// NOT the locale-loading Suspense fallback
expect($('#locale-header').length).toBe(1)
expect($('#locale-header').text()).toC | enerate fallback shells with the correct locale
// filled in for all pregenerated locales.
for (const locale of ['en', 'fr']) {
// next.render$ doesn't stream, so we get just the shell content
const $ = await | {
"filepath": "test/e2e/app-dir/ppr-root-param-fallback/ppr-root-param-fallback.test.ts",
"language": "typescript",
"file_size": 1224,
"cut_index": 518,
"middle_length": 229
} |
'react'
import { cookies } from 'next/headers'
async function getLocaleConfig(localeParam: string) {
'use cache'
await new Promise((resolve) => setTimeout(resolve, 800))
return {
locale: localeParam,
translations: {
home: `Home (${localeParam})`,
blog: `Blog (${localeParam})`,
about: `A... | >
</nav>
<Suspense
fallback={<div id="locale-loading">Loading locale info...</div>}
>
<LocaleInfo params={params} />
</Suspense>
<Suspense fallback={<div id="dynamic-loading">Loading user...</di | <html>
<body>
<div id="static-header">Welcome to our Blog Platform</div>
<nav id="static-nav">
<ul>
<li>Home</li>
<li>Blog</li>
<li>About</li>
</ul | {
"filepath": "test/e2e/app-dir/ppr-root-param-fallback/app/[locale]/layout.tsx",
"language": "tsx",
"file_size": 1875,
"cut_index": 537,
"middle_length": 229
} |
from 'next/headers'
import Link from 'next/link'
async function getBlogPost(locale: string, slug: string) {
'use cache'
await new Promise((resolve) => setTimeout(resolve, 700))
return {
title: `Blog Post: ${slug}`,
locale,
content: 'This content was fetched from the CMS...',
relatedPosts: ['Rela... | arams={params} />
</Suspense>
<Suspense fallback={<div id="dynamic-loading">Loading comments...</div>}>
<DynamicComments />
</Suspense>
</main>
)
}
// This component depends on locale and slug, so it's in Suspense
async fu | <div id="static-blog-header">Blog Article</div>
<div id="static-reading-time">Estimated reading time: 5 minutes</div>
<Suspense fallback={<div id="blog-loading">Loading article...</div>}>
<BlogContent p | {
"filepath": "test/e2e/app-dir/ppr-root-param-fallback/app/[locale]/blog/[slug]/page.tsx",
"language": "tsx",
"file_size": 2052,
"cut_index": 563,
"middle_length": 229
} |
utils'
import { retry } from 'next-test-utils'
describe('prefetch-searchparam', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should set prefetch cache properly on different search params', async () => {
// load WITH search param
const browser = await next.browser('/?q=foo')
e... | wait browser.elementByCss('p').text()).toBe('{"q":"bar"}')
})
// navigate to home, should clear the searchParams value
await browser.elementByCss('[href="/"]').click()
await retry(async () => {
expect(await browser.elementByCss('p'). | click()
await retry(async () => {
expect(a | {
"filepath": "test/e2e/app-dir/prefetch-searchparam/prefetch-searchparam.test.ts",
"language": "typescript",
"file_size": 889,
"cut_index": 547,
"middle_length": 52
} |
{ nextTestSetup } from 'e2e-utils'
describe('require-context', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
it('should get correct require context when using regex filtering', async () => {
... | e context when using no regex', async () => {
// const $ = await next.render$('/require-context-with-no-regex')
// expect($('pre').text()).toBe(
// JSON.stringify([
// './parent/file1',
// './parent/file1.js',
// './pa | t2/file3.js',
])
)
})
// TODO: This test is already scaffolded and just needs to be turned on when turbopack supports it.
// eslint-disable-next-line jest/no-commented-out-tests
// it('should get correct requir | {
"filepath": "test/e2e/app-dir/require-context/require-context.test.ts",
"language": "typescript",
"file_size": 1143,
"cut_index": 518,
"middle_length": 229
} |
'*.test-file.js': [
{
condition: { all: ['browser', 'foreign'] },
loaders: [
{
loader: require.resolve('./test-file-loader.js'),
options: { browser: true, foreign: true },
},
],
},
{
condition: { al... | ion: { not: { any: ['browser', 'foreign'] } },
loaders: [
{
loader: require.resolve('./test-file-loader.js'),
options: { default: true },
},
],
},
],
},
},
}
modul | ,
],
},
{
condit | {
"filepath": "test/e2e/app-dir/webpack-loader-conditions/next.config.js",
"language": "javascript",
"file_size": 937,
"cut_index": 606,
"middle_length": 52
} |
{ nextTestSetup } from 'e2e-utils'
// Specifically tests turbopack.rules.*.foreign config
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'webpack-loader-conditions',
() => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) ret... | () => {
const browser = await next.browser('/')
const text = await browser.elementByCss('body').text()
expect(text).toContain(`server: ${JSON.stringify({ default: true })}`)
expect(text).toContain(`client: ${JSON.stringify({ browser | .toContain(`server: {"default":true}`)
expect(html).toContain(`client: {"default":true}`)
expect(html).toContain(`foreignClient: {}`)
})
it('should render correctly on client side', async | {
"filepath": "test/e2e/app-dir/webpack-loader-conditions/webpack-loader-conditions.test.ts",
"language": "typescript",
"file_size": 1144,
"cut_index": 518,
"middle_length": 229
} |
tTestSetup } from 'e2e-utils'
describe('sitemap-group', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should not add suffix to sitemap under group routes', async () => {
const res = await next.fetch('/foo/sitemap.xml')
expect(res.status).toBe(200)
expect(res.headers.get('cont... | should not add suffix to static sitemap.xml under group routes', async () => {
const res = await next.fetch('/bar/sitemap.xml')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toBe('application/xml')
const text = await | emaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.vercel.com</loc>
<lastmod>2024-12-05T23:45:13.405Z</lastmod>
<changefreq>monthly</changefreq>
</url>
</urlset>
"
`)
})
it(' | {
"filepath": "test/e2e/app-dir/sitemap-group/sitemap-group.test.ts",
"language": "typescript",
"file_size": 1337,
"cut_index": 524,
"middle_length": 229
} |
tTestSetup } from 'e2e-utils'
const pprEnabled = process.env.__NEXT_CACHE_COMPONENTS === 'true'
describe('use-cache-private', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('excludes private caches from prerenders', async () => {
const browser = await next.browser('/')
... | wser.addCookie({ name: 'test-cookie', value: 'foo' })
await browser.refresh()
expect(await browser.elementById('test-cookie').text()).toBe('foo')
})
it('allows reading search params in private caches', async () => {
const browser = await | ).toBe('runtime')
})
it('allows reading cookies in private caches', async () => {
const browser = await next.browser('/cookies')
expect(await browser.elementById('test-cookie').text()).toBe('<empty>')
await bro | {
"filepath": "test/e2e/app-dir/use-cache-private/use-cache-private.test.ts",
"language": "typescript",
"file_size": 1278,
"cut_index": 524,
"middle_length": 229
} |
ort { nextTestSetup } from 'e2e-utils'
describe('app-dir revalidate-dynamic', () => {
const { next, isNextStart } = nextTestSetup({
files: __dirname,
})
if (isNextStart) {
it('should correctly mark a route handler that uses revalidateTag as dynamic', async () => {
expect(next.cliOutput).toContain(... | mentById('data-value').text()
expect(randomNumber).toEqual(randomNumber2)
const revalidateRes = await next.fetch(path)
expect((await revalidateRes.json()).revalidated).toBe(true)
await browser.refresh()
const randomNumber3 | a with %s`,
async (path) => {
const browser = await next.browser('/')
const randomNumber = await browser.elementById('data-value').text()
await browser.refresh()
const randomNumber2 = await browser.ele | {
"filepath": "test/e2e/app-dir/revalidate-dynamic/revalidate-dynamic.test.ts",
"language": "typescript",
"file_size": 1119,
"cut_index": 515,
"middle_length": 229
} |
oyment: true,
env: {
NEXT_TEST_LOG_VALIDATION: '1',
},
})
if (skipped) return
if (isNextStart && !isTurbopack) {
it.skip('TODO: snapshot tests for webpack', () => {})
return
}
if (isNextStart) {
beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'c... | erimental-error'. Implicit validation fires on
// bare pages in dev AND build — error level applies to both modes.
// Per-segment overrides (`level`, `true`, `false`) layer on top of this.
// A `level: 'warning'` override de-escalates a specific rout | tring) => {
return await next.build({
args: [
'--experimental-build-mode',
'generate',
'--debug-build-paths',
`app${pathname}/page.tsx`,
],
})
}
// Validation level is 'exp | {
"filepath": "test/e2e/app-dir/instant-validation-level-error/instant-validation-level-error.test.ts",
"language": "typescript",
"file_size": 13702,
"cut_index": 921,
"middle_length": 229
} |
t { Suspense, type ReactNode } from 'react'
// Validation level is 'experimental-error' (set in next.config.ts).
// Bare page/default segments get implicit validation in dev AND build.
// Build fails when violations are found.
//
// Children are wrapped in Suspense so that pages with runtime data
// accessed at the to... | olation when it runs.
export const unstable_instant = false
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<Suspense fallback={<p>loading…</p>}>{children}</Suspense>
</body>
| nt-specific vi | {
"filepath": "test/e2e/app-dir/instant-validation-level-error/app/layout.tsx",
"language": "tsx",
"file_size": 804,
"cut_index": 517,
"middle_length": 14
} |
from 'e2e-utils'
import { retry } from 'next-test-utils'
// Explicitly don't mix route handlers with pages in this test app, to make sure
// that this also works in isolation.
describe('use-cache-route-handler-only', () => {
const { next, isNextDeploy } = nextTestSetup({
files: __dirname,
})
it('should cach... | rior test activity
// can affect request timing enough for the concurrent requests to no
// longer overlap reliably.
await next.stop()
await next.start()
const [{ rand: first }, { rand: second }] = await Promise.all([
| sNextDeploy) {
// In deploy mode, concurrent requests could hit different lambdas.
it('should dedupe concurrent cache invocations in route handlers', async () => {
// Restart to ensure a cold server. Without this, p | {
"filepath": "test/e2e/app-dir/use-cache-route-handler-only/use-cache-route-handler-only.test.ts",
"language": "typescript",
"file_size": 1987,
"cut_index": 537,
"middle_length": 229
} |
llHandler =
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER === 'true'
describe('navigation-focus', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('navigation to an interactive segment', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[hr... | iveElement.getAttribute('data-testid')
)
).toBe('segment-container')
}
})
})
it('navigation to a scrollable segment', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[href="/scroll | if (enableNewScrollHandler) {
expect(await browser.eval(() => document.activeElement.localName)).toBe(
'body'
)
} else {
expect(
await browser.eval(() =>
document.act | {
"filepath": "test/e2e/app-dir/navigation-focus/navigation-focus.test.ts",
"language": "typescript",
"file_size": 3628,
"cut_index": 614,
"middle_length": 229
} |
ort type { ReactNode } from 'react'
import Link from 'next/link'
import './styles.css'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>
<nav aria-label="Main navigation">
<ul>
<li>
<Link href="/">Home</Link>
... | <Link href="/uri-fragments#section-2">
to URI fragment in different Segment
</Link>
</li>
<li>
<Link href="/uri-fragments">Segment with URI fragments</Link>
</li>
| Segment</Link>
</li>
<li>
<Link href="/segment-with-focusable-descendant">
Segment with focusable descendant
</Link>
</li>
<li>
| {
"filepath": "test/e2e/app-dir/navigation-focus/app/layout.tsx",
"language": "tsx",
"file_size": 1087,
"cut_index": 515,
"middle_length": 229
} |
() {
return (
<>
<nav aria-label="table of contents">
<ol>
<li>
<Link href="#section-1">Section 1</Link>
</li>
<li>
<Link href="#section-2">Section 2</Link>
</li>
<li>
<Link href="#section-3">Section 3</Link>
... | e={{ height: '100vh' }}>bla</p>
<h2 id="section-2">Section 2</h2>
<p style={{ height: '100vh' }}>bla</p>
<h2 id="section-3">Section 3</h2>
<p style={{ height: '100vh' }}>bla</p>
<h2 id="section-4">Section 4</h2>
| <h2 id="section-1">Section 1</h2>
<p styl | {
"filepath": "test/e2e/app-dir/navigation-focus/app/uri-fragments/page.tsx",
"language": "tsx",
"file_size": 967,
"cut_index": 582,
"middle_length": 52
} |
('app-dir assetPrefix handling', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should redirect route when requesting it directly', async () => {
const res = await next.fetch('/a/', {
redirect: 'manual',
})
expect(res.status).toBe(308)
expect(new URL(res.headers.get('... | redirect route when clicking link', async () => {
const browser = await next.browser('/')
await browser
.elementByCss('#to-a-trailing-slash')
.click()
.waitForElementByCss('#a-page')
expect(await browser.waitForElementByCss(' | })
it('should redirect route when requesting it directly by browser', async () => {
const browser = await next.browser('/a')
expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page')
})
it('should | {
"filepath": "test/e2e/app-dir/asset-prefix/asset-prefix.test.ts",
"language": "typescript",
"file_size": 2244,
"cut_index": 563,
"middle_length": 229
} |
('react@experimental', () => {
const { next } = nextTestSetup({
files: __dirname,
overrideFiles: {
'next.config.js': `
module.exports = {
experimental: {
taint: true,
}
}
`,
},
})
it('should opt into the react@experimental when enabling $fla... | ]
expect({
ssrReact,
ssrReactDOM,
ssrClientReact,
ssrClientReactDOM,
ssrClientReactDOMServer,
}).toEqual({
ssrReact: expect.stringMatching('-experimental-'),
ssrReactDOM: expect.stringMatching('-experiment | rver,
] = [
resPages$('#react').text(),
resPages$('#react-dom').text(),
resPages$('#client-react').text(),
resPages$('#client-react-dom').text(),
resPages$('#client-react-dom-server').text(),
| {
"filepath": "test/e2e/app-dir/rsc-basic/rsc-basic-react-experimental.test.ts",
"language": "typescript",
"file_size": 2330,
"cut_index": 563,
"middle_length": 229
} |
rn result
}
describe('app dir - rsc basics', () => {
const { next, isNextDev, isNextStart, isTurbopack } = nextTestSetup({
files: __dirname,
resolutions: {
'@babel/core': '7.22.18',
'@babel/parser': '7.22.16',
'@babel/types': '7.22.17',
'@babel/traverse': '7.22.18',
},
})
if ... | erenceManifest.clientModules
)
expect(clientModulesNames).toSatisfyAll((name) => {
const [, key] = name.split('#', 2)
return key === undefined || key === '' || key === 'default'
})
})
})
}
describe | ient-side manifest is correct before any requests
const clientReferenceManifest = getClientReferenceManifest(
next,
'/page'
)
const clientModulesNames = Object.keys(
clientRef | {
"filepath": "test/e2e/app-dir/rsc-basic/rsc-basic.test.ts",
"language": "typescript",
"file_size": 22252,
"cut_index": 1331,
"middle_length": 229
} |
Direct from '../../components/client'
import ClientFromShared from '../../components/shared'
import SharedFromClient from '../../components/shared-client'
import Bar from '../../components/bar'
export default function Page() {
// All three client components should be rendered correctly, but only
// shared componen... |
{/* <Random /> */}
<br />
<ClientFromDirect />
<br />
<ClientFromShared />
<br />
<ClientFromShared />
<br />
<SharedFromClient />
<br />
<SharedFromClient />
<br />
<Bar />
| eturn (
<div id="main" suppressHydrationWarning> | {
"filepath": "test/e2e/app-dir/rsc-basic/app/shared/page.js",
"language": "javascript",
"file_size": 851,
"cut_index": 529,
"middle_length": 52
} |
xports
import { a, b, c, d, e } from '../../components/shared-exports'
// client default, named exports
import DefaultArrow, {
Named as ClientNamed,
} from '../../components/client-exports'
import { Cjs as CjsShared } from '../../components/cjs-server'
import { Cjs as CjsClient } from '../../components/cjs-client'
... | <DefaultArrow />
</div>
<div>
<ClientNamed />
</div>
<div>
<CjsShared />
</div>
<div>
<CjsClient />
</div>
<div>
Export All: <One />, <Two />, <TwoAliased />
</di | {d}
{e[0]}
</div>
<div>
| {
"filepath": "test/e2e/app-dir/rsc-basic/app/various-exports/page.js",
"language": "javascript",
"file_size": 857,
"cut_index": 529,
"middle_length": 52
} |
ponses haven't reached the client yet.
*/
import { nextTestSetup, type Playwright } from 'e2e-utils'
import { createRouterAct } from 'router-act'
/**
* Reads the rendered route history from the page and returns an array of
* {url, params} objects representing every route state the app rendered.
*/
async function ... | xtDev) {
// Route prediction with static siblings requires production build
// because dev mode uses on-demand compilation (staticChildren is null)
test('skipped in dev mode', () => {})
return
}
it('basic dynamic route prediction: show | tr = await el.getAttribute('data-history')
return JSON.parse(attr).map((h: string) => JSON.parse(h))
}
describe('optimistic-routing', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNe | {
"filepath": "test/e2e/app-dir/optimistic-routing/optimistic-routing.test.ts",
"language": "typescript",
"file_size": 19334,
"cut_index": 1331,
"middle_length": 229
} |
Suspense, type ReactNode } from 'react'
// Validation level is 'warning' (set in next.config.ts).
// Bare page/default segments get implicit validation in dev only — build
// is unaffected unless a segment explicitly overrides with `level: 'experimental-error'`.
//
// Children are wrapped in Suspense so that pages wi... | lation when it runs.
export const unstable_instant = false
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<Suspense fallback={<p>loading…</p>}>{children}</Suspense>
</body>
| or instant navigation" as an
// instant-specific vio | {
"filepath": "test/e2e/app-dir/instant-validation-level-warning/app/layout.tsx",
"language": "tsx",
"file_size": 846,
"cut_index": 520,
"middle_length": 52
} |
waitForNoErrorToast } from 'next-test-utils'
import { join } from 'node:path'
describe('instant validation - opting out of static shells', () => {
const { next, skipped, isNextDev } = nextTestSetup({
files: join(__dirname, 'fixtures', 'valid'),
skipDeployment: true,
})
if (skipped) return
// NOTE: if ... | ayout is configured as blocking', async () => {
const browser = await next.browser('/blocking-layout')
await browser.elementByCss('main')
if (isNextDev) await waitForNoErrorToast(browser)
})
it('does not require a static shell if a page is | ocking', async () => {
const browser = await next.browser('/blocking-root-layout')
await browser.elementByCss('main')
if (isNextDev) await waitForNoErrorToast(browser)
})
it('does not require a static shell if a l | {
"filepath": "test/e2e/app-dir/instant-validation-static-shells/instant-validation-static-shells.test.ts",
"language": "typescript",
"file_size": 2719,
"cut_index": 563,
"middle_length": 229
} |
tTestSetup } from 'e2e-utils'
describe('app dir - crossOrigin config', () => {
const { next, isNextStart, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
if (isNextStart) {
it('skip in start mode', () => {})
return
}
it('should render c... | // Inline <script /> (including RSC payload) and <link /> should not have crossorigin attribute
$('script:not([src]), link:not([href])').each((_, el) => {
const crossOrigin = $(el).attr('crossorigin')
expect(crossOrigin).toBeUndefined()
| $(
'script[src*="https://example.vercel.sh"], link[href*="https://example.vercel.sh"]'
).each((_, el) => {
const crossOrigin = $(el).attr('crossorigin')
expect(crossOrigin).toBe('use-credentials')
})
| {
"filepath": "test/e2e/app-dir/app-config-crossorigin/index.test.ts",
"language": "typescript",
"file_size": 1274,
"cut_index": 524,
"middle_length": 229
} |
next-test-utils'
describe('app-dir refresh', () => {
const { next, skipped, isNextDev } = nextTestSetup({
files: __dirname,
// We do not have access to runtime logs when deployed
skipDeployment: true,
})
if (skipped) return
it('should refresh client cache when refresh() is called in a server acti... | .elementById('server-timestamp')
.text()
expect(newServerTimestamp).not.toBe(initialServerTimestamp)
expect(Number(newServerTimestamp)).toBeGreaterThan(
Number(initialServerTimestamp)
)
})
})
it('should thro | ServerTimestamp).toBeTruthy()
await new Promise((resolve) => setTimeout(resolve, 100))
await browser.elementById('refresh-button').click()
await retry(async () => {
const newServerTimestamp = await browser
| {
"filepath": "test/e2e/app-dir/refresh/refresh.test.ts",
"language": "typescript",
"file_size": 3280,
"cut_index": 614,
"middle_length": 229
} |
ort { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('conflicting-page-segments', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
// we skip start & deploy because the build will fail and we won't be able to catch it
// start is re-trigger... | th.'
)
} else {
await expect(next.start()).rejects.toThrow('next build failed')
await retry(() => {
expect(next.cliOutput).toMatch(
/You cannot have two parallel pages that resolve to the same path\. Please check \/ | ith a parallel segment', async () => {
if (isNextDev) {
await next.start()
const html = await next.render('/')
expect(html).toContain(
'You cannot have two parallel pages that resolve to the same pa | {
"filepath": "test/e2e/app-dir/conflicting-page-segments/conflicting-page-segments.test.ts",
"language": "typescript",
"file_size": 1085,
"cut_index": 515,
"middle_length": 229
} |
} from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
export default async function Page() {
return (
<>
<p>
This page accesses cookies synchronously at runtime. This triggers a
type error. In dev mode, we also log an explicit error that `cookies()`... | e.
await connection()
// Cast to any as we removed UnsafeUnwrapped types, but still need to test with the sync access
const token = (cookies() as any).get('token')
return (
<div>
this component reads the `token` cookie synchronously: {to | to test the subsequent sync cookies access at runtim | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/default/app/sync-cookies-runtime/page.tsx",
"language": "tsx",
"file_size": 866,
"cut_index": 529,
"middle_length": 52
} |
ort { BuildID } from './build-id'
import Indirection from './indirection'
import { date as date1 } from './client-lazy-now-1'
import { date as date2 } from './client-lazy-now-2'
import { date as date3 } from './client-lazy-now-3'
export default async function Page() {
return (
<>
<p>
This page has ... | sync IO when
being initialized during the final render.
</p>
<BuildID />
<Indirection>
<p>Date 1: {date1}</p>
</Indirection>
<Indirection>
<p>Date 2: {date2}</p>
</Indirection>
<Indirection | not lead to
unexpected sync IO errors. In the past this particular setup would show
up as a sync IO error because the later modules did not initialize
during the prospective render and thus appeared to use | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/lazy-module-init/app/serial-client-sync-io/page.tsx",
"language": "tsx",
"file_size": 1068,
"cut_index": 515,
"middle_length": 229
} |
rt { unstable_cacheTag, cacheTag } from 'next/cache'
export default async function Page() {
const stable = await stableTag()
const unstable1 = await unstableTag1()
const unstable2 = await unstableTag2()
return (
<>
<div>
This page calls a "use cache" function that uses the unstable_cacheTag
... | ag1() {
'use cache'
unstable_cacheTag('tag')
return Math.random()
}
async function unstableTag2() {
'use cache'
unstable_cacheTag('tag')
return Math.random()
}
async function stableTag() {
'use cache'
cacheTag('tag')
return Math.random( | able2}</div>
</>
)
}
async function unstableT | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/unstable-deprecations/app/tag/page.tsx",
"language": "tsx",
"file_size": 828,
"cut_index": 516,
"middle_length": 52
} |
import { Suspense } from 'react'
import Link from 'next/link'
export default async function Page() {
return (
<main>
<section>
<p>
This page has has a slow to fill cache. When not bypassing the dev
cache the initial load should be slow while the cache warms up. You
won... | pense fallback={<p>Loading from cache...</p>}>
<CachedData />
</Suspense>
</section>
<Link href="/">Go back home</Link>
</main>
)
}
async function CachedData() {
'use cache'
await new Promise((r) => setTimeout(r, 2 | Suspend When bypassing caches in
dev with "disable cache" the request should instantly show a fallback
UI and show the final content after the delay.
</p>
</section>
<section>
<Sus | {
"filepath": "test/e2e/app-dir/cache-components-errors/fixtures/dev-cache-bypass/app/other/page.tsx",
"language": "tsx",
"file_size": 1027,
"cut_index": 512,
"middle_length": 229
} |
tuck on shared state from the outer render scope. The same function completed when run in isolation, which usually means a module-scoped value (for example a top-level Map used to dedupe fetches) is joining a promise created outside the cache. "use cache" already dedupes calls with the same arguments — within a request... | auto-start.
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (skipped) {
return
}
if (!isNextDev) {
it('is a dev-only suite', () => {})
return
}
describe('when a "use cache" fill hangs in the static stage due to module | se-cache-deadlock-probe', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
// Probe behavior is dev-only; skip the production server start, but
// let dev mode | {
"filepath": "test/e2e/app-dir/use-cache-deadlock-probe/use-cache-deadlock-probe.test.ts",
"language": "typescript",
"file_size": 14156,
"cut_index": 921,
"middle_length": 229
} |
pense } from 'react'
import { getData, preload } from '../shared'
const sharedUrl =
'https://next-data-api-endpoint.vercel.app/api/random?page=recovery-stuck'
// `Quick` emits a chunk during the first probe's window, which suppresses
// that probe's verdict via the mid-probe recovery check. `Stuck` is
// deadlocked... | nc function Stuck() {
const data = await getData(sharedUrl).then((res) => res.text())
return <p id="stuck">{data}</p>
}
async function getCachedData() {
'use cache'
return (
<>
<Suspense fallback={null}>
<Quick />
</Suspen | hold. That
// second probe sees no chunks during its own window and correctly
// reports the deadlock.
async function Quick() {
await new Promise((resolve) => setTimeout(resolve, 11_000))
return <p id="quick">quick</p>
}
asy | {
"filepath": "test/e2e/app-dir/use-cache-deadlock-probe/app/recovery-stuck/page.tsx",
"language": "tsx",
"file_size": 1327,
"cut_index": 524,
"middle_length": 229
} |
./shared'
const sharedUrl =
'https://next-data-api-endpoint.vercel.app/api/random?page=static'
async function getCachedData(): Promise<string> {
'use cache'
// Joins the outer fetch via the module-scoped dedupe map (see note in
// ../shared.ts).
return getData(sharedUrl).then((res) => res.text())
}
async ... | return <p id="result">Error: {error.message}</p>
}
}
export default function Page() {
// Simulate another part of the tree (e.g. a sibling component or a shared
// data loader) kicking off the same fetch in outer scope before `Cached`
// runs.
| turn <p id="result">{data}</p>
} catch (error) {
| {
"filepath": "test/e2e/app-dir/use-cache-deadlock-probe/app/static/page.tsx",
"language": "tsx",
"file_size": 899,
"cut_index": 547,
"middle_length": 52
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.