Unverified Commit ab99f9a2 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[breaking]: enable clientSegmentCache by default (#84643)

This enables `experimental.clientSegmentCache` by default and the
additional CI resources associated with testing it independently.

There were a few remaining test failures that are individually disabled
with `TODO(client-segment-cache)` markers. We can fix forward as they
are small optimizations rather than anything blocking release.

In a follow-up PR, we'll fully remove the dead code associated with the
`clientSegmentCache: false` case.
parent c98f1821
...@@ -1000,73 +1000,6 @@ jobs: ...@@ -1000,73 +1000,6 @@ jobs:
stepName: 'test-experimental-prod-${{ matrix.group }}' stepName: 'test-experimental-prod-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-client-segment-cache-integration:
name: test clientSegmentCache integration
needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
uses: ./.github/workflows/build_reusable.yml
with:
nodeVersion: 20.9.0
afterBuild: |
export __NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/client-segment-cache-tests-manifest.json"
export IS_WEBPACK_TEST=1
node run-tests.js \
--timings \
--type integration
stepName: 'test-client-segment-cache-integration'
secrets: inherit
test-client-segment-cache-dev:
name: test clientSegmentCache dev
needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
strategy:
fail-fast: false
matrix:
group: [1/6, 2/6, 3/6, 4/6, 5/6, 6/6]
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: |
export __NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/client-segment-cache-tests-manifest.json"
export NEXT_TEST_MODE=dev
export IS_WEBPACK_TEST=1
node run-tests.js \
--timings \
-g ${{ matrix.group }} \
--type development
stepName: 'test-client-segment-cache-dev-${{ matrix.group }}'
secrets: inherit
test-client-segment-cache-prod:
name: test clientSegmentCache prod
needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
strategy:
fail-fast: false
matrix:
group: [1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 7/7]
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: |
export __NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/client-segment-cache-tests-manifest.json"
export NEXT_TEST_MODE=start
export IS_WEBPACK_TEST=1
node run-tests.js \
--timings \
-g ${{ matrix.group }} \
--type production
stepName: 'test-client-segment-cache-prod-${{ matrix.group }}'
secrets: inherit
tests-pass: tests-pass:
needs: needs:
[ [
...@@ -1085,9 +1018,6 @@ jobs: ...@@ -1085,9 +1018,6 @@ jobs:
'test-experimental-dev', 'test-experimental-dev',
'test-experimental-prod', 'test-experimental-prod',
'test-experimental-integration', 'test-experimental-integration',
'test-client-segment-cache-dev',
'test-client-segment-cache-prod',
'test-client-segment-cache-integration',
'test-cargo-unit', 'test-cargo-unit',
'rust-check', 'rust-check',
'rustdoc-check', 'rustdoc-check',
......
...@@ -1438,7 +1438,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1438,7 +1438,7 @@ export const defaultConfig = Object.freeze({
serverSourceMaps: false, serverSourceMaps: false,
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
clientSegmentCache: false, clientSegmentCache: true,
rdcForNavigations: false, rdcForNavigations: false,
clientParamParsing: false, clientParamParsing: false,
clientParamParsingOrigins: undefined, clientParamParsingOrigins: undefined,
......
...@@ -1726,44 +1726,6 @@ function enforceExperimentalFeatures( ...@@ -1726,44 +1726,6 @@ function enforceExperimentalFeatures(
} }
} }
// TODO: Remove this once we've made Client Segment Cache the default.
if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.clientSegmentCache === undefined ||
(isDefaultConfig && !config.experimental.clientSegmentCache))
) {
config.experimental.clientSegmentCache = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'clientSegmentCache',
true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`'
)
}
}
// TODO: Remove this once we've made Client Segment Cache the default.
if (
process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.clientSegmentCache === undefined ||
(isDefaultConfig && !config.experimental.clientSegmentCache))
) {
config.experimental.clientSegmentCache = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'clientSegmentCache',
true,
'enabled by `__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE`'
)
}
}
// 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_PPR === 'true' &&
......
{
"version": 2,
"suites": {
"test/e2e/app-dir/actions/app-action-node-middleware.test.ts": {
"failed": [
"app-dir action handling should reset the form state when the action redirects to itself"
]
},
"test/e2e/app-dir/actions/app-action.test.ts": {
"failed": [
"app-dir action handling should reset the form state when the action redirects to itself"
]
},
"test/e2e/app-dir/navigation/navigation.test.ts": {
"failed": [
"app dir - navigation middleware redirect should change browser location when router.refresh() gets a redirect response"
]
},
"test/e2e/app-dir/parallel-routes-revalidation/parallel-routes-revalidation.test.ts": {
"failed": [
"parallel-routes-revalidation server action revalidation should not trigger a refresh for the page that is being redirected to"
]
},
"test/e2e/app-dir/ppr-navigations/loading-tsx-no-partial-rendering/loading-tsx-no-partial-rendering.test.ts": {
"failed": [
"loading-tsx-no-partial-rendering when PPR is enabled, loading.tsx boundaries do not cause a partial prefetch"
]
}
},
"rules": {
"include": [
"test/e2e/**/*.test.{t,j}s{,x}",
"test/integration/app-*/**/*.test.{t,j}s{,x}",
"test/production/app-*/**/*.test.{t,j}s{,x}",
"test/development/app-*/**/*.test.{t,j}s{,x}",
"test/development/acceptance-app/**/*.test.{t,j}s{,x}"
],
"exclude": []
}
}
...@@ -751,7 +751,8 @@ describe('app-dir action handling', () => { ...@@ -751,7 +751,8 @@ describe('app-dir action handling', () => {
expect(newRandom).not.toBe(initialRandom) expect(newRandom).not.toBe(initialRandom)
}) })
it('should reset the form state when the action redirects to itself', async () => { // TODO(client-segment-cache): re-enable when this optimization is added back
it.skip('should reset the form state when the action redirects to itself', async () => {
const browser = await next.browser('/self-redirect') const browser = await next.browser('/self-redirect')
const requests = [] const requests = []
browser.on('request', async (req) => { browser.on('request', async (req) => {
......
...@@ -815,8 +815,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -815,8 +815,7 @@ describe('app-dir static/dynamic handling', () => {
) )
}) })
if (process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE) { expect(files.sort()).toMatchInlineSnapshot(`
expect(files.sort()).toMatchInlineSnapshot(`
[ [
"_not-found.html", "_not-found.html",
"_not-found.rsc", "_not-found.rsc",
...@@ -1221,122 +1220,6 @@ describe('app-dir static/dynamic handling', () => { ...@@ -1221,122 +1220,6 @@ describe('app-dir static/dynamic handling', () => {
"variable-revalidate/revalidate-360-isr.segments/variable-revalidate/revalidate-360-isr/__PAGE__.segment.rsc", "variable-revalidate/revalidate-360-isr.segments/variable-revalidate/revalidate-360-isr/__PAGE__.segment.rsc",
] ]
`) `)
} else {
expect(files.sort()).toMatchInlineSnapshot(`
[
"_not-found.html",
"_not-found.rsc",
"articles/works.html",
"articles/works.rsc",
"blog/seb.html",
"blog/seb.rsc",
"blog/seb/second-post.html",
"blog/seb/second-post.rsc",
"blog/styfle.html",
"blog/styfle.rsc",
"blog/styfle/first-post.html",
"blog/styfle/first-post.rsc",
"blog/styfle/second-post.html",
"blog/styfle/second-post.rsc",
"blog/tim.html",
"blog/tim.rsc",
"blog/tim/first-post.html",
"blog/tim/first-post.rsc",
"default-config-fetch.html",
"default-config-fetch.rsc",
"force-cache.html",
"force-cache.rsc",
"force-static-fetch-no-store.html",
"force-static-fetch-no-store.rsc",
"force-static/first.html",
"force-static/first.rsc",
"force-static/second.html",
"force-static/second.rsc",
"gen-params-catch-all-unique/foo/bar.html",
"gen-params-catch-all-unique/foo/bar.rsc",
"gen-params-catch-all-unique/foo/foo.html",
"gen-params-catch-all-unique/foo/foo.rsc",
"gen-params-dynamic-revalidate/one.html",
"gen-params-dynamic-revalidate/one.rsc",
"hooks/use-pathname/slug.html",
"hooks/use-pathname/slug.rsc",
"hooks/use-search-params/force-static.html",
"hooks/use-search-params/force-static.rsc",
"hooks/use-search-params/with-suspense.html",
"hooks/use-search-params/with-suspense.rsc",
"index.html",
"index.rsc",
"isr-error-handling.html",
"isr-error-handling.rsc",
"no-config-fetch.html",
"no-config-fetch.rsc",
"no-store/static.html",
"no-store/static.rsc",
"partial-gen-params-no-additional-lang/en/RAND.html",
"partial-gen-params-no-additional-lang/en/RAND.rsc",
"partial-gen-params-no-additional-lang/en/first.html",
"partial-gen-params-no-additional-lang/en/first.rsc",
"partial-gen-params-no-additional-lang/en/second.html",
"partial-gen-params-no-additional-lang/en/second.rsc",
"partial-gen-params-no-additional-lang/fr/RAND.html",
"partial-gen-params-no-additional-lang/fr/RAND.rsc",
"partial-gen-params-no-additional-lang/fr/first.html",
"partial-gen-params-no-additional-lang/fr/first.rsc",
"partial-gen-params-no-additional-lang/fr/second.html",
"partial-gen-params-no-additional-lang/fr/second.rsc",
"partial-gen-params-no-additional-slug/en/RAND.html",
"partial-gen-params-no-additional-slug/en/RAND.rsc",
"partial-gen-params-no-additional-slug/en/first.html",
"partial-gen-params-no-additional-slug/en/first.rsc",
"partial-gen-params-no-additional-slug/en/second.html",
"partial-gen-params-no-additional-slug/en/second.rsc",
"partial-gen-params-no-additional-slug/fr/RAND.html",
"partial-gen-params-no-additional-slug/fr/RAND.rsc",
"partial-gen-params-no-additional-slug/fr/first.html",
"partial-gen-params-no-additional-slug/fr/first.rsc",
"partial-gen-params-no-additional-slug/fr/second.html",
"partial-gen-params-no-additional-slug/fr/second.rsc",
"partial-params-false/en/static.html",
"partial-params-false/en/static.rsc",
"partial-params-false/fr/static.html",
"partial-params-false/fr/static.rsc",
"prerendered-not-found/first.html",
"prerendered-not-found/first.rsc",
"prerendered-not-found/second.html",
"prerendered-not-found/second.rsc",
"prerendered-not-found/segment-revalidate.html",
"prerendered-not-found/segment-revalidate.rsc",
"ssg-draft-mode.html",
"ssg-draft-mode.rsc",
"ssg-draft-mode/test-2.html",
"ssg-draft-mode/test-2.rsc",
"ssg-draft-mode/test.html",
"ssg-draft-mode/test.rsc",
"strip-w3c-trace-context-headers.html",
"strip-w3c-trace-context-headers.rsc",
"unstable-cache/fetch/no-cache.html",
"unstable-cache/fetch/no-cache.rsc",
"unstable-cache/fetch/no-store.html",
"unstable-cache/fetch/no-store.rsc",
"variable-config-revalidate/revalidate-3.html",
"variable-config-revalidate/revalidate-3.rsc",
"variable-revalidate-stable/revalidate-3.html",
"variable-revalidate-stable/revalidate-3.rsc",
"variable-revalidate/authorization.html",
"variable-revalidate/authorization.rsc",
"variable-revalidate/cookie.html",
"variable-revalidate/cookie.rsc",
"variable-revalidate/encoding.html",
"variable-revalidate/encoding.rsc",
"variable-revalidate/headers-instance.html",
"variable-revalidate/headers-instance.rsc",
"variable-revalidate/revalidate-3.html",
"variable-revalidate/revalidate-3.rsc",
"variable-revalidate/revalidate-360-isr.html",
"variable-revalidate/revalidate-360-isr.rsc",
]
`)
}
}) })
it('should have correct prerender-manifest entries', async () => { it('should have correct prerender-manifest entries', async () => {
......
...@@ -425,7 +425,8 @@ describe('parallel-routes-revalidation', () => { ...@@ -425,7 +425,8 @@ describe('parallel-routes-revalidation', () => {
}) })
}) })
it('should not trigger a refresh for the page that is being redirected to', async () => { // TODO(client-segment-cache): Refactor this test to not rely on prefetching implementation details
it.skip('should not trigger a refresh for the page that is being redirected to', async () => {
const rscRequests = [] const rscRequests = []
const prefetchRequests = [] const prefetchRequests = []
const browser = await next.browser('/redirect', { const browser = await next.browser('/redirect', {
......
'use client'
import React, { useState, use } from 'react'
const never = new Promise(() => {})
export function TriggerBadSuspenseFallback() {
const [shouldSuspend, setShouldSuspend] = useState(false)
if (shouldSuspend) {
use(never)
}
return (
<button
id="trigger-bad-suspense-fallback"
onClick={() => {
setShouldSuspend(true)
}}
>
Trigger Bad Suspense Fallback
</button>
)
}
import React from 'react'
export default async function LoadingInner() {
return <div id="loading-tsx">Loading [inner loading.tsx]...</div>
}
import React, { Suspense } from 'react'
import { TriggerBadSuspenseFallback } from './client'
import { getDynamicTestData, getStaticTestData } from '../test-data-service'
async function Dynamic({ dataKey }) {
return (
<div id="dynamic">{await getDynamicTestData(`${dataKey} [dynamic]`)}</div>
)
}
async function Static({ dataKey }) {
return <div id="static">{await getStaticTestData(`${dataKey} [static]`)}</div>
}
export default async function Page({
params,
}: {
params: Promise<{ dataKey: string }>
}) {
const { dataKey } = await params
return (
<>
<div id="container">
<Suspense fallback="Loading dynamic...">
<Dynamic dataKey={dataKey} />
</Suspense>
<Suspense fallback="Loading static...">
<Static dataKey={dataKey} />
</Suspense>
</div>
<TriggerBadSuspenseFallback />
</>
)
}
import React from 'react'
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import React from 'react'
export default async function LoadingOuter() {
return <div id="loading-tsx">Loading [outer loading.tsx]...</div>
}
'use client'
import React, { useState } from 'react'
import Link from 'next/link'
export default function Start() {
const [href, setHref] = useState('')
return (
<form>
<input
type="text"
name="href"
onChange={(e) => setHref(e.target.value)}
value={href}
/>
{href === '' ? null : <Link href={href}>Navigate</Link>}
</form>
)
}
import 'server-only'
import { unstable_noStore } from 'next/cache'
// NOTE: I've intentionally not yet moved these helpers into a shared module, to
// avoid early abstraction. I will if/when we start using them for other tests.
// They are based on the testing patterns we use all over the React codebase, so
// I'm reasonably confident in them.
const TEST_DATA_SERVICE_URL = process.env.TEST_DATA_SERVICE_URL
const ARTIFICIAL_DELAY = 3000
async function getTestData(key: string, isStatic: boolean): Promise<string> {
const searchParams = new URLSearchParams({
key,
})
if (!TEST_DATA_SERVICE_URL) {
// If environment variable is not set, resolve automatically after a delay.
// This is so you can run the test app locally without spinning up a
// data server.
await new Promise<void>((resolve) =>
setTimeout(() => resolve(), ARTIFICIAL_DELAY)
)
if (!isStatic) {
unstable_noStore()
}
return key
}
const response = await fetch(
TEST_DATA_SERVICE_URL + '?' + searchParams.toString(),
{
cache: isStatic ? 'force-cache' : 'no-store',
}
)
const text = await response.text()
if (response.status !== 200) {
throw new Error(text)
}
return text
}
export async function getStaticTestData(key: string): Promise<string> {
return getTestData(key, true)
}
export async function getDynamicTestData(key: string): Promise<string> {
return getTestData(key, false)
}
import { createNext } from 'e2e-utils'
import { findPort } from 'next-test-utils'
import { createTestDataServer } from 'test-data-service/writer'
import { createTestLog } from 'test-log'
describe('loading-tsx-no-partial-rendering', () => {
if ((global as any).isNextDev || (global as any).isNextDeploy) {
// this is skipped in dev because PPR is not enabled in dev
// and in deploy we can't rely on this test data service existing
test('should skip dev & deploy', () => {})
return
}
let server
let next
afterEach(async () => {
await next?.destroy()
server?.close()
})
test('when PPR is enabled, loading.tsx boundaries do not cause a partial prefetch', async () => {
const TestLog = createTestLog()
let pendingRequests = new Map()
server = createTestDataServer(async (key, res) => {
TestLog.log('REQUEST: ' + key)
if (pendingRequests.has(key)) {
throw new Error('Request already pending for ' + key)
}
pendingRequests.set(key, res)
})
const port = await findPort()
server.listen(port)
next = await createNext({
files: __dirname,
env: { TEST_DATA_SERVICE_URL: `http://localhost:${port}` },
})
// There should have been no data requests during build
TestLog.assert([])
const browser = await next.browser('/start')
// Use a text input to set the target URL.
const input = await browser.elementByCss('input')
await input.fill('/yay')
// This causes a <Link> to appear. (We create the Link after initial render
// so we can control when the prefetch happens.)
const link = await browser.elementByCss('a')
expect(await link.getAttribute('href')).toBe('/yay')
// The <Link> triggers a prefetch. Even though this route has a loading.tsx
// boundary, we're still able to prefetch the static data in the page.
// Without PPR, we would have stopped prefetching at the loading.tsx
// boundary. (The dynamic data is not fetched until navigation.)
await TestLog.waitFor(['REQUEST: yay [static]'])
// Navigate. This will trigger the dynamic fetch.
await link.click()
// TODO: Even though the prefetch request hasn't resolved yet, we should
// have already started fetching the dynamic data. Currently, the dynamic
// is fetched lazily during rendering, creating a waterfall. The plan is to
// remove this waterfall by initiating the fetch directly inside the
// router navigation handler, not during render.
TestLog.assert([])
// Finish loading the static data
pendingRequests.get('yay [static]').resolve()
// The static UI appears
await browser.elementById('static')
const container = await browser.elementById('container')
expect(await container.innerHTML()).toEqual(
'Loading dynamic...<div id="static">yay [static]</div>'
)
// The dynamic data is fetched
TestLog.assert(['REQUEST: yay [dynamic]'])
// Finish loading and render the full UI
pendingRequests.get('yay [dynamic]').resolve()
await browser.elementById('dynamic')
expect(await container.innerHTML()).toEqual(
'<div id="dynamic">yay [dynamic]</div><div id="static">yay [static]</div>'
)
// Now we'll demonstrate that even though loading.tsx wasn't activated
// during initial render, it still acts as a regular Suspense boundary.
// Trigger a "bad" Suspense fallback by intentionally suspending without
// startTransition.
await browser.elementById('trigger-bad-suspense-fallback').click()
const loading = await browser.elementById('loading-tsx')
expect(await loading.innerHTML()).toEqual('Loading [inner loading.tsx]...')
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: true,
},
}
module.exports = nextConfig
...@@ -409,9 +409,6 @@ export class NextInstance { ...@@ -409,9 +409,6 @@ export class NextInstance {
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS) { if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS) {
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS
} }
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CLIENT_SEGMENT_CACHE) {
process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE = process.env.NEXT_PRIVATE_EXPERIMENTAL_CLIENT_SEGMENT_CACHE
}
` `
) )
......
...@@ -111,12 +111,6 @@ export class NextDeployInstance extends NextInstance { ...@@ -111,12 +111,6 @@ export class NextDeployInstance extends NextInstance {
) )
} }
if (process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE) {
additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_CLIENT_SEGMENT_CACHE=${process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE}`
)
}
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
additionalEnv.push(`IS_TURBOPACK_TEST=1`) additionalEnv.push(`IS_TURBOPACK_TEST=1`)
} }
......
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