Unverified Commit d81ef269 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

feat(breaking): Hard Deprecate PPR Configuration (#84280)

This hard deprecates the `experimental.ppr` configuration, requiring
users to opt-in instead via `experimental.cacheComponents`. This does
mean that the previous `experimental.ppr = "incremental"` will no longer
be supported.

NAR-433
parent 6cecc754
......@@ -700,7 +700,6 @@ jobs:
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: |
export __NEXT_EXPERIMENTAL_PPR=true # for compatibility with the existing tests
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
......
......@@ -110,7 +110,7 @@
"test-storybook": "turbo run test-storybook",
"with-rspack": "cross-env NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1",
"with-webpack": "cross-env IS_WEBPACK_TEST=1",
"with-experimental": "cross-env __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_PPR=true __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true"
"with-experimental": "cross-env __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true"
},
"devDependencies": {
"@actions/core": "1.10.1",
......
......@@ -862,5 +862,6 @@
"861": "Client Max Body Size must be larger than 0 bytes",
"862": "Request body exceeded %s",
"863": "\\`<Link legacyBehavior>\\` received a direct child that is either a Server Component, or JSX that was loaded with React.lazy(). This is not supported. Either remove legacyBehavior, or make the direct child a Client Component that renders the Link's \\`<a>\\` tag.",
"864": "Missing value for segment key: \"%s\" with dynamic param type: %s"
"864": "Missing value for segment key: \"%s\" with dynamic param type: %s",
"865": "`experimental.rdcForNavigations` is enabled, but `experimental.cacheComponents` is not."
}
......@@ -13,7 +13,7 @@ import type { SizeLimit } from '../types'
import type { SupportedTestRunners } from '../cli/next-test'
import type { ExperimentalPPRConfig } from './lib/experimental/ppr'
import { INFINITE_CACHE } from '../lib/constants'
import { isStableBuild } from '../shared/lib/canary-only'
import { isStableBuild } from '../shared/lib/errors/canary-only-config-error'
import type { FallbackRouteParam } from '../build/static-paths/types'
export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & {
......@@ -573,8 +573,8 @@ export interface ExperimentalConfig {
clientTraceMetadata?: string[]
/**
* Enables experimental Partial Prerendering feature of Next.js.
* Using this feature will enable the `react@experimental` for the `app` directory.
* @deprecated This configuration option has been merged into `experimental.cacheComponents`.
* The Partial Prerendering feature is still available via `experimental.cacheComponents`.
*/
ppr?: ExperimentalPPRConfig
......
......@@ -86,13 +86,13 @@ describe('loadConfig', () => {
const loadConfigPromise = loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
ppr: true,
cacheComponents: true,
},
},
})
await expect(loadConfigPromise).rejects.toThrow(
/The experimental feature "experimental.ppr" can only be enabled when using the latest canary version of Next.js./
/The experimental feature "experimental.cacheComponents" can only be enabled when using the latest canary version of Next.js./
)
try {
......@@ -115,7 +115,7 @@ describe('loadConfig', () => {
},
})
).rejects.toThrow(
/The experimental feature "experimental.ppr" can only be enabled when using the latest canary version of Next.js./
/`experimental\.ppr` has been merged into `experimental\.cacheComponents`/
)
})
......@@ -157,41 +157,40 @@ describe('loadConfig', () => {
delete process.env.__NEXT_VERSION
})
it('errors when cacheComponents is enabled but PPR is disabled', async () => {
it('errors when rdcForNavigations is enabled but cacheComponents is disabled', async () => {
await expect(
loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
cacheComponents: true,
rdcForNavigations: true,
ppr: false,
},
},
})
).rejects.toThrow(
'`experimental.ppr` can not be `false` when `experimental.cacheComponents` is `true`. PPR is implicitly enabled when Cache Components is enabled.'
'`experimental.rdcForNavigations` is enabled, but `experimental.cacheComponents` is not.'
)
})
it('errors when rdcForNavigations is enabled but ppr is disabled', async () => {
it('errors when ppr is set to incremental', async () => {
await expect(
loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
rdcForNavigations: true,
ppr: false,
ppr: 'incremental',
},
},
})
).rejects.toThrow(
'`experimental.rdcForNavigations` is enabled, but `experimental.ppr` is not.'
/`experimental\.ppr` has been merged into `experimental\.cacheComponents`/
)
})
it('defaults rdcForNavigations to true when ppr is enabled', async () => {
it('defaults rdcForNavigations to true when cacheComponents is enabled', async () => {
const result = await loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
ppr: true,
cacheComponents: true,
},
},
})
......@@ -199,34 +198,6 @@ describe('loadConfig', () => {
expect(result.experimental.rdcForNavigations).toBe(true)
})
it('allows explicitly disabling rdcForNavigations when ppr is enabled', async () => {
const result = await loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
ppr: true,
rdcForNavigations: false,
},
},
})
expect(result.experimental.rdcForNavigations).toBe(false)
})
it('errors when cacheComponents is enabled but PPR set to "incremental"', async () => {
await expect(
loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: {
experimental: {
cacheComponents: true,
ppr: 'incremental',
},
},
})
).rejects.toThrow(
'`experimental.ppr` can not be `"incremental"` when `experimental.cacheComponents` is `true`. PPR is implicitly enabled when Cache Components is enabled.'
)
})
it('migrates experimental.dynamicIO to experimental.cacheComponents', async () => {
process.env.__NEXT_VERSION = 'canary'
......
......@@ -38,10 +38,14 @@ import { dset } from '../shared/lib/dset'
import { normalizeZodErrors } from '../shared/lib/zod'
import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot'
import { findDir } from '../lib/find-pages-dir'
import { CanaryOnlyError, isStableBuild } from '../shared/lib/canary-only'
import {
CanaryOnlyConfigError,
isStableBuild,
} from '../shared/lib/errors/canary-only-config-error'
import { interopDefault } from '../lib/interop-default'
import { djb2Hash } from '../shared/lib/hash'
import type { NextAdapter } from '../build/adapter/build-complete'
import { HardDeprecatedConfigError } from '../shared/lib/errors/hard-deprecated-config-error'
export { normalizeConfig } from './config-shared'
export type { DomainLocale, NextConfig } from './config-shared'
......@@ -365,17 +369,23 @@ function assignDefaultsAndValidate(
if (isStableBuild()) {
// Prevents usage of certain experimental features outside of canary
if (result.experimental?.ppr) {
throw new CanaryOnlyError({ feature: 'experimental.ppr' })
} else if (result.experimental?.cacheComponents) {
throw new CanaryOnlyError({ feature: 'experimental.cacheComponents' })
if (result.experimental?.cacheComponents) {
throw new CanaryOnlyConfigError({
feature: 'experimental.cacheComponents',
})
} else if (result.experimental?.turbopackFileSystemCacheForBuild) {
throw new CanaryOnlyError({
throw new CanaryOnlyConfigError({
feature: 'experimental.turbopackFileSystemCacheForBuild',
})
}
}
if (result.experimental.ppr) {
throw new HardDeprecatedConfigError(
`\`experimental.ppr\` has been merged into \`experimental.cacheComponents\`. The Partial Prerendering feature is still available, but is now enabled via \`experimental.cacheComponents\`. Please update your ${configFileName} accordingly.`
)
}
if (result.output === 'export') {
if (result.i18n) {
throw new Error(
......@@ -1178,6 +1188,11 @@ function assignDefaultsAndValidate(
result.experimental.mcpServer = true
}
// TODO: remove once we've finished migrating internally to cacheComponents.
if (result.experimental.cacheComponents) {
result.experimental.ppr = true
}
// "use cache" was originally implicitly enabled with the cacheComponents flag, so
// we transfer the value for cacheComponents to the explicit useCache flag to ensure
// backwards compatibility.
......@@ -1185,39 +1200,10 @@ function assignDefaultsAndValidate(
result.experimental.useCache = result.experimental.cacheComponents
}
// If cacheComponents is enabled, we also enable PPR.
if (result.experimental.cacheComponents) {
if (
userConfig.experimental?.ppr === false ||
userConfig.experimental?.ppr === 'incremental'
) {
throw new Error(
`\`experimental.ppr\` can not be \`${JSON.stringify(userConfig.experimental?.ppr)}\` when \`experimental.cacheComponents\` is \`true\`. PPR is implicitly enabled when Cache Components is enabled.`
)
}
result.experimental.ppr = true
if (
configuredExperimentalFeatures &&
// If we've already noted that the `process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`
// has enabled the feature, we don't need to note it again.
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS !== 'true' &&
process.env.__NEXT_EXPERIMENTAL_PPR !== 'true'
) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'ppr',
true,
'enabled by `experimental.cacheComponents`'
)
}
}
// If ppr is enabled and the user hasn't configured rdcForNavigations, we
// enable it by default.
// If cacheComponents is enabled and the user hasn't configured
// rdcForNavigations, we enable it by default.
if (
result.experimental.ppr &&
result.experimental.cacheComponents &&
userConfig.experimental?.rdcForNavigations === undefined
) {
result.experimental.rdcForNavigations = true
......@@ -1227,15 +1213,18 @@ function assignDefaultsAndValidate(
configuredExperimentalFeatures,
'rdcForNavigations',
true,
'enabled by `experimental.ppr`'
'enabled by `experimental.cacheComponents`'
)
}
}
// If rdcForNavigations is enabled, but ppr is not, we throw an error.
if (result.experimental.rdcForNavigations && !result.experimental.ppr) {
// If rdcForNavigations is enabled, but cacheComponents is not, we throw an error.
if (
result.experimental.rdcForNavigations &&
!result.experimental.cacheComponents
) {
throw new Error(
'`experimental.rdcForNavigations` is enabled, but `experimental.ppr` is not.'
'`experimental.rdcForNavigations` is enabled, but `experimental.cacheComponents` is not.'
)
}
......@@ -1714,47 +1703,9 @@ function enforceExperimentalFeatures(
)
}
// TODO: Remove this once we've made Cache Components the default.
if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.ppr === undefined ||
(isDefaultConfig && !config.experimental.ppr))
) {
config.experimental.ppr = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'ppr',
true,
'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
)
}
}
// TODO: Remove this once we've made Cache Components the default.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.ppr === undefined ||
(isDefaultConfig && !config.experimental.ppr))
) {
config.experimental.ppr = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'ppr',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
)
}
}
// TODO: Remove this once we've made Client Param Parsing the default.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.clientParamParsing === undefined ||
(isDefaultConfig && !config.experimental.clientParamParsing))
......@@ -1766,7 +1717,7 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures,
'clientParamParsing',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
)
}
}
......@@ -1790,7 +1741,7 @@ function enforceExperimentalFeatures(
}
}
// TODO: Remove this once we've made RDC for Navigations the default for PPR.
// TODO: Remove this once we've made RDC for Navigations the default for cache components.
if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config.
......@@ -1828,25 +1779,6 @@ function enforceExperimentalFeatures(
}
}
// TODO: Remove this once we've made RDC for Navigations the default for PPR.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.rdcForNavigations === undefined ||
(isDefaultConfig && !config.experimental.rdcForNavigations))
) {
config.experimental.rdcForNavigations = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'rdcForNavigations',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
)
}
}
if (
process.env.__NEXT_ENABLE_REACT_COMPILER === 'true' &&
// We do respect an explicit value in the user config.
......
......@@ -6,7 +6,7 @@ export function isStableBuild() {
)
}
export class CanaryOnlyError extends Error {
export class CanaryOnlyConfigError extends Error {
constructor(arg: { feature: string } | string) {
if (typeof arg === 'object' && 'feature' in arg) {
super(
......
export class HardDeprecatedConfigError extends Error {
constructor(message: string) {
super(message)
// This error is meant to interrupt the server start/build process
// but the stack trace isn't meaningful, as it points to internal code.
this.stack = undefined
}
}
......@@ -9,7 +9,7 @@ import {
retry,
} from 'next-test-utils'
const pprEnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const pprEnabled = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
describe('Error overlay for hydration errors in App router', () => {
const { next, isTurbopack } = nextTestSetup({
......
......@@ -15,7 +15,7 @@ const nextConfig = {
}
},
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -4,7 +4,8 @@ import { retry } from 'next-test-utils'
const isCacheComponentsEnabled =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
describe('source-mapping', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('source-mapping', () => {
const { next } = nextTestSetup({
files: __dirname,
})
......
......@@ -40,7 +40,7 @@ describe('app-dir static/dynamic handling', () => {
}
})
if (!process.env.__NEXT_EXPERIMENTAL_PPR) {
if (!process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
it('should respond correctly for dynamic route with dynamicParams false in layout', async () => {
const res = await next.fetch('/partial-params-false/en/another')
expect(res.status).toBe(200)
......@@ -783,7 +783,7 @@ describe('app-dir static/dynamic handling', () => {
if (isNextStart) {
it('should not encode dynamic parameters as search parameters in RSC data', async () => {
const data = process.env.__NEXT_EXPERIMENTAL_PPR
const data = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS
? await next.readFile('.next/server/app/blog/seb.prefetch.rsc')
: await next.readFile('.next/server/app/blog/seb.rsc')
......@@ -3307,7 +3307,7 @@ describe('app-dir static/dynamic handling', () => {
for (let i = 0; i < 5; i++) {
const res = await next.fetch('/articles/non-existent')
if (process.env.__NEXT_EXPERIMENTAL_PPR && !isNextDev) {
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS && !isNextDev) {
expect(res.status).toBe(200)
} else {
expect(res.status).toBe(404)
......@@ -3522,7 +3522,7 @@ describe('app-dir static/dynamic handling', () => {
})
} else {
// TODO: re-implement this in a way that'll support PFPR
if (!process.env.__NEXT_EXPERIMENTAL_PPR) {
if (!process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
it('should not error with dynamic server usage with force-static', async () => {
const res = await next.fetch(
'/static-to-dynamic-error-forced/static-bailout-1'
......@@ -3563,7 +3563,7 @@ describe('app-dir static/dynamic handling', () => {
)
})
if (!process.env.__NEXT_EXPERIMENTAL_PPR) {
if (!process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
it('should properly error when dynamic = "error" page uses dynamic', async () => {
const res = await next.fetch('/dynamic-error/static-bailout-1')
const outputIndex = next.cliOutput.length
......@@ -4460,7 +4460,7 @@ describe('app-dir static/dynamic handling', () => {
expect(html).toInclude('"noindex"')
expect(html).toInclude('This page could not be found.')
if (process.env.__NEXT_EXPERIMENTAL_PPR && !isNextDev) {
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS && !isNextDev) {
expect(res.status).toBe(200)
} else {
expect(res.status).toBe(404)
......
......@@ -5,7 +5,7 @@ export const dynamic = 'error'
export default async function Page(props) {
const params = await props.params
// When PPR is enabled, we will bailout on parameter access.
if (!process.env.__NEXT_EXPERIMENTAL_PPR) {
if (!process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
if (params.id.includes('static-bailout')) {
console.log('calling cookies', await cookies())
}
......
......@@ -7,11 +7,6 @@ import {
RSC_HEADER,
} from 'next/dist/client/components/app-router-headers'
// TODO: We should decide on an established pattern for gating test assertions
// on experimental flags. For example, as a first step we could all the common
// gates like this one into a single module.
const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
describe('app dir - basic', () => {
const { next, isNextDev, isNextStart, isNextDeploy } = nextTestSetup({
files: __dirname,
......@@ -592,7 +587,7 @@ describe('app dir - basic', () => {
;(isNextDev ||
// When PPR is enabled, the shared layouts re-render because we prefetch
// from the root. This will be addressed before GA.
isPPREnabledByDefault
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? it.skip
: it)(
'should not rerender layout when navigating between routes in the same layout',
......@@ -1389,7 +1384,7 @@ describe('app dir - basic', () => {
;(isNextDev ||
// When PPR is enabled, the shared layouts re-render because we prefetch
// from the root. This will be addressed before GA.
isPPREnabledByDefault
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? it.skip
: it)(
'should render the template that is a server component and rerender on navigation',
......
......@@ -25,7 +25,7 @@ describe('custom-cache-control', () => {
isNextDev ? 'no-store, must-revalidate' : 's-maxage=31'
)
})
;(process.env.__NEXT_EXPERIMENTAL_PPR ? it.skip : it)(
;(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS ? it.skip : it)(
'should have default cache-control for app-ssg another',
async () => {
const res = await next.fetch('/app-ssg/another')
......
......@@ -27,7 +27,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
} else if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
// in PPR we expect the shell to be rendered at build and the page to be rendered at runtime
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime')
......@@ -57,7 +57,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
} else if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
// @TODO this should actually be build but there is a bug in how we do segment level dynamic in PPR at the moment
// see note in create-component-tree
expect($('#layout').text()).toBe('at runtime')
......@@ -88,7 +88,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
} else if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
// in PPR we expect the shell to be rendered at build and the page to be rendered at runtime
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime')
......@@ -124,7 +124,7 @@ describe('dynamic-data', () => {
expect($('#page').text()).toBe('at runtime')
// we don't assert the state of the fallback because it can depend on the timing
// of when streaming starts and how fast the client references resolve
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
} else if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
// in PPR we expect the shell to be rendered at build and the page to be rendered at runtime
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime')
......
import { nextTestSetup } from 'e2e-utils'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
;(isPPREnabled ? describe.skip : describe)(
'app-dir - metadata-static-generation',
......
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
// Skip PPR test as it's covered in test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts
;(isPPREnabled ? describe.skip : describe)(
......
......@@ -46,7 +46,7 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
// despite the page being static, the first two requests both cause a render
// and only the second one gets cached and re-used.
// we work around it by doing a dummy request to get that first "uncached" request out of the way.
if (process.env.__NEXT_EXPERIMENTAL_PPR) {
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
await getTimestampPageData(path)
}
......
import { nextTestSetup } from 'e2e-utils'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
describe('app dir - not-found - default', () => {
const { next, isNextStart } = nextTestSetup({
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
prerenderEarlyExit: false,
},
}
......
......@@ -2,7 +2,8 @@ import { nextBuild } from 'next-test-utils'
// In order for the global isNextStart to be set
import 'e2e-utils'
describe('ppr build errors', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr build errors', () => {
;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only',
() => {
......
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -82,7 +82,8 @@ const expectDirectives = (header: string, directives: string[]) => {
expect(split.length).toEqual(directives.length)
}
describe('ppr-full', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-full', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
export { default } from '../../lib/page'
export const experimental_ppr = false
export { default } from '../../../../lib/page'
export const experimental_ppr = false
export { default } from '../../../../lib/page'
export const experimental_ppr = true
export { default } from '../../lib/page'
export const experimental_ppr = true
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export { default } from '../../../../../lib/page'
export const experimental_ppr = false
export { default } from '../../../../../lib/page'
export const experimental_ppr = true
export const experimental_ppr = false
export default function Layout({ children }) {
return children
}
export { default } from '../../../../../lib/page'
export const experimental_ppr = false
export { default } from '../../../../../lib/page'
export const experimental_ppr = true
export const experimental_ppr = true
export default function Layout({ children }) {
return children
}
export { default, generateStaticParams } from '../../../lib/page'
export const dynamicParams = false
export { default, generateStaticParams } from '../../../../lib/page'
export const experimental_ppr = false
export const dynamicParams = false
export { default, generateStaticParams } from '../../../../lib/page'
export const experimental_ppr = true
export const dynamicParams = false
export { default } from '../lib/page'
export default function Page() {
return <div id="static-page">Fully static page!</div>
}
import { unstable_noStore } from 'next/cache'
import Link from 'next/link'
import { Suspense } from 'react'
function Dynamic() {
unstable_noStore()
return <div id="dynamic">Dynamic</div>
}
export default function Page() {
return (
<>
<li>
<Link href="/">Root</Link>
<Link href="/enabled">Enabled</Link>
<Link href="/disabled">Disabled</Link>
<Link href="/static">Static</Link>
</li>
<Suspense fallback={<div id="fallback">Loading...</div>}>
<Dynamic />
</Suspense>
</>
)
}
export const slugs = ['a', 'b', 'c']
export const generateStaticParams = () => {
return slugs.map((slug) => ({ slug }))
}
/**
* @type {import('next').NextConfig}
*/
module.exports = {
experimental: {
ppr: 'incremental',
},
}
import { nextTestSetup, isNextDev } from 'e2e-utils'
type Route = {
route: string
enabled: boolean
pathnames: string[]
}
const routes: ReadonlyArray<Route> = [
{
route: '/',
pathnames: ['/'],
enabled: false,
},
{
route: '/disabled',
pathnames: ['/disabled'],
enabled: false,
},
{
route: '/enabled',
pathnames: ['/enabled'],
enabled: true,
},
{
route: '/omitted/[slug]',
pathnames: ['/omitted/a', '/omitted/b', '/omitted/c'],
enabled: false,
},
{
route: '/omitted/disabled/[slug]',
pathnames: [
'/omitted/disabled/a',
'/omitted/disabled/b',
'/omitted/disabled/c',
],
enabled: false,
},
{
route: '/omitted/enabled/[slug]',
pathnames: [
'/omitted/enabled/a',
'/omitted/enabled/b',
'/omitted/enabled/c',
],
enabled: true,
},
{
route: '/dynamic/[slug]',
pathnames: ['/dynamic/a', '/dynamic/b', '/dynamic/c'],
enabled: false,
},
{
route: '/dynamic/disabled/[slug]',
pathnames: [
'/dynamic/disabled/a',
'/dynamic/disabled/b',
'/dynamic/disabled/c',
],
enabled: false,
},
{
route: '/dynamic/enabled/[slug]',
pathnames: [
'/dynamic/enabled/a',
'/dynamic/enabled/b',
'/dynamic/enabled/c',
],
enabled: true,
},
{
route: '/nested/enabled/[slug]',
pathnames: ['/nested/enabled/a', '/nested/enabled/b', '/nested/enabled/c'],
enabled: true,
},
{
route: '/nested/enabled/disabled/[slug]',
pathnames: [
'/nested/enabled/disabled/a',
'/nested/enabled/disabled/b',
'/nested/enabled/disabled/c',
],
enabled: false,
},
{
route: '/nested/enabled/enabled/[slug]',
pathnames: [
'/nested/enabled/enabled/a',
'/nested/enabled/enabled/b',
'/nested/enabled/enabled/c',
],
enabled: true,
},
{
route: '/nested/disabled/[slug]',
pathnames: [
'/nested/disabled/a',
'/nested/disabled/b',
'/nested/disabled/c',
],
enabled: false,
},
{
route: '/nested/disabled/disabled/[slug]',
pathnames: [
'/nested/disabled/disabled/a',
'/nested/disabled/disabled/b',
'/nested/disabled/disabled/c',
],
enabled: false,
},
{
route: '/nested/disabled/enabled/[slug]',
pathnames: [
'/nested/disabled/enabled/a',
'/nested/disabled/enabled/b',
'/nested/disabled/enabled/c',
],
enabled: true,
},
]
describe('ppr-incremental', () => {
// We don't perform static builds and partial prerendering in development
// mode.
if (isNextDev) return it.skip('should skip next dev', () => {})
const { next } = nextTestSetup({ files: __dirname })
describe('ppr disabled', () => {
describe.each(routes.filter(({ enabled }) => !enabled))(
'$route',
({ pathnames }) => {
// When PPR is disabled, we won't include the fallback in the initial
// load because the dynamic render will not suspend.
describe('should render without the fallback in the initial load', () => {
it.each(pathnames)('%s', async (pathname) => {
const $ = await next.render$(pathname)
expect($('#fallback')).toHaveLength(0)
})
})
describe('should not have the dynamic content hidden', () => {
it.each(pathnames)('%s', async (pathname) => {
const $ = await next.render$(pathname)
expect($('#dynamic')).toHaveLength(1)
expect($('#dynamic').parent('[hidden]')).toHaveLength(0)
})
})
}
)
it('should not trigger a dynamic request for static pages', async () => {
let rscRequests = []
const browser = await next.browser('/', {
beforePageLoad(page) {
page.route('**/static*', async (route) => {
const request = route.request()
const headers = await request.allHeaders()
const url = new URL(request.url())
if (headers['rsc'] === '1') {
rscRequests.push(url.pathname)
await route.continue()
}
})
},
})
await browser.waitForIdleNetwork()
// we should see an RSC request for the initial prefetch to the static page
expect(rscRequests).toEqual(expect.arrayContaining(['/static']))
rscRequests = []
await browser.elementByCss('[href="/static"]').click()
await browser.waitForElementByCss('#static-page')
expect(rscRequests.length).toBe(0)
})
})
describe('ppr enabled', () => {
describe.each(routes.filter(({ enabled }) => enabled))(
'$route',
({ pathnames }) => {
// When PPR is enabled, we will always include the fallback in the
// initial load because the dynamic component uses `unstable_noStore()`.
describe('should render with the fallback in the initial load', () => {
it.each(pathnames)('%s', async (pathname) => {
const $ = await next.render$(pathname)
expect($('#fallback')).toHaveLength(1)
})
})
describe('should have the dynamic content hidden', () => {
it.each(pathnames)('%s', async (pathname) => {
const $ = await next.render$(pathname)
expect($('#dynamic')).toHaveLength(1)
expect($('#dynamic').parent('[hidden]')).toHaveLength(1)
})
})
}
)
})
})
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -4,7 +4,8 @@ function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1
}
describe('ppr-metadata-blocking-ppr-fallback', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-metadata-blocking-ppr-fallback', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
// Need to skip deployment because the test uses the private env cannot be used in deployment
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
useCache: true,
},
}
......
......@@ -6,7 +6,8 @@ function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1
}
describe('ppr-metadata-streaming', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-metadata-streaming', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
import { nextTestSetup } from 'e2e-utils'
import { expectedParams as expected } from './expected'
describe('ppr-middleware-rewrite-force-dynamic-generate-static-params', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr-middleware-rewrite-force-dynamic-generate-static-params', () => {
const { next } = nextTestSetup({
files: __dirname,
})
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
import { TestPage } from '../../../components/page'
export const experimental_ppr = true
export default async function Page(props) {
const params = await props.params
const { locale } = params
return <TestPage pathname={`/${locale}/about`} />
}
import { locales } from '../../components/page'
export async function generateStaticParams() {
return locales.map((locale) => ({ locale }))
}
export default async function Layout(props) {
const params = await props.params
const { locale } = params
const { children } = props
return (
<html lang={locale}>
<body>{children}</body>
</html>
)
}
import { TestPage } from '../../components/page'
export default async function Page(props) {
const params = await props.params
const { locale } = params
return <TestPage pathname={`/${locale}`} />
}
import { TestPage } from '../../../components/page'
export default async function Page(props) {
const params = await props.params
const { locale } = params
return <TestPage pathname={`/${locale}/static`} noDynamic />
}
export default ({ children }) => {
return children
}
import { redirect } from 'next/navigation'
import { locales } from '../components/page'
export default () => {
// Redirect to the default locale
return redirect(`/${locales[0]}`)
}
import { unstable_noStore } from 'next/cache'
import Link from 'next/link'
import { Suspense } from 'react'
export const locales = ['en', 'fr']
export const links = [
{ href: '/', text: 'Home' },
...locales
.map((locale) => {
return [
{ href: `/${locale}`, text: locale },
{ href: `/${locale}/about`, text: `${locale} - About` },
{ href: `/${locale}/static`, text: `${locale} - Static` },
]
})
.flat(),
]
function Dynamic({ noDynamic = false }) {
if (!noDynamic) unstable_noStore()
return <div id="dynamic">Dynamic</div>
}
export function TestPage({ pathname, noDynamic = false }) {
return (
<div>
<ul>
{links.map(({ href, text }) => (
<li key={href}>
<Link href={href}>{text}</Link>
</li>
))}
</ul>
<code data-value={pathname}>{pathname}</code>
<Suspense fallback={<div>Loading...</div>}>
<Dynamic noDynamic={noDynamic} />
</Suspense>
</div>
)
}
import { NextInstance, nextTestSetup } from 'e2e-utils'
import { links, locales } from './components/page'
import glob from 'glob'
import { promisify } from 'node:util'
import { waitForHydration } from 'development-sandbox'
import { setTimeout } from 'node:timers/promises'
const globp = promisify(glob)
async function getDotNextFiles(next: NextInstance): Promise<Array<string>> {
const files = await globp('**/.next/**/*', {
cwd: next.testDir,
absolute: true,
})
return files
}
describe('ppr-navigations incremental', () => {
const { next, isNextDev, isTurbopack, isNextDeploy } = nextTestSetup({
files: __dirname,
})
it('can navigate between all the links and back without writing to disk', async () => {
const before =
!isNextDev && !isTurbopack && !isNextDeploy
? await getDotNextFiles(next)
: []
const browser = await next.browser('/')
await browser.waitForIdleNetwork()
await waitForHydration(browser)
await setTimeout(500)
// Add a variable to the window so we can tell if it MPA navigated. If this
// value is still true at the end of the test, then we know that the page
// didn't MPA navigate.
const random = Math.random().toString(36).substring(7)
await browser.eval(`window.random = ${JSON.stringify(random)}`)
try {
for (const { href } of links) {
// Find the link element for the href and click it.
await browser.waitForElementByCss(`a[href="${href}"]`).click()
await browser.waitForIdleNetwork()
await waitForHydration(browser)
await setTimeout(500)
// Wait for that page to load.
if (href === '/') {
// The root page redirects to the first locale.
await browser.waitForElementByCss(`[data-value="/${locales[0]}"]`)
} else {
await browser.waitForElementByCss(`[data-value="${href}"]`)
}
await browser.waitForElementByCss('#dynamic', 1500)
// Check if the page navigated.
expect(await browser.eval(`window.random`)).toBe(random)
}
} finally {
await browser.close()
}
if (!isNextDev && !isTurbopack && !isNextDeploy) {
const after = await getDotNextFiles(next)
// Ensure that no new files were written to disk. If this test fails, it's
// likely that there was a change to the incremental cache or file system
// cache that resulted in information like the ppr state not being properly
// propagated.
expect(after).toEqual(before)
}
})
})
module.exports = {
experimental: {
ppr: 'incremental',
},
}
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
import { nextTestSetup } from 'e2e-utils'
describe('prefetch-navigation', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('prefetch-navigation', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
import { createNext } from 'e2e-utils'
describe('search-params', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('search-params', () => {
if ((global as any).isNextDev) {
test('ppr is disabled in dev', () => {})
return
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -2,9 +2,7 @@ import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
ppr: true,
// until the flags are merged, test both `ppr` and `cacheComponents`
// cacheComponents: true,
cacheComponents: true,
},
}
......
module.exports = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -2,7 +2,8 @@ import { nextTestSetup } from 'e2e-utils'
import { retry, findAllTelemetryEvents } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('ppr', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr', () => {
const { next, isNextDev, isNextStart } = nextTestSetup({
files: __dirname,
env: {
......
......@@ -7,7 +7,7 @@ const nextConfig = {
: undefined,
experimental: {
// Emitting Link headers currently requires the experimental PPR feature.
ppr: true,
cacheComponents: true,
},
}
......
......@@ -42,7 +42,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -78,7 +78,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -114,7 +114,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -151,7 +151,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -187,7 +187,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -223,7 +223,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -259,7 +259,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -295,7 +295,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -339,7 +339,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......@@ -442,7 +442,7 @@ const cases: {
headers: {
rsc: '1',
'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? {
'next-router-segment-prefetch': '/_tree',
}
......
......@@ -10,7 +10,8 @@ import {
// TODO: We should decide on an established pattern for gating test assertions
// on experimental flags. For example, as a first step we could all the common
// gates like this one into a single module.
const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabledByDefault =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
async function resolveStreamResponse(response: any, onData?: any) {
let result = ''
......@@ -460,7 +461,7 @@ describe('app dir - rsc basics', () => {
// TODO: (PPR) remove once PPR is stable
// TODO(new-dev-overlay): remove once new dev overlay is stable
const bundledReactVersionPattern =
process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? '-experimental-'
: '-canary-'
......
......@@ -34,20 +34,21 @@ describe('rsc-redirect', () => {
})
})
// TODO: these tests aren't currently run at all during testing
if (process.env.NODE_ENV === 'production') {
describe.each([
{ ppr: true, segmentCache: true },
{ ppr: true, segmentCache: false },
{ ppr: false, segmentCache: true },
{ ppr: false, segmentCache: false },
{ cacheComponents: true, segmentCache: true },
{ cacheComponents: true, segmentCache: false },
{ cacheComponents: false, segmentCache: true },
{ cacheComponents: false, segmentCache: false },
] as const)(
'rsc-redirect /old-about -> /about (ppr: $ppr, segmentCache: $segmentCache)',
({ ppr, segmentCache }) => {
'rsc-redirect /old-about -> /about (cacheComponents: $cacheComponents, segmentCache: $segmentCache)',
({ cacheComponents, segmentCache }) => {
beforeAll(() => {
// Write next.config.js with the current flags
fs.writeFileSync(
configPath,
`module.exports = { experimental: { ppr: ${ppr}, clientSegmentCache: ${segmentCache} } }\n`
`module.exports = { experimental: { cacheComponents: ${cacheComponents}, clientSegmentCache: ${segmentCache} } }\n`
)
})
......
export default function Loading() {
return <div>Loading dynamic content...</div>
}
import { connection } from 'next/server'
export const experimental_ppr = true
export default async function DynamicPage() {
await connection()
return <div id="dynamic-content">Dynamic Content</div>
}
export default function Loading() {
return <div>Loading dynamic content...</div>
}
import { connection } from 'next/server'
export default async function DynamicPage() {
await connection()
return <div id="dynamic-content">Dynamic Content</div>
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { LinkAccordion } from '../components/link-accordion'
export default function Page() {
return (
<div>
<h1>
<code>clientSegmentCache: 'client-only'</code>
</h1>
<p>
This page demonstrates the behavior when the experimental Segment Cache
flag is set to <code>'client-only'</code> instead of <code>true</code>.
The new prefetching implementation is enabled on the client, but the
server will not generate any per-segment prefetching. This is useful
because the client implementation has many other improvements that are
unrelated to per-segment prefetching, like improved scheduling and
dynamic request deduping.
</p>
<ul>
<li>
<LinkAccordion href="/static">Static page</LinkAccordion>
</li>
<li>
<LinkAccordion href="/dynamic-with-ppr">
Dynamic page (with PPR enabled)
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/dynamic-without-ppr">
Dynamic page (without PPR enabled)
</LinkAccordion>
</li>
</ul>
</div>
)
}
export default function StaticPage() {
return <div id="static-content">Static Content</div>
}
import { nextTestSetup } from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('segment cache prefetch scheduling', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled', () => {})
return
}
it('prefetches a static page in a single request', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
})
// Because per-segment prefetching is not enabled in this app, the attempt
// to prefetch the route tree will return not just the tree but the data for
// the entire page. Although this prevents us from deduping shared layouts,
// we should seed the cache with the extra data to avoid a second request
// for the data.
const linkVisibilityToggle = await browser.elementByCss(
'input[data-link-accordion="/static"]'
)
await act(
async () => {
await linkVisibilityToggle.click()
},
{
// This assertion will fail if this string appears in multiple requests.
includes: 'Static Content',
}
)
// When navigating to the prefetched static page, no additional requests
// are issued.
const link = await browser.elementByCss('a[href="/static"]')
await act(async () => {
await link.click()
const staticContent = await browser.elementById('static-content')
expect(await staticContent.innerHTML()).toBe('Static Content')
}, 'no-requests')
})
// TODO: This is disabled because, due to a recent change to metadata
// prefetches, sometimes a fully static page is requested twice unnecessarily.
// Disabling for now rather than fixing since it only happens in "client-only"
// mode, which was never properly supported or released,
// and we're about to delete.
it.skip('prefetches a dynamic page (with PPR enabled)', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
})
const linkVisibilityToggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic-with-ppr"]'
)
await act(async () => {
await linkVisibilityToggle.click()
}, [
// This assertion will fail if this string appears in multiple requests.
{
includes: 'Loading dynamic content...',
},
// Does not include the dynamic content
{
block: 'reject',
includes: 'Dynamic Content',
},
])
// When navigating to the prefetched dynamic page, an additional request
// is issued to fetch the dynamic content.
const link = await browser.elementByCss('a[href="/dynamic-with-ppr"]')
await act(
async () => {
await link.click()
},
{
includes: 'Dynamic Content',
}
)
const dynamicContent = await browser.elementById('dynamic-content')
expect(await dynamicContent.innerHTML()).toBe('Dynamic Content')
})
it('prefetches a dynamic page (without PPR enabled)', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
})
const linkVisibilityToggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic-without-ppr"]'
)
await act(async () => {
await linkVisibilityToggle.click()
}, [
// This assertion will fail if this string appears in multiple requests.
{
includes: 'Loading dynamic content...',
},
// Does not include the dynamic content
{
block: 'reject',
includes: 'Dynamic Content',
},
])
// When navigating to the prefetched dynamic page, an additional request
// is issued to fetch the dynamic content.
const link = await browser.elementByCss('a[href="/dynamic-without-ppr"]')
await act(
async () => {
await link.click()
},
{
includes: 'Dynamic Content',
}
)
const dynamicContent = await browser.elementById('dynamic-content')
expect(await dynamicContent.innerHTML()).toBe('Dynamic Content')
})
})
'use client'
import Link, { type LinkProps } from 'next/link'
import { useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = useState(false)
return (
<>
<input
type="checkbox"
checked={isVisible}
onChange={() => setIsVisible(!isVisible)}
data-link-accordion={href}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
<>{children} (link is hidden)</>
)}
</>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: 'incremental',
clientSegmentCache: 'client-only',
},
}
module.exports = nextConfig
import { connection } from 'next/server'
export default async function Page() {
await connection()
return <div>/[lang]/[teamSlug]/[projectSlug]/monitoring</div>
}
export const experimental_ppr = true
import { connection } from 'next/server'
export default async function Page() {
await connection()
return <div>/[lang]/[teamSlug]/~/monitoring</div>
}
export default function RootLayout({ children, params }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export function generateStaticParams() {
return ['en', 'fr'].map((lang) => ({ lang }))
}
export default function Loading() {
return <div>Loading...</div>
}
import Link from 'next/link'
export default function Page() {
return (
<div>
<Link href="/es/~/monitoring">Monitoring</Link>
</div>
)
}
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return '/new/[teamSlug]/page.tsx'
}
import { connection } from 'next/server'
export default async function Page() {
await connection()
return <div>/prefetch-tests/[id]</div>
}
export const experimental_ppr = true
import { connection } from 'next/server'
export default async function Page() {
await connection()
return <div>/prefetch-tests/dynamic</div>
}
export default function RootLayout({ children, params }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import Link from 'next/link'
export default function Page() {
return (
<div>
<Link href="/prefetch-tests/dynamic">Dynamic</Link>
</div>
)
}
import { nextTestSetup } from 'e2e-utils'
import { computeCacheBustingSearchParam } from 'next/dist/shared/lib/router/utils/cache-busting-search-param'
describe('conflicting routes', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('prefetching is disabled', () => {})
return
}
// The server will reject prefetch requests that don't set a cache-busting
// search param.
// TODO: We should try to avoid unit tests that simulate internal client
// router requests. There are only a handful of cases that do this currently.
// In the meantime, consider moving this into a shared testing utility.
async function segmentPrefetch(url: string, segmentPath: string) {
const fetchUrl = new URL(url, 'http://localhost')
const searchParams = new URLSearchParams(fetchUrl.search)
searchParams.set(
'_rsc',
computeCacheBustingSearchParam('1', segmentPath, undefined, undefined)
)
fetchUrl.search = searchParams.toString()
return await next.fetch(fetchUrl.pathname + fetchUrl.search, {
headers: {
rsc: '1',
'next-router-prefetch': '1',
'next-router-segment-prefetch': segmentPath,
},
})
}
it.each([
'/en/vercel/~/monitoring',
'/fr/vercel/~/monitoring',
'/es/vercel/~/monitoring',
])('%s matches the right route', async (path) => {
const res = await segmentPrefetch(path, '/_tree')
expect(res.status).toBe(200)
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/[lang]/[teamSlug]/~/monitoring.prefetch.rsc'
)
}
})
it('matches the right route when the original route has no dynamic params, is dynamic, and PPR is disabled', async () => {
const res = await segmentPrefetch('/prefetch-tests/dynamic', '/_tree')
expect(res.status).toBe(200)
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/prefetch-tests/dynamic.prefetch.rsc'
)
}
})
it('handles conflict between App Router and Pages Router routes', async () => {
const res = await segmentPrefetch('/new/templates', '/_tree')
expect(res.status).toBe(200)
expect(await res.text()).toContain(
// when deployed we map to an empty object to signal to
// client router it should MPA navigate
isNextDeploy ? '{}' : '/new/templates/[[...slug]].js'
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: 'incremental',
clientSegmentCache: true,
},
}
module.exports = nextConfig
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
export default function Page() {
return '/new/templates/[[...slug]].js'
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
'use client'
import Link, { type LinkProps } from 'next/link'
import { useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
id,
}: {
href: string
children: string
prefetch?: LinkProps['prefetch']
id?: string
}) {
const [isVisible, setIsVisible] = useState(false)
return (
<>
<input
type="checkbox"
checked={isVisible}
onChange={() => setIsVisible(!isVisible)}
data-link-accordion={href}
id={id}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
`${children} (link is hidden)`
)}
</>
)
}
import { Suspense } from 'react'
import { connection } from 'next/server'
async function DynamicContentInSharedLayout() {
await connection()
return (
<div id="dynamic-content-in-shared-layout">
Dynamic content in shared layout
</div>
)
}
export default function SharedLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<div id="shared-layout">
<Suspense
fallback={
<div id="shared-layout-ppr-boundary">
Loading (PPR shell of shared-layout)...
</div>
}
>
<DynamicContentInSharedLayout />
</Suspense>
{children}
</div>
)
}
import { Suspense } from 'react'
import { connection } from 'next/server'
async function Content() {
await connection()
return <div id="page-content">Dynamic page content</div>
}
export default async function Page() {
return (
<Suspense fallback={<div id="page-loading-boundary">Loading page...</div>}>
<Content />
</Suspense>
)
}
import { Suspense } from 'react'
import { connection } from 'next/server'
export const experimental_ppr = true
async function Content() {
await connection()
return <div id="page-content">Dynamic page content</div>
}
export default async function Page() {
return (
<Suspense fallback={<div id="page-loading-boundary">Loading page...</div>}>
<Content />
</Suspense>
)
}
export default function SharedLayout({
children,
}: {
children: React.ReactNode
}) {
return <div id="has-loading-boundary">{children}</div>
}
export default function Loading() {
return (
<div id="loading-boundary">
Loading (has-loading-boundary/loading.tsx)...
</div>
)
}
import { LinkAccordion } from '../link-accordion'
export default function MixedFetchStrategies() {
return (
<>
<p>
This page tests what happens when a shared layout belongs to both a
PPR-enabled route and a non-PPR enabled route. The layout data should be
omitted when prefetching the non-PPR enabled route, because it's inside
another layout that has a loading boundary. But it should be included
when prefetching the route that has PPR enabled.
</p>
<ul>
<li>
<LinkAccordion
id="ppr-enabled"
href="/mixed-fetch-strategies/has-loading-boundary/a/b/shared-layout/ppr-enabled"
>
Link to PPR enabled page
</LinkAccordion>
<ul>
<li>
<LinkAccordion
id="ppr-enabled-prefetch-true"
prefetch="unstable_forceStale"
href="/mixed-fetch-strategies/has-loading-boundary/a/b/shared-layout/ppr-enabled"
>
Same link, but with prefetch="unstable_forceStale"
</LinkAccordion>
</li>
</ul>
</li>
<li>
<LinkAccordion
id="ppr-disabled"
href="/mixed-fetch-strategies/has-loading-boundary/a/b/shared-layout/ppr-disabled"
>
Link to PPR disabled page
</LinkAccordion>
</li>
</ul>
</>
)
}
import { LinkAccordion } from './link-accordion'
export default function Page() {
return (
<>
<p>
This page is used to test that if you prefetch a link multiple times,
the prefetches are deduped by the client cache (unless/until they become
stale). The e2e associated with this page works by toggling the
visibility of the links and checking whether any prefetch requests are
issued.
</p>
<p>
You can test the behavior manually by opening up the network tab in the
browser's DevTools and seeing what happens when you toggle a Link's
visibility.
</p>
<ul>
<li>
<LinkAccordion href="/ppr-enabled">
Page with PPR enabled
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/ppr-enabled/dynamic-param">
Page with PPR enabled but has dynamic param
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/ppr-disabled">
Page with PPR disabled
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/ppr-disabled-with-loading-boundary">
Page with PPR disabled, but has a loading boundary
</LinkAccordion>
<ul>
<li>
<LinkAccordion href="/ppr-disabled-with-loading-boundary/child">
Another dynamic page that shares the same loading boundary
</LinkAccordion>
</li>
</ul>
</li>
<li>
<LinkAccordion
prefetch={true}
href="/ppr-disabled-dynamic-head?foo=yay"
>
Page with PPR disabled and a dynamic head, prefetch=true
</LinkAccordion>
</li>
</ul>
</>
)
}
import { Suspense } from 'react'
import { connection } from 'next/server'
import { Metadata } from 'next'
export async function generateMetadata({
searchParams,
}: {
searchParams: Promise<{ foo: string }>
}): Promise<Metadata> {
const { foo } = await searchParams
return {
title: 'Dynamic Title: ' + (foo ?? '(empty)'),
}
}
async function Content() {
await connection()
return <div id="page-content">Page content</div>
}
export default function PPRDisabledDynamicHead() {
return (
<Suspense fallback="Loading...">
<Content />
</Suspense>
)
}
import { connection } from 'next/server'
export default async function PPRDisabledWithLoadingBoundaryChildPage() {
await connection()
return <div id="child-page-content">Child page content</div>
}
export default function Loading() {
return <div id="loading-boundary">Loading...</div>
}
import { connection } from 'next/server'
export default async function PPRDisabledWithLoadingBoundary() {
await connection()
return <div id="page-content">Page content</div>
}
import { Suspense } from 'react'
import { connection } from 'next/server'
async function Content() {
await connection()
return <div id="page-content">Page content</div>
}
export default function PPRDisabled() {
return (
<Suspense fallback="Loading...">
<Content />
</Suspense>
)
}
export default function Page() {
return <div id="page-content">Page content</div>
}
export const experimental_ppr = true
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return children
}
export default function PPREnabled() {
return <div id="page-content">Page content</div>
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: 'incremental',
clientSegmentCache: true,
},
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import { createRouterAct } from 'router-act'
import { Page } from 'playwright'
describe('segment cache (incremental opt in)', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
test('ppr is disabled', () => {})
return
}
async function testPrefetchDeduping(linkHref) {
// This e2e test app is designed to verify that if you prefetch a link
// multiple times, the prefetches are deduped by the client cache
// (unless/until they become stale). It works by toggling the visibility of
// the links and checking whether any prefetch requests are issued.
//
// Throughout the duration of the test, we collect all the prefetch requests
// that occur. Then at the end we confirm there are no duplicates.
const prefetches = new Map()
const duplicatePrefetches = new Map()
const unexpectedResponses = []
let currentPage: Page
const browser = await next.browser('/', {
async beforePageLoad(page) {
currentPage = page
await page.route('**/*', async (route) => {
const request = route.request()
const headers = await request.allHeaders()
const isPrefetch =
headers['rsc'] !== undefined &&
headers['next-router-prefetch'] !== undefined
if (isPrefetch) {
const url = request.url()
const prefetchInfo = {
href: new URL(url).pathname,
segment: headers['next-router-segment-prefetch'],
base: headers['next-router-state-tree'] ?? null,
}
const key = JSON.stringify(prefetchInfo)
if (prefetches.has(key)) {
duplicatePrefetches.set(key, prefetchInfo)
} else {
prefetches.set(key, prefetchInfo)
}
const response = await page.request.fetch(request, {
maxRedirects: 0,
})
const status = response.status()
if (status !== 200) {
unexpectedResponses.push({
status,
url,
headers: response.headers(),
response: await response.text(),
})
}
return route.fulfill({ response })
}
route.continue()
})
},
})
// Each link on the test page has a checkbox that controls its visibility.
// It starts off as hidden.
const checkbox = await browser.elementByCss(
`input[data-link-accordion="${linkHref}"]`
)
// Confirm the checkbox is not checked
expect(await checkbox.isChecked()).toBe(false)
// Click the checkbox to reveal the link and trigger a prefetch
await checkbox.click()
await browser.elementByCss(`a[href="${linkHref}"]`)
// Toggle the visibility of the link. Prefetches are initiated on viewport,
// so if the cache does not dedupe then properly, this test will detect it.
await checkbox.click() // hide
await checkbox.click() // show
const link = await browser.elementByCss(`a[href="${linkHref}"]`)
// Navigate to the target link
await link.click()
// Confirm the navigation happened
await browser.elementById('page-content')
expect(new URL(await browser.url()).pathname).toBe(linkHref)
// Wait for all pending requests to complete.
await currentPage.unrouteAll({ behavior: 'wait' })
// Finally, assert there were no duplicate prefetches and no unexpected
// responses.
expect(prefetches).not.toBeEmpty()
expect(duplicatePrefetches).toBeEmpty()
expect(unexpectedResponses).toBeEmpty()
}
describe('multiple prefetches to same link are deduped', () => {
it('page with PPR enabled', () => testPrefetchDeduping('/ppr-enabled'))
it('page with PPR enabled, and has a dynamic param', () =>
testPrefetchDeduping('/ppr-enabled/dynamic-param'))
it('page with PPR disabled', () => testPrefetchDeduping('/ppr-disabled'))
it('page with PPR disabled, and has a loading boundary', () =>
testPrefetchDeduping('/ppr-disabled-with-loading-boundary'))
})
it('prefetches a dynamic route when PPR is disabled if it has a loading.tsx boundary', async () => {
let act
const browser = await next.browser('/', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Initiate a prefetch for a dynamic page with no PPR, but with a
// loading.tsx boundary. We should be able to prefetch up to the
// loading boundary.
await act(async () => {
const checkbox = await browser.elementByCss(
`input[data-link-accordion="/ppr-disabled-with-loading-boundary"]`
)
await checkbox.click()
}, [
// Response includes the loading boundary
{ includes: 'Loading...' },
// but it does not include the dynamic page content
{ includes: 'Page content', block: 'reject' },
])
// Navigate to the page
await act(
async () => {
await browser
.elementByCss(`a[href="/ppr-disabled-with-loading-boundary"]`)
.click()
// We can immediately render the loading boundary before the network
// responds, because it was prefetched
const loadingBoundary = await browser.elementById('loading-boundary')
expect(await loadingBoundary.text()).toBe('Loading...')
},
// The page content is fetched on navigation
{ includes: 'Page content' }
)
const pageContent = await browser.elementById('page-content')
expect(await pageContent.text()).toBe('Page content')
})
it(
'skips prefetching a dynamic route when PPR is disabled if everything up ' +
'to its loading.tsx boundary is already cached',
async () => {
let act
const browser = await next.browser('/', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Initiate a prefetch for a dynamic page with no PPR, but with a
// loading.tsx boundary. We should be able to prefetch up to the
// loading boundary.
await act(async () => {
const checkbox = await browser.elementByCss(
`input[data-link-accordion="/ppr-disabled-with-loading-boundary"]`
)
await checkbox.click()
}, [
// Response includes the loading boundary
{ includes: 'Loading...' },
// but it does not include the dynamic page content
{ includes: 'Page content', block: 'reject' },
])
// When prefetching a different page with the same loading boundary,
// we should not need to fetch the loading boundary again
await act(
async () => {
const checkbox = await browser.elementByCss(
`input[data-link-accordion="/ppr-disabled-with-loading-boundary/child"]`
)
await checkbox.click()
},
{ includes: 'Loading...', block: 'reject' }
)
// Navigate to the page
await act(async () => {
await browser
.elementByCss(`a[href="/ppr-disabled-with-loading-boundary/child"]`)
.click()
// We can immediately render the loading boundary before the network
// responds, because it was prefetched
const loadingBoundary = await browser.elementById('loading-boundary')
expect(await loadingBoundary.text()).toBe('Loading...')
}, [
// The page content is fetched on navigation
{ includes: 'Child page content' },
// The loading boundary is not fetched on navigation, because it
// was already loaded into the cache during the prefetch for the
// other page.
{ includes: 'Loading...', block: 'reject' },
])
const pageContent = await browser.elementById('child-page-content')
expect(await pageContent.text()).toBe('Child page content')
}
)
it('skips prefetching a dynamic route when PPR is disabled if it has no loading.tsx boundary', async () => {
let act
const browser = await next.browser('/', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Initiate a prefetch for a dynamic page with no loading.tsx and no PPR.
// The route tree prefetch will tell the client that there is no loading
// boundary, and therefore the client can skip prefetching the data, since
// it would be an empty response, anyway.
await act(
async () => {
const checkbox = await browser.elementByCss(
`input[data-link-accordion="/ppr-disabled"]`
)
await checkbox.click()
},
// We should not prefetch the page content
{ includes: 'Page content', block: 'reject' }
)
// Navigate to the page
await act(
async () => {
await browser.elementByCss(`a[href="/ppr-disabled"]`).click()
},
// The page content is fetched on navigation
{ includes: 'Page content' }
)
const pageContent = await browser.elementById('page-content')
expect(await pageContent.text()).toBe('Page content')
})
it(
'prefetches a shared layout on a PPR-enabled route that was previously ' +
'omitted from a non-PPR-enabled route',
async () => {
let act
const browser = await next.browser('/mixed-fetch-strategies', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Initiate a prefetch for the PPR-disabled route first. This will not
// include the /shared-layout/ segment, because it's inside the
// loading boundary.
await act(async () => {
const checkbox = await browser.elementById('ppr-disabled')
await checkbox.click()
})
// Then initiate a prefetch for the PPR-enabled route. This prefetch
// should include the /shared-layout/ segment despite the presence of
// the loading boundary, and despite the earlier non-PPR attempt
await act(async () => {
const checkbox = await browser.elementById('ppr-enabled')
await checkbox.click()
})
// Navigate to the PPR-enabled route
await act(async () => {
const link = await browser.elementByCss('#ppr-enabled + a')
await link.click()
// If we prefetched all the segments correctly, we should be able to
// reveal the page's loading state, before the server responds.
await browser.elementById('page-loading-boundary')
})
}
)
it(
'when a link is prefetched with <Link prefetch="unstable_forceStale">, no dynamic request ' +
'is made on navigation',
async () => {
let act
const browser = await next.browser('/mixed-fetch-strategies', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
await act(
async () => {
const checkbox = await browser.elementById(
'ppr-enabled-prefetch-true'
)
await checkbox.click()
},
{
includes: 'Dynamic page content',
}
)
// Navigate to fully prefetched route
const link = await browser.elementByCss('#ppr-enabled-prefetch-true + a')
await act(
async () => {
await link.click()
// We should be able to fully load the page content, including the
// dynamic data, before the server responds.
await browser.elementById('page-content')
},
// Assert that no network requests are initiated within this block.
'no-requests'
)
}
)
it(
'when prefetching with prefetch="unstable_forceStale", refetches cache entries that only ' +
'contain partial data',
async () => {
let act
const browser = await next.browser('/mixed-fetch-strategies', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Prefetch a link with PPR
await act(
async () => {
const checkbox = await browser.elementById('ppr-enabled')
await checkbox.click()
},
{ includes: 'Loading (PPR shell of shared-layout)...' }
)
// Prefetch the same link again, this time with prefetch="unstable_forceStale" to include
// the dynamic data
await act(
async () => {
const checkbox = await browser.elementById(
'ppr-enabled-prefetch-true'
)
await checkbox.click()
},
{
includes: 'Dynamic content in shared layout',
}
)
// Navigate to the PPR-enabled route
const link = await browser.elementByCss('#ppr-enabled-prefetch-true + a')
await act(
async () => {
await link.click()
// If we prefetched all the segments correctly, we should be able to
// fully load the page content, including the dynamic data, before the
// server responds.
//
// If this fails, it likely means that the partial cache entry that
// resulted from prefetching the normal link (<Link prefetch={false}>)
// was not properly re-fetched when the full link (<Link
// prefetch='unstable_forceStale'>) was prefetched.
await browser.elementById('page-content')
},
// Assert that no network requests are initiated within this block.
'no-requests'
)
}
)
it(
'when prefetching with prefetch="unstable_forceStale", refetches partial cache entries ' +
"even if there's already a pending PPR request",
async () => {
// This test is hard to describe succinctly because it involves a fairly
// complex race condition between a non-PPR prefetch, a PPR prefetch, and
// a "full" prefetch. Despite the complexity of the scenario, it's worth
// testing because could easily happen in real world conditions.
let act
const browser = await next.browser('/mixed-fetch-strategies', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
// Initiate a prefetch for the PPR-disabled route first. This will not
// include the /shared-layout/ segment, because it's inside the
// loading boundary.
await act(
async () => {
const checkbox = await browser.elementById('ppr-disabled')
await checkbox.click()
},
{ includes: 'Loading (has-loading-boundary/loading.tsx)...' }
)
// Then initiate a prefetch for the PPR-enabled route.
await act(async () => {
// Create an inner act scope so we initate a prefetch but block it
// from responding.
await act(
async () => {
const checkbox = await browser.elementById('ppr-enabled')
await checkbox.click()
},
{
// This prefetch should include the /shared-layout/ segment despite
// the presence of the loading boundary, and despite the earlier
// non-PPR attempt.
includes: 'Loading (PPR shell of shared-layout)...',
// We're going to block it from responding, so we can test what
// happens if another prefetch is initiated in the meantime.
block: true,
}
)
// Before the previous prefetch finishes, prefetch the same link again,
// this time with prefetch="unstable_forceStale" to include the dynamic data.
await act(
async () => {
const checkbox = await browser.elementById(
'ppr-enabled-prefetch-true'
)
await checkbox.click()
},
// This prefetch should load the dynamic data in the shared layout
{
includes: 'Dynamic content in shared layout',
}
)
})
// Navigate to the PPR-enabled route.
await act(
async () => {
const link = await browser.elementByCss(
'#ppr-enabled-prefetch-true + a'
)
await link.click()
// If we prefetched all the segments correctly, we should be able to
// fully load the page content, including the dynamic data, before the
// server responds.
//
// If this fails, it likely means that the pending cache entry that
// resulted from prefetching the normal link (<Link prefetch={false}>)
// was not properly re-fetched when the full link (<Link
// prefetch='unstable_forceStale'>) was prefetched.
await browser.elementById('page-content')
},
// Assert that no network requests are initiated within this block.
'no-requests'
)
}
)
it('fully prefetch a page with a dynamic title', async () => {
let act
const browser = await next.browser('/', {
beforePageLoad(p) {
act = createRouterAct(p)
},
})
await act(
async () => {
const checkbox = await browser.elementByCss(
'input[data-link-accordion="/ppr-disabled-dynamic-head?foo=yay"]'
)
await checkbox.click()
},
// Because the link is prefetched with prefetch=true, we should be able to
// prefetch the title, even though it's dynamic.
{
includes: 'Dynamic Title: yay',
// TODO: Due to a race condition, the metadata is sometimes fetched twice
// instead of once (though not more than that). The planned fix is to
// cache metadata separate from the route tree. Then we can remove
// this option.
allowMultipleResponses: true,
}
)
// When we navigate to the page, it should not make any additional
// network requests, because both the segment data and the head were
// fully prefetched.
await act(async () => {
const link = await browser.elementByCss(
'a[href="/ppr-disabled-dynamic-head?foo=yay"]'
)
await link.click()
const pageContent = await browser.elementById('page-content')
expect(await pageContent.text()).toBe('Page content')
const title = await browser.eval(() => document.title)
expect(title).toBe('Dynamic Title: yay')
}, 'no-requests')
})
})
import { nextTestSetup } from 'e2e-utils'
describe('static-shell-debugging', () => {
const ppr = Boolean(process.env.__NEXT_EXPERIMENTAL_PPR)
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('static-shell-debugging', () => {
const ppr = Boolean(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS)
const context = {
ppr,
debugging: ppr,
......
......@@ -13,10 +13,7 @@ describe('middleware-static-rewrite', () => {
return
}
if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' ||
process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
) {
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true') {
// Here we're validating that the correct fallback shell was used for
// rendering.
it('should use the correct fallback route', async () => {
......
......@@ -10,7 +10,7 @@ describe('use-cache-output-export', () => {
skipStart: process.env.NEXT_TEST_MODE !== 'dev',
})
if (process.env.__NEXT_EXPERIMENTAL_PPR === 'true') {
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true') {
return it.skip('for PPR', () => {
// PPR is not compatible with `output: 'export'`.
})
......
import { nextTestSetup } from 'e2e-utils'
const pprEnabled =
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ||
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
const pprEnabled = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
describe('use-cache-private', () => {
const { next, isNextDev } = nextTestSetup({
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
useCache: true,
},
}
......
......@@ -16,8 +16,6 @@ import { PrerenderManifest } from 'next/dist/build'
const GENERIC_RSC_ERROR =
'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
const withPPR = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const withCacheComponents =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
......@@ -451,7 +449,7 @@ describe('use-cache', () => {
let prerenderedRoutes = Object.entries(prerenderManifest.routes)
if (withPPR || withCacheComponents) {
if (withCacheComponents) {
// For the purpose of this test we don't consider an incomplete shell.
prerenderedRoutes = prerenderedRoutes.filter(([pathname, route]) => {
const filename = pathname.replace(/^\//, '').replace(/^$/, 'index')
......@@ -508,7 +506,7 @@ describe('use-cache', () => {
})
it('should match the expected revalidate and expire configs on the prerender manifest', async () => {
const { version, routes, dynamicRoutes } = JSON.parse(
const { version, routes } = JSON.parse(
await next.readFile('.next/prerender-manifest.json')
) as PrerenderManifest
......@@ -525,14 +523,6 @@ describe('use-cache', () => {
expect(routes['/cache-life-with-dynamic'].initialExpireSeconds).toBe(
300
)
} else if (withPPR) {
// We don't exclude dynamic caches for the legacy PPR prerendering.
expect(
routes['/cache-life-with-dynamic'].initialRevalidateSeconds
).toBe(99)
expect(routes['/cache-life-with-dynamic'].initialExpireSeconds).toBe(
299
)
}
// default expireTime
......@@ -541,12 +531,6 @@ describe('use-cache', () => {
// The revalidate config from the fetch call should lower the revalidate
// config for the page.
expect(routes['/cache-tag'].initialRevalidateSeconds).toBe(42)
if (withPPR) {
// cache life profile "weeks"
expect(dynamicRoutes['/[id]'].fallbackRevalidate).toBe(604800)
expect(dynamicRoutes['/[id]'].fallbackExpire).toBe(2592000)
}
})
it('should match the expected stale config in the page header', async () => {
......@@ -562,14 +546,6 @@ describe('use-cache', () => {
expect(cacheLifeWithDynamicMeta.headers['x-nextjs-stale-time']).toBe(
'19'
)
} else if (withPPR) {
const cacheLifeWithDynamicMeta = JSON.parse(
await next.readFile('.next/server/app/cache-life-with-dynamic.meta')
)
// We don't exclude dynamic caches for the legacy PPR prerendering.
expect(cacheLifeWithDynamicMeta.headers['x-nextjs-stale-time']).toBe(
'18'
)
}
})
......@@ -1020,7 +996,7 @@ describe('use-cache', () => {
})
}
if (isNextStart && withPPR) {
if (isNextStart && withCacheComponents) {
it('should exclude inner caches and omitted caches from the resume data cache (RDC)', async () => {
await next.fetch('/rdc')
......
......@@ -63,976 +63,968 @@ describe('opentelemetry', () => {
},
},
]) {
;(process.env.__NEXT_EXPERIMENTAL_PPR ? describe.skip : describe)(
env.name,
() => {
describe('app router', () => {
it('should handle RSC with fetch', async () => {
await next.fetch('/app/param/rsc-fetch', env.fetchInit)
;(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS
? describe.skip
: describe)(env.name, () => {
describe('app router', () => {
it('should handle RSC with fetch', async () => {
await next.fetch('/app/param/rsc-fetch', env.fetchInit)
await expectTrace(getCollector(), [
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch',
attributes: {
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch',
'http.status_code': 200,
'http.target': '/app/param/rsc-fetch',
'next.route': '/app/[param]/rsc-fetch',
'next.rsc': false,
'next.span_name': 'GET /app/[param]/rsc-fetch',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch',
attributes: {
'next.route': '/app/[param]/rsc-fetch',
'next.span_name':
'render route (app) /app/[param]/rsc-fetch',
'next.span_type': 'AppRender.getBodyResult',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'build component tree',
attributes: {
'next.span_name': 'build component tree',
'next.span_type': 'NextNodeServer.createComponentTree',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'resolve segment modules',
attributes: {
'next.segment': '__PAGE__',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve segment modules',
attributes: {
'next.segment': '[param]',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'fetch GET https://example.vercel.sh/',
attributes: {
'http.method': 'GET',
'http.url': 'https://example.vercel.sh/',
'net.peer.name': 'example.vercel.sh',
'next.span_name':
'fetch GET https://example.vercel.sh/',
'next.span_type': 'AppRender.fetch',
},
kind: 2,
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/layout',
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/rsc-fetch/page',
attributes: {
'next.page': '/app/[param]/rsc-fetch/page',
'next.span_name':
'generateMetadata /app/[param]/rsc-fetch/page',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
{
attributes: {
'next.clientComponentLoadCount': isNextDev ? 7 : 6,
'next.span_type':
'NextNodeServer.clientComponentLoading',
},
kind: 0,
name: 'NextNodeServer.clientComponentLoading',
status: {
code: 0,
},
},
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'resolve page components',
attributes: {
'next.route': '/app/[param]/rsc-fetch',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should propagate custom context without span', async () => {
await next.fetch('/app/param/rsc-fetch', {
...env.fetchInit,
headers: { ...env.fetchInit?.headers, 'x-custom': 'custom1' },
})
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch',
attributes: {
custom: 'custom1',
},
},
])
})
it('should handle RSC with fetch on edge', async () => {
await next.fetch('/app/param/rsc-fetch/edge', env.fetchInit)
await expectTrace(
getCollector(),
[
{
name: 'GET /app/[param]/rsc-fetch',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
runtime: 'edge',
name: 'GET /app/[param]/rsc-fetch/edge',
kind: 1,
attributes: {
'next.span_name': 'GET /app/[param]/rsc-fetch/edge',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch',
'http.target': '/app/param/rsc-fetch/edge?param=param',
'http.status_code': 200,
'http.target': '/app/param/rsc-fetch',
'next.route': '/app/[param]/rsc-fetch',
'next.rsc': false,
'next.span_name': 'GET /app/[param]/rsc-fetch',
'next.span_type': 'BaseServer.handleRequest',
'next.route': '/app/[param]/rsc-fetch/edge',
'http.route': '/app/[param]/rsc-fetch/edge',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch',
name: 'render route (app) /app/[param]/rsc-fetch/edge',
kind: 0,
attributes: {
'next.route': '/app/[param]/rsc-fetch',
'next.span_name':
'render route (app) /app/[param]/rsc-fetch',
'render route (app) /app/[param]/rsc-fetch/edge',
'next.span_type': 'AppRender.getBodyResult',
'next.route': '/app/[param]/rsc-fetch/edge',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'build component tree',
kind: 0,
attributes: {
'next.span_name': 'build component tree',
'next.span_type':
'NextNodeServer.createComponentTree',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'resolve segment modules',
kind: 0,
attributes: {
'next.segment': '__PAGE__',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
'next.segment': '__PAGE__',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve segment modules',
kind: 0,
attributes: {
'next.segment': '[param]',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
'next.segment': '[param]',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'fetch GET https://example.vercel.sh/',
kind: 2,
attributes: {
'http.method': 'GET',
'http.url': 'https://example.vercel.sh/',
'net.peer.name': 'example.vercel.sh',
'next.span_name':
'fetch GET https://example.vercel.sh/',
'next.span_type': 'AppRender.fetch',
'http.url': 'https://example.vercel.sh/',
'http.method': 'GET',
'net.peer.name': 'example.vercel.sh',
},
kind: 2,
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/layout',
kind: 0,
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
'next.page': '/app/[param]/layout',
},
kind: 0,
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/rsc-fetch/page',
name: 'generateMetadata /app/[param]/rsc-fetch/edge/page',
kind: 0,
attributes: {
'next.page': '/app/[param]/rsc-fetch/page',
'next.span_name':
'generateMetadata /app/[param]/rsc-fetch/page',
'generateMetadata /app/[param]/rsc-fetch/edge/page',
'next.span_type': 'ResolveMetadata.generateMetadata',
'next.page': '/app/[param]/rsc-fetch/edge/page',
},
kind: 0,
status: { code: 0 },
},
{
attributes: {
'next.clientComponentLoadCount': isNextDev ? 7 : 6,
'next.span_type':
'NextNodeServer.clientComponentLoading',
},
kind: 0,
name: 'NextNodeServer.clientComponentLoading',
status: {
code: 0,
},
},
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'resolve page components',
attributes: {
'next.route': '/app/[param]/rsc-fetch',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
},
])
],
true
)
})
it('should handle RSC with fetch in RSC mode', async () => {
await next.fetch(`/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`, {
...env.fetchInit,
headers: {
...env.fetchInit?.headers,
Rsc: '1',
},
})
it('should propagate custom context without span', async () => {
await next.fetch('/app/param/rsc-fetch', {
...env.fetchInit,
headers: { ...env.fetchInit?.headers, 'x-custom': 'custom1' },
})
await expectTrace(getCollector(), [
{
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'RSC GET /app/[param]/rsc-fetch',
attributes: {
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch',
'http.status_code': 200,
'http.target': `/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`,
'next.route': '/app/[param]/rsc-fetch',
'next.rsc': true,
'next.span_name': 'RSC GET /app/[param]/rsc-fetch',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
},
])
})
it('should handle route handlers in app router', async () => {
await next.fetch('/api/app/param/data', env.fetchInit)
await expectTrace(getCollector(), [
{
name: 'GET /api/app/[param]/data',
attributes: {
'http.method': 'GET',
'http.route': '/api/app/[param]/data',
'http.status_code': 200,
'http.target': '/api/app/param/data',
'next.route': '/api/app/[param]/data',
'next.span_name': 'GET /api/app/[param]/data',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'executing api route (app) /api/app/[param]/data',
attributes: {
'next.route': '/api/app/[param]/data',
'next.span_name':
'executing api route (app) /api/app/[param]/data',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/api/app/[param]/data',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle route handlers in app router on edge', async () => {
await next.fetch('/api/app/param/data/edge', env.fetchInit)
await expectTrace(getCollector(), [
await expectTrace(
getCollector(),
[
{
name: 'GET /app/[param]/rsc-fetch',
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'executing api route (app) /api/app/[param]/data/edge',
attributes: {
custom: 'custom1',
'next.route': '/api/app/[param]/data/edge',
'next.span_name':
'executing api route (app) /api/app/[param]/data/edge',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
},
kind: 0,
status: { code: 0 },
},
])
})
],
true
)
})
it('should trace middleware', async () => {
await next.fetch('/behind-middleware', env.fetchInit)
await expectTrace(getCollector(), [
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'middleware GET',
attributes: {
'http.method': 'GET',
'http.target': '/behind-middleware',
'next.span_name': 'middleware GET',
'next.span_type': 'Middleware.execute',
},
status: { code: 0 },
spans: [],
},
{
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /behind-middleware',
attributes: {
'http.method': 'GET',
'http.route': '/behind-middleware',
'http.status_code': 200,
'http.target': '/behind-middleware',
'next.route': '/behind-middleware',
'next.span_name': 'GET /behind-middleware',
'next.span_type': 'BaseServer.handleRequest',
},
},
])
})
it('should handle RSC with fetch on edge', async () => {
await next.fetch('/app/param/rsc-fetch/edge', env.fetchInit)
it('should handle error in RSC', async () => {
await next.fetch(
'/app/param/rsc-fetch/error?status=error',
env.fetchInit
)
await expectTrace(
getCollector(),
[
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch/error',
attributes: {
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch/error',
'http.status_code': 500,
'http.target': '/app/param/rsc-fetch/error?status=error',
'next.route': '/app/[param]/rsc-fetch/error',
'next.rsc': false,
'next.span_name': 'GET /app/[param]/rsc-fetch/error',
'next.span_type': 'BaseServer.handleRequest',
'error.type': '500',
},
kind: 1,
status: { code: 2 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
traceId: env.span.traceId,
parentId: env.span.rootParentId,
runtime: 'edge',
name: 'GET /app/[param]/rsc-fetch/edge',
kind: 1,
name: 'render route (app) /app/[param]/rsc-fetch/error',
attributes: {
'next.span_name': 'GET /app/[param]/rsc-fetch/edge',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/app/param/rsc-fetch/edge?param=param',
'http.status_code': 200,
'next.route': '/app/[param]/rsc-fetch/edge',
'http.route': '/app/[param]/rsc-fetch/edge',
'next.route': '/app/[param]/rsc-fetch/error',
'next.span_name':
'render route (app) /app/[param]/rsc-fetch/error',
'next.span_type': 'AppRender.getBodyResult',
},
status: { code: 0 },
kind: 0,
status: { code: 2 },
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch/edge',
kind: 0,
name: 'build component tree',
attributes: {
'next.span_name':
'render route (app) /app/[param]/rsc-fetch/edge',
'next.span_type': 'AppRender.getBodyResult',
'next.route': '/app/[param]/rsc-fetch/edge',
'next.span_name': 'build component tree',
'next.span_type': 'NextNodeServer.createComponentTree',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'build component tree',
kind: 0,
name: 'resolve segment modules',
attributes: {
'next.span_name': 'build component tree',
'next.segment': '__PAGE__',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.createComponentTree',
},
status: { code: 0 },
spans: [
{
name: 'resolve segment modules',
kind: 0,
attributes: {
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
'next.segment': '__PAGE__',
},
status: { code: 0 },
},
{
name: 'resolve segment modules',
kind: 0,
attributes: {
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
'next.segment': '[param]',
},
status: { code: 0 },
},
],
},
{
name: 'fetch GET https://example.vercel.sh/',
kind: 2,
attributes: {
'next.span_name':
'fetch GET https://example.vercel.sh/',
'next.span_type': 'AppRender.fetch',
'http.url': 'https://example.vercel.sh/',
'http.method': 'GET',
'net.peer.name': 'example.vercel.sh',
'NextNodeServer.getLayoutOrPageModule',
},
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/layout',
kind: 0,
attributes: {
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type':
'ResolveMetadata.generateMetadata',
'next.page': '/app/[param]/layout',
},
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/rsc-fetch/edge/page',
kind: 0,
name: 'resolve segment modules',
attributes: {
'next.span_name':
'generateMetadata /app/[param]/rsc-fetch/edge/page',
'next.segment': '[param]',
'next.span_name': 'resolve segment modules',
'next.span_type':
'ResolveMetadata.generateMetadata',
'next.page': '/app/[param]/rsc-fetch/edge/page',
'NextNodeServer.getLayoutOrPageModule',
},
kind: 0,
status: { code: 0 },
},
],
},
],
},
],
true
)
})
it('should handle RSC with fetch in RSC mode', async () => {
await next.fetch(`/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`, {
...env.fetchInit,
headers: {
...env.fetchInit?.headers,
Rsc: '1',
},
})
await expectTrace(getCollector(), [
{
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'RSC GET /app/[param]/rsc-fetch',
attributes: {
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch',
'http.status_code': 200,
'http.target': `/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`,
'next.route': '/app/[param]/rsc-fetch',
'next.rsc': true,
'next.span_name': 'RSC GET /app/[param]/rsc-fetch',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
},
])
})
it('should handle route handlers in app router', async () => {
await next.fetch('/api/app/param/data', env.fetchInit)
await expectTrace(getCollector(), [
{
name: 'GET /api/app/[param]/data',
attributes: {
'http.method': 'GET',
'http.route': '/api/app/[param]/data',
'http.status_code': 200,
'http.target': '/api/app/param/data',
'next.route': '/api/app/[param]/data',
'next.span_name': 'GET /api/app/[param]/data',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'executing api route (app) /api/app/[param]/data',
attributes: {
'next.route': '/api/app/[param]/data',
'next.span_name':
'executing api route (app) /api/app/[param]/data',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
{
name: 'generateMetadata /app/[param]/layout',
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/api/app/[param]/data',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
{
name: 'generateMetadata /app/[param]/layout',
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
kind: 0,
status: { code: 0 },
},
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
{
attributes: {
'next.clientComponentLoadCount': isNextDev ? 10 : 8,
'next.span_type':
'NextNodeServer.clientComponentLoading',
},
kind: 0,
name: 'NextNodeServer.clientComponentLoading',
status: {
code: 0,
},
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle route handlers in app router on edge', async () => {
await next.fetch('/api/app/param/data/edge', env.fetchInit)
await expectTrace(
getCollector(),
[
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
},
kind: 0,
status: { code: 0 },
},
],
},
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'executing api route (app) /api/app/[param]/data/edge',
name: 'resolve page components',
attributes: {
'next.route': '/api/app/[param]/data/edge',
'next.span_name':
'executing api route (app) /api/app/[param]/data/edge',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
'next.route': '/app/[param]/rsc-fetch/error',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
true
)
})
it('should trace middleware', async () => {
await next.fetch('/behind-middleware', env.fetchInit)
},
])
})
})
await expectTrace(getCollector(), [
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'middleware GET',
attributes: {
'http.method': 'GET',
'http.target': '/behind-middleware',
'next.span_name': 'middleware GET',
'next.span_type': 'Middleware.execute',
},
status: { code: 0 },
spans: [],
},
describe('pages', () => {
it('should handle getServerSideProps', async () => {
await next.fetch('/pages/param/getServerSideProps', env.fetchInit)
{
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /behind-middleware',
attributes: {
'http.method': 'GET',
'http.route': '/behind-middleware',
'http.status_code': 200,
'http.target': '/behind-middleware',
'next.route': '/behind-middleware',
'next.span_name': 'GET /behind-middleware',
'next.span_type': 'BaseServer.handleRequest',
},
await expectTrace(getCollector(), [
{
name: 'GET /pages/[param]/getServerSideProps',
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSideProps',
'http.status_code': 200,
'http.target': '/pages/param/getServerSideProps',
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name': 'GET /pages/[param]/getServerSideProps',
'next.span_type': 'BaseServer.handleRequest',
},
])
})
it('should handle error in RSC', async () => {
await next.fetch(
'/app/param/rsc-fetch/error?status=error',
env.fetchInit
)
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch/error',
attributes: {
'http.method': 'GET',
'http.route': '/app/[param]/rsc-fetch/error',
'http.status_code': 500,
'http.target': '/app/param/rsc-fetch/error?status=error',
'next.route': '/app/[param]/rsc-fetch/error',
'next.rsc': false,
'next.span_name': 'GET /app/[param]/rsc-fetch/error',
'next.span_type': 'BaseServer.handleRequest',
'error.type': '500',
},
kind: 1,
status: { code: 2 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch/error',
attributes: {
'next.route': '/app/[param]/rsc-fetch/error',
'next.span_name':
'render route (app) /app/[param]/rsc-fetch/error',
'next.span_type': 'AppRender.getBodyResult',
},
kind: 0,
status: { code: 2 },
spans: [
{
name: 'build component tree',
attributes: {
'next.span_name': 'build component tree',
'next.span_type':
'NextNodeServer.createComponentTree',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'resolve segment modules',
attributes: {
'next.segment': '__PAGE__',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve segment modules',
attributes: {
'next.segment': '[param]',
'next.span_name': 'resolve segment modules',
'next.span_type':
'NextNodeServer.getLayoutOrPageModule',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'generateMetadata /app/[param]/layout',
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
{
name: 'generateMetadata /app/[param]/layout',
attributes: {
'next.page': '/app/[param]/layout',
'next.span_name':
'generateMetadata /app/[param]/layout',
'next.span_type': 'ResolveMetadata.generateMetadata',
},
kind: 0,
status: { code: 0 },
},
{
attributes: {
'next.clientComponentLoadCount': isNextDev ? 10 : 8,
'next.span_type':
'NextNodeServer.clientComponentLoading',
},
kind: 0,
name: 'NextNodeServer.clientComponentLoading',
status: {
code: 0,
},
},
{
name: 'start response',
attributes: {
'next.span_name': 'start response',
'next.span_type': 'NextNodeServer.startResponse',
},
kind: 0,
status: { code: 0 },
},
],
},
{
name: 'resolve page components',
attributes: {
'next.route': '/app/[param]/rsc-fetch/error',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSideProps',
attributes: {
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSideProps',
'next.span_type': 'Render.getServerSideProps',
},
],
},
])
})
})
describe('pages', () => {
it('should handle getServerSideProps', async () => {
await next.fetch('/pages/param/getServerSideProps', env.fetchInit)
await expectTrace(getCollector(), [
{
name: 'GET /pages/[param]/getServerSideProps',
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSideProps',
'http.status_code': 200,
'http.target': '/pages/param/getServerSideProps',
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name': 'GET /pages/[param]/getServerSideProps',
'next.span_type': 'BaseServer.handleRequest',
kind: 0,
status: { code: 0 },
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSideProps',
attributes: {
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSideProps',
'next.span_type': 'Render.getServerSideProps',
},
kind: 0,
status: { code: 0 },
},
{
name: 'render route (pages) /pages/[param]/getServerSideProps',
attributes: {
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name':
'render route (pages) /pages/[param]/getServerSideProps',
'next.span_type': 'Render.renderDocument',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
{
name: 'render route (pages) /pages/[param]/getServerSideProps',
attributes: {
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name':
'render route (pages) /pages/[param]/getServerSideProps',
'next.span_type': 'Render.renderDocument',
},
],
},
])
})
it("should handle getStaticProps when fallback: 'blocking'", async () => {
const v = env.span.rootParentId ? '2' : ''
await next.fetch(`/pages/param/getStaticProps${v}`, env.fetchInit)
await expectTrace(getCollector(), [
{
name: `GET /pages/[param]/getStaticProps${v}`,
attributes: {
'http.method': 'GET',
'http.route': `/pages/[param]/getStaticProps${v}`,
'http.status_code': 200,
'http.target': `/pages/param/getStaticProps${v}`,
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `GET /pages/[param]/getStaticProps${v}`,
'next.span_type': 'BaseServer.handleRequest',
kind: 0,
status: { code: 0 },
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: `getStaticProps /pages/[param]/getStaticProps${v}`,
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `getStaticProps /pages/[param]/getStaticProps${v}`,
'next.span_type': 'Render.getStaticProps',
},
kind: 0,
status: { code: 0 },
},
{
name: `render route (pages) /pages/[param]/getStaticProps${v}`,
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `render route (pages) /pages/[param]/getStaticProps${v}`,
'next.span_type': 'Render.renderDocument',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle getServerSideProps on edge', async () => {
await next.fetch(
'/pages/param/edge/getServerSideProps',
env.fetchInit
)
await expectTrace(
getCollector(),
[
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /pages/[param]/edge/getServerSideProps',
kind: 1,
name: 'resolve page components',
attributes: {
'next.span_name':
'GET /pages/[param]/edge/getServerSideProps',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target':
'/pages/param/edge/getServerSideProps?param=param',
'http.status_code': 200,
'next.route': '/pages/[param]/edge/getServerSideProps',
'http.route': '/pages/[param]/edge/getServerSideProps',
'next.route': '/pages/[param]/getServerSideProps',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
spans: [
{
name: 'getServerSideProps /pages/[param]/edge/getServerSideProps',
kind: 0,
attributes: {
'next.span_name':
'getServerSideProps /pages/[param]/edge/getServerSideProps',
'next.span_type': 'Render.getServerSideProps',
'next.route': '/pages/[param]/edge/getServerSideProps',
},
status: { code: 0 },
},
{
name: 'render route (pages) /pages/[param]/edge/getServerSideProps',
kind: 0,
attributes: {
'next.span_name':
'render route (pages) /pages/[param]/edge/getServerSideProps',
'next.span_type': 'Render.renderDocument',
'next.route': '/pages/[param]/edge/getServerSideProps',
},
status: { code: 0 },
},
],
},
],
true
)
})
},
])
})
it('should handle getServerSideProps exceptions', async () => {
await next.fetch(
'/pages/param/getServerSidePropsError',
env.fetchInit
)
it("should handle getStaticProps when fallback: 'blocking'", async () => {
const v = env.span.rootParentId ? '2' : ''
await next.fetch(`/pages/param/getStaticProps${v}`, env.fetchInit)
await expectTrace(getCollector(), [
{
name: 'GET /pages/[param]/getServerSidePropsError',
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSidePropsError',
'http.status_code': 500,
'http.target': '/pages/param/getServerSidePropsError',
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name':
'GET /pages/[param]/getServerSidePropsError',
'next.span_type': 'BaseServer.handleRequest',
'error.type': '500',
},
kind: 1,
status: { code: 2 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSidePropsError',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSidePropsError',
'next.span_type': 'Render.getServerSideProps',
'error.type': 'Error',
},
kind: 0,
status: {
code: 2,
message: 'ServerSideProps error',
},
events: [
{
name: 'exception',
attributes: {
'exception.type': 'Error',
'exception.message': 'ServerSideProps error',
},
},
],
},
{
name: 'render route (pages) /_error',
attributes: {
'next.route': '/_error',
'next.span_name': 'render route (pages) /_error',
'next.span_type': 'Render.renderDocument',
},
kind: 0,
status: { code: 0 },
await expectTrace(getCollector(), [
{
name: `GET /pages/[param]/getStaticProps${v}`,
attributes: {
'http.method': 'GET',
'http.route': `/pages/[param]/getStaticProps${v}`,
'http.status_code': 200,
'http.target': `/pages/param/getStaticProps${v}`,
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `GET /pages/[param]/getStaticProps${v}`,
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: `getStaticProps /pages/[param]/getStaticProps${v}`,
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `getStaticProps /pages/[param]/getStaticProps${v}`,
'next.span_type': 'Render.getStaticProps',
},
{
name: 'resolve page components',
attributes: {
'next.route': '/_error',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
kind: 0,
status: { code: 0 },
},
{
name: `render route (pages) /pages/[param]/getStaticProps${v}`,
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': `render route (pages) /pages/[param]/getStaticProps${v}`,
'next.span_type': 'Render.renderDocument',
},
...(isNextDev
? []
: [
{
name: 'resolve page components',
attributes: {
'next.route': '/500',
'next.span_name': 'resolve page components',
'next.span_type':
'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/500',
'next.span_name': 'resolve page components',
'next.span_type':
'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
]),
{
name: 'resolve page components',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': `/pages/[param]/getStaticProps${v}`,
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
],
},
])
})
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle getServerSideProps returning notFound', async () => {
await next.fetch(
'/pages/param/getServerSidePropsNotFound',
env.fetchInit
)
it('should handle getServerSideProps on edge', async () => {
await next.fetch(
'/pages/param/edge/getServerSideProps',
env.fetchInit
)
await expectTrace(getCollector(), [
await expectTrace(
getCollector(),
[
{
name: 'GET /pages/[param]/getServerSidePropsNotFound',
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /pages/[param]/edge/getServerSideProps',
kind: 1,
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSidePropsNotFound',
'http.status_code': 404,
'http.target': '/pages/param/getServerSidePropsNotFound',
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name':
'GET /pages/[param]/getServerSidePropsNotFound',
'GET /pages/[param]/edge/getServerSideProps',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target':
'/pages/param/edge/getServerSideProps?param=param',
'http.status_code': 200,
'next.route': '/pages/[param]/edge/getServerSideProps',
'http.route': '/pages/[param]/edge/getServerSideProps',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSidePropsNotFound',
name: 'getServerSideProps /pages/[param]/edge/getServerSideProps',
kind: 0,
attributes: {
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSidePropsNotFound',
'getServerSideProps /pages/[param]/edge/getServerSideProps',
'next.span_type': 'Render.getServerSideProps',
'next.route': '/pages/[param]/edge/getServerSideProps',
},
kind: 0,
status: {
code: 0,
},
},
...(isNextDev
? [
{
name: 'render route (app) /_not-found',
attributes: {
'next.route': '/_not-found',
'next.span_name': 'render route (app) /_not-found',
'next.span_type': 'AppRender.getBodyResult',
},
kind: 0,
status: { code: 0 },
},
]
: []),
{
name: 'resolve page components',
attributes: {
'next.route': '/_not-found',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
name: 'render route (pages) /pages/[param]/edge/getServerSideProps',
kind: 0,
attributes: {
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
'next.span_name':
'render route (pages) /pages/[param]/edge/getServerSideProps',
'next.span_type': 'Render.renderDocument',
'next.route': '/pages/[param]/edge/getServerSideProps',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
],
true
)
})
it('should handle api routes in pages', async () => {
await next.fetch('/api/pages/param/basic', env.fetchInit)
it('should handle getServerSideProps exceptions', async () => {
await next.fetch(
'/pages/param/getServerSidePropsError',
env.fetchInit
)
await expectTrace(getCollector(), [
{
name: 'GET /api/pages/[param]/basic',
attributes: {
'http.method': 'GET',
'http.route': '/api/pages/[param]/basic',
'http.status_code': 200,
'http.target': '/api/pages/param/basic',
'next.route': '/api/pages/[param]/basic',
'next.span_name': 'GET /api/pages/[param]/basic',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'executing api route (pages) /api/pages/[param]/basic',
attributes: {
'next.span_name':
'executing api route (pages) /api/pages/[param]/basic',
'next.span_type': 'Node.runHandler',
await expectTrace(getCollector(), [
{
name: 'GET /pages/[param]/getServerSidePropsError',
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSidePropsError',
'http.status_code': 500,
'http.target': '/pages/param/getServerSidePropsError',
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name': 'GET /pages/[param]/getServerSidePropsError',
'next.span_type': 'BaseServer.handleRequest',
'error.type': '500',
},
kind: 1,
status: { code: 2 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSidePropsError',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSidePropsError',
'next.span_type': 'Render.getServerSideProps',
'error.type': 'Error',
},
kind: 0,
status: {
code: 2,
message: 'ServerSideProps error',
},
events: [
{
name: 'exception',
attributes: {
'exception.type': 'Error',
'exception.message': 'ServerSideProps error',
},
},
kind: 0,
status: { code: 0 },
],
},
{
name: 'render route (pages) /_error',
attributes: {
'next.route': '/_error',
'next.span_name': 'render route (pages) /_error',
'next.span_type': 'Render.renderDocument',
},
],
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/_error',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
...(isNextDev
? []
: [
{
name: 'resolve page components',
attributes: {
'next.route': '/500',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/500',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
]),
{
name: 'resolve page components',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle getServerSideProps returning notFound', async () => {
await next.fetch(
'/pages/param/getServerSidePropsNotFound',
env.fetchInit
)
await expectTrace(getCollector(), [
{
name: 'GET /pages/[param]/getServerSidePropsNotFound',
attributes: {
'http.method': 'GET',
'http.route': '/pages/[param]/getServerSidePropsNotFound',
'http.status_code': 404,
'http.target': '/pages/param/getServerSidePropsNotFound',
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name':
'GET /pages/[param]/getServerSidePropsNotFound',
'next.span_type': 'BaseServer.handleRequest',
},
])
})
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
name: 'getServerSideProps /pages/[param]/getServerSidePropsNotFound',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name':
'getServerSideProps /pages/[param]/getServerSidePropsNotFound',
'next.span_type': 'Render.getServerSideProps',
},
kind: 0,
status: {
code: 0,
},
},
...(isNextDev
? [
{
name: 'render route (app) /_not-found',
attributes: {
'next.route': '/_not-found',
'next.span_name': 'render route (app) /_not-found',
'next.span_type': 'AppRender.getBodyResult',
},
kind: 0,
status: { code: 0 },
},
]
: []),
{
name: 'resolve page components',
attributes: {
'next.route': '/_not-found',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
{
name: 'resolve page components',
attributes: {
'next.route': '/pages/[param]/getServerSidePropsNotFound',
'next.span_name': 'resolve page components',
'next.span_type': 'NextNodeServer.findPageComponents',
},
kind: 0,
status: { code: 0 },
},
],
},
])
})
it('should handle api routes in pages on edge', async () => {
await next.fetch('/api/pages/param/edge', env.fetchInit)
it('should handle api routes in pages', async () => {
await next.fetch('/api/pages/param/basic', env.fetchInit)
await expectTrace(
getCollector(),
[
await expectTrace(getCollector(), [
{
name: 'GET /api/pages/[param]/basic',
attributes: {
'http.method': 'GET',
'http.route': '/api/pages/[param]/basic',
'http.status_code': 200,
'http.target': '/api/pages/param/basic',
'next.route': '/api/pages/[param]/basic',
'next.span_name': 'GET /api/pages/[param]/basic',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
status: { code: 0 },
traceId: env.span.traceId,
parentId: env.span.rootParentId,
spans: [
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'executing api route (pages) /api/pages/[param]/edge',
name: 'executing api route (pages) /api/pages/[param]/basic',
attributes: {
'next.span_name':
'executing api route (pages) /api/pages/[param]/edge',
'executing api route (pages) /api/pages/[param]/basic',
'next.span_type': 'Node.runHandler',
},
kind: 0,
status: { code: 0 },
},
],
true
)
})
},
])
})
}
)
it('should handle api routes in pages on edge', async () => {
await next.fetch('/api/pages/param/edge', env.fetchInit)
await expectTrace(
getCollector(),
[
{
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'executing api route (pages) /api/pages/[param]/edge',
attributes: {
'next.span_name':
'executing api route (pages) /api/pages/[param]/edge',
'next.span_type': 'Node.runHandler',
},
kind: 0,
status: { code: 0 },
},
],
true
)
})
})
})
}
})
......@@ -1065,57 +1057,56 @@ describe('opentelemetry with disabled fetch tracing', () => {
await collector.shutdown()
await new Promise((r) => setTimeout(r, 1000))
})
;(process.env.__NEXT_EXPERIMENTAL_PPR ? describe.skip : describe)(
'root context',
() => {
describe('app router with disabled fetch', () => {
it('should handle RSC with disabled fetch', async () => {
await next.fetch('/app/param/rsc-fetch')
;(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS
? describe.skip
: describe)('root context', () => {
describe('app router with disabled fetch', () => {
it('should handle RSC with disabled fetch', async () => {
await next.fetch('/app/param/rsc-fetch')
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch',
traceId: '[trace-id]',
parentId: undefined,
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch',
spans: [
{
name: 'build component tree',
spans: [
{
name: 'resolve segment modules',
},
{
name: 'resolve segment modules',
},
],
},
{
name: 'generateMetadata /app/[param]/layout',
},
{
name: 'generateMetadata /app/[param]/rsc-fetch/page',
},
{
name: 'NextNodeServer.clientComponentLoading',
},
{
name: 'start response',
},
],
},
{
name: 'resolve page components',
},
],
},
])
})
await expectTrace(getCollector(), [
{
name: 'GET /app/[param]/rsc-fetch',
traceId: '[trace-id]',
parentId: undefined,
spans: [
{
name: 'render route (app) /app/[param]/rsc-fetch',
spans: [
{
name: 'build component tree',
spans: [
{
name: 'resolve segment modules',
},
{
name: 'resolve segment modules',
},
],
},
{
name: 'generateMetadata /app/[param]/layout',
},
{
name: 'generateMetadata /app/[param]/rsc-fetch/page',
},
{
name: 'NextNodeServer.clientComponentLoading',
},
{
name: 'start response',
},
],
},
{
name: 'resolve page components',
},
],
},
])
})
}
)
})
})
})
type HierSavedSpan = SavedSpan & { spans?: HierSavedSpan[] }
......
......@@ -143,7 +143,8 @@ describe('Config Experimental Warning', () => {
expect(stdout).toMatch(' · cpus: 2')
})
it('should show the configured value for string features', async () => {
// TODO: the incremental option has been removed, update to another string feature
it.skip('should show the configured value for string features', async () => {
configFile.write(`
module.exports = {
experimental: {
......
......@@ -403,9 +403,6 @@ export class NextInstance {
}
// alias experimental feature flags for deployment compatibility
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_PPR) {
process.env.__NEXT_EXPERIMENTAL_PPR = process.env.NEXT_PRIVATE_EXPERIMENTAL_PPR
}
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS) {
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS
}
......
......@@ -99,11 +99,6 @@ export class NextDeployInstance extends NextInstance {
)
// Add experimental feature flags
if (process.env.__NEXT_EXPERIMENTAL_PPR) {
additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_PPR=${process.env.__NEXT_EXPERIMENTAL_PPR}`
)
}
if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS) {
additionalEnv.push(
......
process.env.TEST_CACHE_COMPONENTS = '1'
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('adapter-config-cache-components', () => {
require('./adapter-config.test')
})
process.env.TEST_PPR = '1'
require('./adapter-config.test')
......@@ -5,7 +5,7 @@ const require = Module.createRequire(import.meta.url)
const nextConfig = {
experimental: {
adapterPath: require.resolve('./my-adapter.mjs'),
ppr: Boolean(process.env.TEST_PPR),
cacheComponents: process.env.TEST_CACHE_COMPONENTS === '1',
},
output: process.env.TEST_EXPORT ? 'export' : undefined,
}
......
......@@ -26,9 +26,8 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (Turbopack)
- Experiments (use with caution):
✓ cacheComponents
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`)
......@@ -37,9 +36,8 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (webpack)
- Experiments (use with caution):
✓ cacheComponents
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`)
......@@ -73,8 +71,7 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)"
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)"
`)
} else if (isRspack) {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
......@@ -82,8 +79,7 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)"
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)"
`)
} else {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
......@@ -91,8 +87,7 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)"
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)"
`)
}
}
......@@ -147,9 +142,8 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (Turbopack)
- Experiments (use with caution):
✓ cacheComponents
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
......@@ -162,9 +156,8 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (webpack)
- Experiments (use with caution):
✓ cacheComponents
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
......@@ -210,9 +203,8 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
⨯ turbopackMinify (disabled by \`--debug-prerender\`)"
`)
......@@ -223,9 +215,8 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
`)
......@@ -236,9 +227,8 @@ describe('build-output-prerender', () => {
- Experiments (use with caution):
✓ cacheComponents
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`experimental.cacheComponents\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`experimental.ppr\`)
✓ rdcForNavigations (enabled by \`experimental.cacheComponents\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
`)
......@@ -293,9 +283,8 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (Turbopack)
- Experiments (use with caution):
✓ cacheComponents (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`)
......@@ -304,9 +293,8 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (webpack)
- Experiments (use with caution):
✓ cacheComponents (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`experimental.cacheComponents\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`)
......@@ -364,9 +352,8 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (Turbopack)
- Experiments (use with caution):
✓ cacheComponents (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
......@@ -379,9 +366,8 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (webpack)
- Experiments (use with caution):
✓ cacheComponents (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
✓ clientParamParsing (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ enablePrerenderSourceMaps (enabled by \`--debug-prerender\`)
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ rdcForNavigations (enabled by \`__NEXT_EXPERIMENTAL_CACHE_COMPONENTS\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
......
......@@ -2,7 +2,8 @@ import { nextTestSetup } from 'e2e-utils'
import path from 'path'
describe('build-output-tree-view', () => {
describe('with mixed static and dynamic pages and app router routes', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('with mixed static and dynamic pages and app router routes', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures/mixed'),
skipStart: true,
......
......@@ -4,7 +4,7 @@
const nextConfig = {
experimental: {
useCache: true,
ppr: true,
cacheComponents: true,
},
}
......
......@@ -10,7 +10,8 @@ describe('empty-generate-static-params', () => {
if (skipped) return
it('should mark the page with empty generateStaticParams as SSG in build output', async () => {
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabled =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
expect(next.cliOutput).toContain(`${isPPREnabled ? '◐' : '●'} /[slug]`)
})
......@@ -19,7 +20,8 @@ describe('empty-generate-static-params', () => {
expect(firstResponse.status).toBe(200)
// With PPR enabled, the initial request doesn't send back a cache header
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isPPREnabled =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
expect(firstResponse.headers.get('x-nextjs-cache')).toBe(
isPPREnabled ? null : 'MISS'
......
import { nextTestSetup } from 'e2e-utils'
describe('app-dir - metadata-streaming-config-customized', () => {
// TODO: the incremental option has been removed, update to use cacheComponents
describe.skip('app-dir - metadata-streaming-config-customized', () => {
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
......
import { nextTestSetup } from 'e2e-utils'
describe('app-dir - metadata-streaming-config', () => {
// TODO: the incremental option has been removed, update to use cacheComponents
describe.skip('app-dir - metadata-streaming-config', () => {
const { next } = nextTestSetup({
files: __dirname,
})
......
......@@ -6,7 +6,7 @@ describe('app-dir parallel-routes-static', () => {
})
it('should static generate parallel routes', async () => {
const rscExtension = process.env.__NEXT_EXPERIMENTAL_PPR
const rscExtension = process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS
? '.prefetch.rsc'
: '.rsc'
expect(await next.hasFile('.next/server/app/nested/foo.html')).toBe(true)
......
......@@ -3,7 +3,7 @@
*/
const nextConfig = {
experimental: {
ppr: true,
cacheComponents: true,
},
}
......
......@@ -226,7 +226,10 @@ import cheerio from 'cheerio'
`script-src 'nonce-"><script></script>"'`
)
if (runtime === 'node' && process.env.__NEXT_EXPERIMENTAL_PPR) {
if (
runtime === 'node' &&
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS
) {
expect(res.status).toBe(200)
} else {
expect(res.status).toBe(500)
......
......@@ -13,7 +13,8 @@ import {
} from 'next-test-utils'
import { ChildProcess } from 'node:child_process'
describe('required server files app router', () => {
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('required server files app router', () => {
let next: NextInstance
let server: ChildProcess
let appPort: number | string
......@@ -55,7 +56,7 @@ describe('required server files app router', () => {
nextConfig: {
cacheHandler: './cache-handler.js',
experimental: {
ppr: true,
cacheComponents: true,
clientSegmentCache: true,
clientParamParsing: true,
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment