Unverified Commit 3dafc76f authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[fragment-scroll] Add `experimental.appNewScrollHandler` (#83107)

Just plumbing and enabling that flag in the experimental shards. The flag will enable our Layout router to use Fragment refs for scroll restoration. Implementation will be done in a follow-up.
parent 507ab36d
...@@ -722,6 +722,7 @@ jobs: ...@@ -722,6 +722,7 @@ jobs:
# Keep Next.js related env variables in sync with additionalEnv in next-deploy.ts # Keep Next.js related env variables in sync with additionalEnv in next-deploy.ts
afterBuild: | afterBuild: |
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json,test/cache-components-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json,test/cache-components-tests-manifest.json"
export NEXT_E2E_TEST_TIMEOUT=240000 export NEXT_E2E_TEST_TIMEOUT=240000
...@@ -962,6 +963,7 @@ jobs: ...@@ -962,6 +963,7 @@ jobs:
nodeVersion: 20.9.0 nodeVersion: 20.9.0
afterBuild: | afterBuild: |
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json"
export IS_WEBPACK_TEST=1 export IS_WEBPACK_TEST=1
...@@ -985,6 +987,7 @@ jobs: ...@@ -985,6 +987,7 @@ jobs:
with: with:
afterBuild: | afterBuild: |
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json"
export NEXT_TEST_MODE=dev export NEXT_TEST_MODE=dev
...@@ -1010,6 +1013,7 @@ jobs: ...@@ -1010,6 +1013,7 @@ jobs:
with: with:
afterBuild: | afterBuild: |
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json" export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json"
export NEXT_TEST_MODE=start export NEXT_TEST_MODE=start
......
...@@ -1095,6 +1095,7 @@ pub struct ExperimentalConfig { ...@@ -1095,6 +1095,7 @@ pub struct ExperimentalConfig {
adjust_font_fallbacks_with_size_adjust: Option<bool>, adjust_font_fallbacks_with_size_adjust: Option<bool>,
after: Option<bool>, after: Option<bool>,
app_document_preloading: Option<bool>, app_document_preloading: Option<bool>,
app_new_scroll_handler: Option<bool>,
case_sensitive_routes: Option<bool>, case_sensitive_routes: Option<bool>,
cpus: Option<f64>, cpus: Option<f64>,
cra_compat: Option<bool>, cra_compat: Option<bool>,
...@@ -1913,6 +1914,11 @@ impl NextConfig { ...@@ -1913,6 +1914,11 @@ impl NextConfig {
Vc::cell(self.experimental.gesture_transition.unwrap_or(false)) Vc::cell(self.experimental.gesture_transition.unwrap_or(false))
} }
#[turbo_tasks::function]
pub fn enable_app_new_scroll_handler(&self) -> Vc<bool> {
Vc::cell(self.experimental.app_new_scroll_handler.unwrap_or(false))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn enable_cache_components(&self) -> Vc<bool> { pub fn enable_cache_components(&self) -> Vc<bool> {
Vc::cell(self.cache_components.unwrap_or(false)) Vc::cell(self.cache_components.unwrap_or(false))
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,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_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true" "with-experimental": "cross-env __NEXT_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true"
}, },
"devDependencies": { "devDependencies": {
"@actions/core": "1.10.1", "@actions/core": "1.10.1",
......
...@@ -166,6 +166,9 @@ export function getDefineEnv({ ...@@ -166,6 +166,9 @@ export function getDefineEnv({
'process.env.__NEXT_APP_NAV_FAIL_HANDLING': Boolean( 'process.env.__NEXT_APP_NAV_FAIL_HANDLING': Boolean(
config.experimental.appNavFailHandling config.experimental.appNavFailHandling
), ),
'process.env.__NEXT_APP_NEW_SCROLL_HANDLER': Boolean(
config.experimental.appNewScrollHandler
),
'process.env.__NEXT_PPR': isPPREnabled, 'process.env.__NEXT_PPR': isPPREnabled,
'process.env.__NEXT_CACHE_COMPONENTS': isCacheComponentsEnabled, 'process.env.__NEXT_CACHE_COMPONENTS': isCacheComponentsEnabled,
'process.env.__NEXT_USE_CACHE': isUseCacheEnabled, 'process.env.__NEXT_USE_CACHE': isUseCacheEnabled,
......
...@@ -182,6 +182,7 @@ export const experimentalSchema = { ...@@ -182,6 +182,7 @@ export const experimentalSchema = {
useSkewCookie: z.boolean().optional(), useSkewCookie: z.boolean().optional(),
after: z.boolean().optional(), after: z.boolean().optional(),
appNavFailHandling: z.boolean().optional(), appNavFailHandling: z.boolean().optional(),
appNewScrollHandler: z.boolean().optional(),
preloadEntriesOnStart: z.boolean().optional(), preloadEntriesOnStart: z.boolean().optional(),
allowedRevalidateHeaderKeys: z.array(z.string()).optional(), allowedRevalidateHeaderKeys: z.array(z.string()).optional(),
staleTimes: z staleTimes: z
......
...@@ -324,6 +324,7 @@ export interface LoggingConfig { ...@@ -324,6 +324,7 @@ export interface LoggingConfig {
export interface ExperimentalConfig { export interface ExperimentalConfig {
adapterPath?: string adapterPath?: string
appNewScrollHandler?: boolean
useSkewCookie?: boolean useSkewCookie?: boolean
/** @deprecated use top-level `cacheHandlers` instead */ /** @deprecated use top-level `cacheHandlers` instead */
cacheHandlers?: NextConfig['cacheHandlers'] cacheHandlers?: NextConfig['cacheHandlers']
...@@ -1617,6 +1618,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1617,6 +1618,7 @@ export const defaultConfig = Object.freeze({
}, },
experimental: { experimental: {
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined, adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
appNewScrollHandler: false,
useSkewCookie: false, useSkewCookie: false,
cssChunking: true, cssChunking: true,
multiZoneDraftMode: false, multiZoneDraftMode: false,
......
...@@ -1906,6 +1906,25 @@ function enforceExperimentalFeatures( ...@@ -1906,6 +1906,25 @@ function enforceExperimentalFeatures(
config.cacheComponents = true config.cacheComponents = true
} }
// TODO: Remove this once appNewScrollHandler is the default.
if (
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.appNewScrollHandler === undefined ||
(isDefaultConfig && !config.experimental.appNewScrollHandler))
) {
config.experimental.appNewScrollHandler = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'appNewScrollHandler',
true,
'enabled by `__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER`'
)
}
}
// TODO: Remove this once using the debug channel is the default. // TODO: Remove this once using the debug channel is the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL === 'true' && process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL === 'true' &&
......
...@@ -439,6 +439,9 @@ export class NextInstance { ...@@ -439,6 +439,9 @@ export class NextInstance {
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS) { if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS) {
process.env.__NEXT_CACHE_COMPONENTS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS process.env.__NEXT_CACHE_COMPONENTS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS
} }
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER) {
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER = process.env.NEXT_PRIVATE_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER
}
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL) { if (process.env.NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL) {
process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL = process.env.NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL = process.env.NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL
} }
......
...@@ -301,6 +301,11 @@ export class NextDeployInstance extends NextInstance { ...@@ -301,6 +301,11 @@ export class NextDeployInstance extends NextInstance {
`NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS=${process.env.__NEXT_CACHE_COMPONENTS}` `NEXT_PRIVATE_EXPERIMENTAL_CACHE_COMPONENTS=${process.env.__NEXT_CACHE_COMPONENTS}`
) )
} }
if (process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER) {
additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=${process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER}`
)
}
if (process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL) { if (process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL) {
additionalEnv.push( additionalEnv.push(
`NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL=${process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL}` `NEXT_PRIVATE_EXPERIMENTAL_DEBUG_CHANNEL=${process.env.__NEXT_EXPERIMENTAL_DEBUG_CHANNEL}`
......
...@@ -20,6 +20,7 @@ describe('build-output-prerender', () => { ...@@ -20,6 +20,7 @@ describe('build-output-prerender', () => {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(` expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z (Turbopack, Cache Components) "▲ Next.js x.y.z (Turbopack, Cache Components)
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)" ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`) `)
} else { } else {
...@@ -27,6 +28,7 @@ describe('build-output-prerender', () => { ...@@ -27,6 +28,7 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (webpack) "▲ Next.js x.y.z (webpack)
- Cache Components enabled - Cache Components enabled
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)" ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`) `)
} }
...@@ -101,6 +103,7 @@ describe('build-output-prerender', () => { ...@@ -101,6 +103,7 @@ describe('build-output-prerender', () => {
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production. "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
▲ Next.js x.y.z (Turbopack, Cache Components) ▲ Next.js x.y.z (Turbopack, Cache Components)
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`) ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`) ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`) ✓ serverSourceMaps (enabled by \`--debug-prerender\`)
...@@ -112,6 +115,7 @@ describe('build-output-prerender', () => { ...@@ -112,6 +115,7 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (webpack) ▲ Next.js x.y.z (webpack)
- Cache Components enabled - Cache Components enabled
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`) ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`) ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
⨯ serverMinification (disabled by \`--debug-prerender\`) ⨯ serverMinification (disabled by \`--debug-prerender\`)
...@@ -230,6 +234,7 @@ describe('build-output-prerender', () => { ...@@ -230,6 +234,7 @@ describe('build-output-prerender', () => {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(` expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z (Turbopack, Cache Components) "▲ Next.js x.y.z (Turbopack, Cache Components)
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)" ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`) `)
} else { } else {
...@@ -237,6 +242,7 @@ describe('build-output-prerender', () => { ...@@ -237,6 +242,7 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (webpack) "▲ Next.js x.y.z (webpack)
- Cache Components enabled - Cache Components enabled
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)" ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
`) `)
} }
...@@ -278,6 +284,7 @@ describe('build-output-prerender', () => { ...@@ -278,6 +284,7 @@ describe('build-output-prerender', () => {
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production. "⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
▲ Next.js x.y.z (Turbopack, Cache Components) ▲ Next.js x.y.z (Turbopack, Cache Components)
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`) ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`) ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`) ✓ serverSourceMaps (enabled by \`--debug-prerender\`)
...@@ -289,6 +296,7 @@ describe('build-output-prerender', () => { ...@@ -289,6 +296,7 @@ describe('build-output-prerender', () => {
▲ Next.js x.y.z (webpack) ▲ Next.js x.y.z (webpack)
- Cache Components enabled - Cache Components enabled
- Experiments (use with caution): - Experiments (use with caution):
✓ appNewScrollHandler (enabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`) ⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`) ✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
⨯ serverMinification (disabled by \`--debug-prerender\`) ⨯ serverMinification (disabled by \`--debug-prerender\`)
......
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