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: ...@@ -700,7 +700,6 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
afterBuild: | afterBuild: |
export __NEXT_EXPERIMENTAL_PPR=true # for compatibility with the existing tests
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
"test-storybook": "turbo run test-storybook", "test-storybook": "turbo run test-storybook",
"with-rspack": "cross-env NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1", "with-rspack": "cross-env NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1",
"with-webpack": "cross-env IS_WEBPACK_TEST=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": { "devDependencies": {
"@actions/core": "1.10.1", "@actions/core": "1.10.1",
......
...@@ -862,5 +862,6 @@ ...@@ -862,5 +862,6 @@
"861": "Client Max Body Size must be larger than 0 bytes", "861": "Client Max Body Size must be larger than 0 bytes",
"862": "Request body exceeded %s", "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.", "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' ...@@ -13,7 +13,7 @@ import type { SizeLimit } from '../types'
import type { SupportedTestRunners } from '../cli/next-test' import type { SupportedTestRunners } from '../cli/next-test'
import type { ExperimentalPPRConfig } from './lib/experimental/ppr' import type { ExperimentalPPRConfig } from './lib/experimental/ppr'
import { INFINITE_CACHE } from '../lib/constants' 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' import type { FallbackRouteParam } from '../build/static-paths/types'
export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & { export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & {
...@@ -573,8 +573,8 @@ export interface ExperimentalConfig { ...@@ -573,8 +573,8 @@ export interface ExperimentalConfig {
clientTraceMetadata?: string[] clientTraceMetadata?: string[]
/** /**
* Enables experimental Partial Prerendering feature of Next.js. * @deprecated This configuration option has been merged into `experimental.cacheComponents`.
* Using this feature will enable the `react@experimental` for the `app` directory. * The Partial Prerendering feature is still available via `experimental.cacheComponents`.
*/ */
ppr?: ExperimentalPPRConfig ppr?: ExperimentalPPRConfig
......
...@@ -86,13 +86,13 @@ describe('loadConfig', () => { ...@@ -86,13 +86,13 @@ describe('loadConfig', () => {
const loadConfigPromise = loadConfig(PHASE_PRODUCTION_BUILD, __dirname, { const loadConfigPromise = loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: { customConfig: {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
}, },
}) })
await expect(loadConfigPromise).rejects.toThrow( 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 { try {
...@@ -115,7 +115,7 @@ describe('loadConfig', () => { ...@@ -115,7 +115,7 @@ describe('loadConfig', () => {
}, },
}) })
).rejects.toThrow( ).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', () => { ...@@ -157,41 +157,40 @@ describe('loadConfig', () => {
delete process.env.__NEXT_VERSION 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( await expect(
loadConfig(PHASE_PRODUCTION_BUILD, __dirname, { loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: { customConfig: {
experimental: { experimental: {
cacheComponents: true, rdcForNavigations: true,
ppr: false, ppr: false,
}, },
}, },
}) })
).rejects.toThrow( ).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( await expect(
loadConfig(PHASE_PRODUCTION_BUILD, __dirname, { loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: { customConfig: {
experimental: { experimental: {
rdcForNavigations: true, ppr: 'incremental',
ppr: false,
}, },
}, },
}) })
).rejects.toThrow( ).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, { const result = await loadConfig(PHASE_PRODUCTION_BUILD, __dirname, {
customConfig: { customConfig: {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
}, },
}) })
...@@ -199,34 +198,6 @@ describe('loadConfig', () => { ...@@ -199,34 +198,6 @@ describe('loadConfig', () => {
expect(result.experimental.rdcForNavigations).toBe(true) 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 () => { it('migrates experimental.dynamicIO to experimental.cacheComponents', async () => {
process.env.__NEXT_VERSION = 'canary' process.env.__NEXT_VERSION = 'canary'
......
...@@ -38,10 +38,14 @@ import { dset } from '../shared/lib/dset' ...@@ -38,10 +38,14 @@ import { dset } from '../shared/lib/dset'
import { normalizeZodErrors } from '../shared/lib/zod' import { normalizeZodErrors } from '../shared/lib/zod'
import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot' import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot'
import { findDir } from '../lib/find-pages-dir' 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 { interopDefault } from '../lib/interop-default'
import { djb2Hash } from '../shared/lib/hash' import { djb2Hash } from '../shared/lib/hash'
import type { NextAdapter } from '../build/adapter/build-complete' import type { NextAdapter } from '../build/adapter/build-complete'
import { HardDeprecatedConfigError } from '../shared/lib/errors/hard-deprecated-config-error'
export { normalizeConfig } from './config-shared' export { normalizeConfig } from './config-shared'
export type { DomainLocale, NextConfig } from './config-shared' export type { DomainLocale, NextConfig } from './config-shared'
...@@ -365,17 +369,23 @@ function assignDefaultsAndValidate( ...@@ -365,17 +369,23 @@ function assignDefaultsAndValidate(
if (isStableBuild()) { if (isStableBuild()) {
// Prevents usage of certain experimental features outside of canary // Prevents usage of certain experimental features outside of canary
if (result.experimental?.ppr) { if (result.experimental?.cacheComponents) {
throw new CanaryOnlyError({ feature: 'experimental.ppr' }) throw new CanaryOnlyConfigError({
} else if (result.experimental?.cacheComponents) { feature: 'experimental.cacheComponents',
throw new CanaryOnlyError({ feature: 'experimental.cacheComponents' }) })
} else if (result.experimental?.turbopackFileSystemCacheForBuild) { } else if (result.experimental?.turbopackFileSystemCacheForBuild) {
throw new CanaryOnlyError({ throw new CanaryOnlyConfigError({
feature: 'experimental.turbopackFileSystemCacheForBuild', 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.output === 'export') {
if (result.i18n) { if (result.i18n) {
throw new Error( throw new Error(
...@@ -1178,6 +1188,11 @@ function assignDefaultsAndValidate( ...@@ -1178,6 +1188,11 @@ function assignDefaultsAndValidate(
result.experimental.mcpServer = true 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 // "use cache" was originally implicitly enabled with the cacheComponents flag, so
// we transfer the value for cacheComponents to the explicit useCache flag to ensure // we transfer the value for cacheComponents to the explicit useCache flag to ensure
// backwards compatibility. // backwards compatibility.
...@@ -1185,39 +1200,10 @@ function assignDefaultsAndValidate( ...@@ -1185,39 +1200,10 @@ function assignDefaultsAndValidate(
result.experimental.useCache = result.experimental.cacheComponents result.experimental.useCache = result.experimental.cacheComponents
} }
// If cacheComponents is enabled, we also enable PPR. // If cacheComponents is enabled and the user hasn't configured
if (result.experimental.cacheComponents) { // rdcForNavigations, we enable it by default.
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 ( if (
configuredExperimentalFeatures && result.experimental.cacheComponents &&
// 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 (
result.experimental.ppr &&
userConfig.experimental?.rdcForNavigations === undefined userConfig.experimental?.rdcForNavigations === undefined
) { ) {
result.experimental.rdcForNavigations = true result.experimental.rdcForNavigations = true
...@@ -1227,15 +1213,18 @@ function assignDefaultsAndValidate( ...@@ -1227,15 +1213,18 @@ function assignDefaultsAndValidate(
configuredExperimentalFeatures, configuredExperimentalFeatures,
'rdcForNavigations', 'rdcForNavigations',
true, true,
'enabled by `experimental.ppr`' 'enabled by `experimental.cacheComponents`'
) )
} }
} }
// If rdcForNavigations is enabled, but ppr is not, we throw an error. // If rdcForNavigations is enabled, but cacheComponents is not, we throw an error.
if (result.experimental.rdcForNavigations && !result.experimental.ppr) { if (
result.experimental.rdcForNavigations &&
!result.experimental.cacheComponents
) {
throw new Error( 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( ...@@ -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. // TODO: Remove this once we've made Client Param Parsing the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' && process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
(config.experimental.clientParamParsing === undefined || (config.experimental.clientParamParsing === undefined ||
(isDefaultConfig && !config.experimental.clientParamParsing)) (isDefaultConfig && !config.experimental.clientParamParsing))
...@@ -1766,7 +1717,7 @@ function enforceExperimentalFeatures( ...@@ -1766,7 +1717,7 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures, configuredExperimentalFeatures,
'clientParamParsing', 'clientParamParsing',
true, true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`' 'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
) )
} }
} }
...@@ -1790,7 +1741,7 @@ function enforceExperimentalFeatures( ...@@ -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 ( if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' && process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
...@@ -1828,25 +1779,6 @@ function enforceExperimentalFeatures( ...@@ -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 ( if (
process.env.__NEXT_ENABLE_REACT_COMPILER === 'true' && process.env.__NEXT_ENABLE_REACT_COMPILER === 'true' &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
......
...@@ -6,7 +6,7 @@ export function isStableBuild() { ...@@ -6,7 +6,7 @@ export function isStableBuild() {
) )
} }
export class CanaryOnlyError extends Error { export class CanaryOnlyConfigError extends Error {
constructor(arg: { feature: string } | string) { constructor(arg: { feature: string } | string) {
if (typeof arg === 'object' && 'feature' in arg) { if (typeof arg === 'object' && 'feature' in arg) {
super( 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 { ...@@ -9,7 +9,7 @@ import {
retry, retry,
} from 'next-test-utils' } 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', () => { describe('Error overlay for hydration errors in App router', () => {
const { next, isTurbopack } = nextTestSetup({ const { next, isTurbopack } = nextTestSetup({
......
...@@ -15,7 +15,7 @@ const nextConfig = { ...@@ -15,7 +15,7 @@ const nextConfig = {
} }
}, },
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -4,7 +4,8 @@ import { retry } from 'next-test-utils' ...@@ -4,7 +4,8 @@ import { retry } from 'next-test-utils'
const isCacheComponentsEnabled = const isCacheComponentsEnabled =
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
describe('source-mapping', () => { // TODO(NAR-423): Migrate to Cache Components.
describe.skip('source-mapping', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
...@@ -40,7 +40,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -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 () => { it('should respond correctly for dynamic route with dynamicParams false in layout', async () => {
const res = await next.fetch('/partial-params-false/en/another') const res = await next.fetch('/partial-params-false/en/another')
expect(res.status).toBe(200) expect(res.status).toBe(200)
...@@ -783,7 +783,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -783,7 +783,7 @@ describe('app-dir static/dynamic handling', () => {
if (isNextStart) { if (isNextStart) {
it('should not encode dynamic parameters as search parameters in RSC data', async () => { 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.prefetch.rsc')
: await next.readFile('.next/server/app/blog/seb.rsc') : await next.readFile('.next/server/app/blog/seb.rsc')
...@@ -3307,7 +3307,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -3307,7 +3307,7 @@ describe('app-dir static/dynamic handling', () => {
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
const res = await next.fetch('/articles/non-existent') 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) expect(res.status).toBe(200)
} else { } else {
expect(res.status).toBe(404) expect(res.status).toBe(404)
...@@ -3522,7 +3522,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -3522,7 +3522,7 @@ describe('app-dir static/dynamic handling', () => {
}) })
} else { } else {
// TODO: re-implement this in a way that'll support PFPR // 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 () => { it('should not error with dynamic server usage with force-static', async () => {
const res = await next.fetch( const res = await next.fetch(
'/static-to-dynamic-error-forced/static-bailout-1' '/static-to-dynamic-error-forced/static-bailout-1'
...@@ -3563,7 +3563,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -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 () => { it('should properly error when dynamic = "error" page uses dynamic', async () => {
const res = await next.fetch('/dynamic-error/static-bailout-1') const res = await next.fetch('/dynamic-error/static-bailout-1')
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
...@@ -4460,7 +4460,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -4460,7 +4460,7 @@ describe('app-dir static/dynamic handling', () => {
expect(html).toInclude('"noindex"') expect(html).toInclude('"noindex"')
expect(html).toInclude('This page could not be found.') 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) expect(res.status).toBe(200)
} else { } else {
expect(res.status).toBe(404) expect(res.status).toBe(404)
......
...@@ -5,7 +5,7 @@ export const dynamic = 'error' ...@@ -5,7 +5,7 @@ export const dynamic = 'error'
export default async function Page(props) { export default async function Page(props) {
const params = await props.params const params = await props.params
// When PPR is enabled, we will bailout on parameter access. // 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')) { if (params.id.includes('static-bailout')) {
console.log('calling cookies', await cookies()) console.log('calling cookies', await cookies())
} }
......
...@@ -7,11 +7,6 @@ import { ...@@ -7,11 +7,6 @@ import {
RSC_HEADER, RSC_HEADER,
} from 'next/dist/client/components/app-router-headers' } 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', () => { describe('app dir - basic', () => {
const { next, isNextDev, isNextStart, isNextDeploy } = nextTestSetup({ const { next, isNextDev, isNextStart, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
...@@ -592,7 +587,7 @@ describe('app dir - basic', () => { ...@@ -592,7 +587,7 @@ describe('app dir - basic', () => {
;(isNextDev || ;(isNextDev ||
// When PPR is enabled, the shared layouts re-render because we prefetch // When PPR is enabled, the shared layouts re-render because we prefetch
// from the root. This will be addressed before GA. // from the root. This will be addressed before GA.
isPPREnabledByDefault process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? it.skip ? it.skip
: it)( : it)(
'should not rerender layout when navigating between routes in the same layout', 'should not rerender layout when navigating between routes in the same layout',
...@@ -1389,7 +1384,7 @@ describe('app dir - basic', () => { ...@@ -1389,7 +1384,7 @@ describe('app dir - basic', () => {
;(isNextDev || ;(isNextDev ||
// When PPR is enabled, the shared layouts re-render because we prefetch // When PPR is enabled, the shared layouts re-render because we prefetch
// from the root. This will be addressed before GA. // from the root. This will be addressed before GA.
isPPREnabledByDefault process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? it.skip ? it.skip
: it)( : it)(
'should render the template that is a server component and rerender on navigation', 'should render the template that is a server component and rerender on navigation',
......
...@@ -25,7 +25,7 @@ describe('custom-cache-control', () => { ...@@ -25,7 +25,7 @@ describe('custom-cache-control', () => {
isNextDev ? 'no-store, must-revalidate' : 's-maxage=31' 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', 'should have default cache-control for app-ssg another',
async () => { async () => {
const res = await next.fetch('/app-ssg/another') const res = await next.fetch('/app-ssg/another')
......
...@@ -27,7 +27,7 @@ describe('dynamic-data', () => { ...@@ -27,7 +27,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime // in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('#page').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 // 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($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
...@@ -57,7 +57,7 @@ describe('dynamic-data', () => { ...@@ -57,7 +57,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime // in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('#page').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 // @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 // see note in create-component-tree
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
...@@ -88,7 +88,7 @@ describe('dynamic-data', () => { ...@@ -88,7 +88,7 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime // in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('#page').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 // 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($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime') expect($('#page').text()).toBe('at buildtime')
...@@ -124,7 +124,7 @@ describe('dynamic-data', () => { ...@@ -124,7 +124,7 @@ describe('dynamic-data', () => {
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
// we don't assert the state of the fallback because it can depend on the timing // 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 // 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 // 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($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
......
import { nextTestSetup } from 'e2e-utils' 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)( ;(isPPREnabled ? describe.skip : describe)(
'app-dir - metadata-static-generation', 'app-dir - metadata-static-generation',
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-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 // Skip PPR test as it's covered in test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts
;(isPPREnabled ? describe.skip : describe)( ;(isPPREnabled ? describe.skip : describe)(
......
...@@ -46,7 +46,7 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -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 // despite the page being static, the first two requests both cause a render
// and only the second one gets cached and re-used. // 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. // 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) await getTimestampPageData(path)
} }
......
import { nextTestSetup } from 'e2e-utils' 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', () => { describe('app dir - not-found - default', () => {
const { next, isNextStart } = nextTestSetup({ const { next, isNextStart } = nextTestSetup({
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
prerenderEarlyExit: false, prerenderEarlyExit: false,
}, },
} }
......
...@@ -2,7 +2,8 @@ import { nextBuild } from 'next-test-utils' ...@@ -2,7 +2,8 @@ import { nextBuild } from 'next-test-utils'
// In order for the global isNextStart to be set // In order for the global isNextStart to be set
import 'e2e-utils' 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)( ;(Boolean((global as any).isNextStart) ? describe : describe.skip)(
'production only', 'production only',
() => { () => {
......
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -82,7 +82,8 @@ const expectDirectives = (header: string, directives: string[]) => { ...@@ -82,7 +82,8 @@ const expectDirectives = (header: string, directives: string[]) => {
expect(split.length).toEqual(directives.length) 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({ const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { 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 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -4,7 +4,8 @@ function countSubstring(str: string, substr: string): number { ...@@ -4,7 +4,8 @@ function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1 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({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
// Need to skip deployment because the test uses the private env cannot be used in deployment // Need to skip deployment because the test uses the private env cannot be used in deployment
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
useCache: true, useCache: true,
}, },
} }
......
...@@ -6,7 +6,8 @@ function countSubstring(str: string, substr: string): number { ...@@ -6,7 +6,8 @@ function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1 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({ const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { expectedParams as expected } from './expected' 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({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { 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 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('prefetch-navigation', () => { // TODO(NAR-423): Migrate to Cache Components.
describe.skip('prefetch-navigation', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
import { createNext } from 'e2e-utils' import { createNext } from 'e2e-utils'
describe('search-params', () => { // TODO(NAR-423): Migrate to Cache Components.
describe.skip('search-params', () => {
if ((global as any).isNextDev) { if ((global as any).isNextDev) {
test('ppr is disabled in dev', () => {}) test('ppr is disabled in dev', () => {})
return return
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -2,9 +2,7 @@ import type { NextConfig } from 'next' ...@@ -2,9 +2,7 @@ import type { NextConfig } from 'next'
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
// until the flags are merged, test both `ppr` and `cacheComponents`
// cacheComponents: true,
}, },
} }
......
module.exports = { module.exports = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -2,7 +2,8 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,7 +2,8 @@ import { nextTestSetup } from 'e2e-utils'
import { retry, findAllTelemetryEvents } from 'next-test-utils' import { retry, findAllTelemetryEvents } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('ppr', () => { // TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr', () => {
const { next, isNextDev, isNextStart } = nextTestSetup({ const { next, isNextDev, isNextStart } = nextTestSetup({
files: __dirname, files: __dirname,
env: { env: {
......
...@@ -7,7 +7,7 @@ const nextConfig = { ...@@ -7,7 +7,7 @@ const nextConfig = {
: undefined, : undefined,
experimental: { experimental: {
// Emitting Link headers currently requires the experimental PPR feature. // Emitting Link headers currently requires the experimental PPR feature.
ppr: true, cacheComponents: true,
}, },
} }
......
...@@ -42,7 +42,7 @@ const cases: { ...@@ -42,7 +42,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -78,7 +78,7 @@ const cases: { ...@@ -78,7 +78,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -114,7 +114,7 @@ const cases: { ...@@ -114,7 +114,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -151,7 +151,7 @@ const cases: { ...@@ -151,7 +151,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -187,7 +187,7 @@ const cases: { ...@@ -187,7 +187,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -223,7 +223,7 @@ const cases: { ...@@ -223,7 +223,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -259,7 +259,7 @@ const cases: { ...@@ -259,7 +259,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -295,7 +295,7 @@ const cases: { ...@@ -295,7 +295,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -339,7 +339,7 @@ const cases: { ...@@ -339,7 +339,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
...@@ -442,7 +442,7 @@ const cases: { ...@@ -442,7 +442,7 @@ const cases: {
headers: { headers: {
rsc: '1', rsc: '1',
'next-router-prefetch': '1', 'next-router-prefetch': '1',
...(process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ...(process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? { ? {
'next-router-segment-prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
} }
......
...@@ -10,7 +10,8 @@ import { ...@@ -10,7 +10,8 @@ import {
// TODO: We should decide on an established pattern for gating test assertions // 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 // on experimental flags. For example, as a first step we could all the common
// gates like this one into a single module. // 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) { async function resolveStreamResponse(response: any, onData?: any) {
let result = '' let result = ''
...@@ -460,7 +461,7 @@ describe('app dir - rsc basics', () => { ...@@ -460,7 +461,7 @@ describe('app dir - rsc basics', () => {
// TODO: (PPR) remove once PPR is stable // TODO: (PPR) remove once PPR is stable
// TODO(new-dev-overlay): remove once new dev overlay is stable // TODO(new-dev-overlay): remove once new dev overlay is stable
const bundledReactVersionPattern = const bundledReactVersionPattern =
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
? '-experimental-' ? '-experimental-'
: '-canary-' : '-canary-'
......
...@@ -34,20 +34,21 @@ describe('rsc-redirect', () => { ...@@ -34,20 +34,21 @@ describe('rsc-redirect', () => {
}) })
}) })
// TODO: these tests aren't currently run at all during testing
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
describe.each([ describe.each([
{ ppr: true, segmentCache: true }, { cacheComponents: true, segmentCache: true },
{ ppr: true, segmentCache: false }, { cacheComponents: true, segmentCache: false },
{ ppr: false, segmentCache: true }, { cacheComponents: false, segmentCache: true },
{ ppr: false, segmentCache: false }, { cacheComponents: false, segmentCache: false },
] as const)( ] as const)(
'rsc-redirect /old-about -> /about (ppr: $ppr, segmentCache: $segmentCache)', 'rsc-redirect /old-about -> /about (cacheComponents: $cacheComponents, segmentCache: $segmentCache)',
({ ppr, segmentCache }) => { ({ cacheComponents, segmentCache }) => {
beforeAll(() => { beforeAll(() => {
// Write next.config.js with the current flags // Write next.config.js with the current flags
fs.writeFileSync( fs.writeFileSync(
configPath, 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
This diff is collapsed.
This diff is collapsed.
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