Unverified Commit 2c047359 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[fragment-scroll] Remove `config.experimental.appNewScrollHandler` (#95602)

parent 79168556
......@@ -394,7 +394,6 @@ jobs:
export NEXT_TEST_MODE=dev
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export RUST_BACKTRACE=1
node run-tests.js \
......@@ -437,7 +436,6 @@ jobs:
export NEXT_TEST_MODE=start
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export RUST_BACKTRACE=1
node run-tests.js --timings --require-timings -g ${{ matrix.group }} --type production
......@@ -474,7 +472,6 @@ jobs:
export NEXT_TEST_MODE=dev
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
# rspack flags
export NEXT_RSPACK=1
......@@ -521,7 +518,6 @@ jobs:
export NEXT_TEST_MODE=start
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
# rspack flags
export NEXT_RSPACK=1
......@@ -684,7 +680,6 @@ jobs:
with:
afterBuild: |
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
node scripts/test-new-tests.mjs \
--flake-detection \
--mode dev \
......@@ -711,7 +706,6 @@ jobs:
with:
afterBuild: |
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
node scripts/test-new-tests.mjs \
--flake-detection \
--mode start \
......@@ -781,7 +775,6 @@ jobs:
export NEXT_ENABLE_ADAPTER=1
export NEXT_E2E_TEST_TIMEOUT=240000
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export IS_TURBOPACK_TEST=1
node scripts/test-new-tests.mjs \
--mode deploy \
......@@ -848,7 +841,6 @@ jobs:
export NEXT_TEST_MODE=dev
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
node run-tests.js \
--timings \
......@@ -870,7 +862,6 @@ jobs:
afterBuild: |
export NEXT_TEST_MODE=dev
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export IS_TURBOPACK_TEST=1
export TURBOPACK_DEV=1
......@@ -894,7 +885,6 @@ jobs:
afterBuild: |
export NEXT_TEST_MODE=start
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export IS_TURBOPACK_TEST=1
export TURBOPACK_BUILD=1
......@@ -919,7 +909,6 @@ jobs:
afterBuild: |
export NEXT_TEST_MODE=start
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
export IS_TURBOPACK_TEST=1
export TURBOPACK_BUILD=1
......@@ -961,7 +950,6 @@ jobs:
export NEXT_TEST_MODE=start
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
node run-tests.js --timings --require-timings -g ${{ matrix.group }} --type production
testTimingsArtifact: 'test-timings'
......@@ -981,7 +969,6 @@ jobs:
# these all run without concurrency because they're heavier
export TEST_CONCURRENCY=1
export IS_TURBOPACK_TEST=1
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=false
TURBOPACK_BUILD=1 NEXT_TEST_MODE=start BROWSER_NAME=firefox node run-tests.js \
test/production/pages-dir/production/test/index.test.ts \
test/production/chunk-load-failure/chunk-load-failure.test.ts
......
......@@ -1333,7 +1333,6 @@ pub struct ExperimentalConfig {
adjust_font_fallbacks_with_size_adjust: Option<bool>,
after: Option<bool>,
app_document_preloading: Option<bool>,
app_new_scroll_handler: Option<bool>,
case_sensitive_routes: Option<bool>,
cpus: Option<f64>,
cra_compat: Option<bool>,
......
......@@ -171,9 +171,6 @@ export function getDefineEnv({
'process.env.__NEXT_APP_NAV_FAIL_HANDLING': Boolean(
config.experimental.appNavFailHandling
),
'process.env.__NEXT_APP_NEW_SCROLL_HANDLER': Boolean(
config.experimental.appNewScrollHandler
),
'process.env.__NEXT_TURBOPACK_SHARED_RUNTIME': Boolean(
config.experimental.turbopackSharedRuntime
),
......
......@@ -22,7 +22,6 @@ import React, {
type JSX,
type ActivityProps,
} from 'react'
import ReactDOM from 'react-dom'
import {
LayoutRouterContext,
GlobalLayoutRouterContext,
......@@ -51,56 +50,6 @@ import { getParamValueFromCacheKey } from '../route-params'
import type { Params } from '../../server/request/params'
import { isDeferredRsc } from './router-reducer/ppr-navigations'
const enableNewScrollHandler = process.env.__NEXT_APP_NEW_SCROLL_HANDLER
const __DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = (
ReactDOM as any
).__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
// TODO-APP: Replace with new React API for finding dom nodes without a `ref` when available
/**
* Wraps ReactDOM.findDOMNode with additional logic to hide React Strict Mode warning
*/
function findDOMNode(
instance: React.ReactInstance | null | undefined
): Element | Text | null {
// Tree-shake for server bundle
if (typeof window === 'undefined') return null
// __DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode is null during module init.
// We need to lazily reference it.
const internal_reactDOMfindDOMNode =
__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode
return internal_reactDOMfindDOMNode(instance)
}
const rectProperties = [
'bottom',
'height',
'left',
'right',
'top',
'width',
'x',
'y',
] as const
/**
* Check if a HTMLElement is hidden or fixed/sticky position
*/
function shouldSkipElement(element: HTMLElement) {
// we ignore fixed or sticky positioned elements since they'll likely pass the "in-viewport" check
// and will result in a situation we bail on scroll because of something like a fixed nav,
// even though the actual page content is offscreen
if (['sticky', 'fixed'].includes(getComputedStyle(element).position)) {
return true
}
// Uses `getBoundingClientRect` to check if the element is hidden instead of `offsetParent`
// because `offsetParent` doesn't consider document/body
const rect = element.getBoundingClientRect()
return rectProperties.every((item) => rect[item] === 0)
}
const enum ScrollTargetState {
NoClientRects,
InViewport,
......@@ -189,145 +138,14 @@ interface ScrollAndMaybeFocusHandlerProps {
children: React.ReactNode
cacheNode: CacheNode
}
class InnerScrollAndFocusHandlerOld extends React.Component<ScrollAndMaybeFocusHandlerProps> {
handlePotentialScroll = () => {
// Handle scroll and focus, it's only applied once.
const { focusAndScrollRef, cacheNode } = this.props
const scrollRef = focusAndScrollRef.forceScroll
? focusAndScrollRef.scrollRef
: cacheNode.scrollRef
if (scrollRef === null || !scrollRef.current) return
let domNode:
| ReturnType<typeof getHashFragmentDomNode>
| ReturnType<typeof findDOMNode> = null
const hashFragment = focusAndScrollRef.hashFragment
if (hashFragment) {
domNode = getHashFragmentDomNode(hashFragment)
if (domNode === null) {
// A missing hash target is still a handled scroll intent. Do not
// fall back to the route segment or leave the intent pending.
scrollRef.current = false
focusAndScrollRef.onlyHashChange = false
focusAndScrollRef.hashFragment = null
return
}
}
// `findDOMNode` is tricky because it returns just the first child if the component is a fragment.
// This already caused a bug where the first child was a <link/> in head.
if (!domNode) {
domNode = findDOMNode(this)
}
// If there is no DOM node this layout-router level is skipped. It'll be handled higher-up in the tree.
if (!(domNode instanceof Element)) {
return
}
// Verify if the element is a HTMLElement and if we want to consider it for scroll behavior.
// If the element is skipped, try to select the next sibling and try again.
while (!(domNode instanceof HTMLElement) || shouldSkipElement(domNode)) {
if (process.env.NODE_ENV !== 'production') {
if (domNode.parentElement?.localName === 'head') {
// We enter this state when metadata was rendered as part of the page or via Next.js.
// This is always a bug in Next.js and caused by React hoisting metadata.
// Fixed with `experimental.appNewScrollHandler`
}
}
// No siblings found that match the criteria are found, so handle scroll higher up in the tree instead.
if (domNode.nextElementSibling === null) {
return
}
domNode = domNode.nextElementSibling
}
// Mark as scrolled so no other segment scrolls for this navigation.
scrollRef.current = false
disableSmoothScrollDuringRouteTransition(
() => {
// In case of hash scroll, we only need to scroll the element into view
if (hashFragment) {
domNode.scrollIntoView()
return
}
// Store the current viewport height because reading `clientHeight` causes a reflow,
// and it won't change during this function.
const htmlElement = document.documentElement
const viewportHeight = htmlElement.clientHeight
let scrollPaddingTop: number | null = null
const getScrollPaddingTop = () => {
if (scrollPaddingTop === null) {
// Reuse the style and layout update from the geometry read above.
scrollPaddingTop = getScrollPaddingTopInPixels(
htmlElement,
viewportHeight
)
}
return scrollPaddingTop
}
// If the element's top edge is already in the viewport, exit early.
if (
getScrollTargetState(domNode, viewportHeight, getScrollPaddingTop) ===
ScrollTargetState.InViewport
) {
return
}
// Otherwise, try scrolling go the top of the document to be backward compatible with pages
// scrollIntoView() called on `<html/>` element scrolls horizontally on chrome and firefox (that shouldn't happen)
// We could use it to scroll horizontally following RTL but that also seems to be broken - it will always scroll left
// scrollLeft = 0 also seems to ignore RTL and manually checking for RTL is too much hassle so we will scroll just vertically
htmlElement.scrollTop = 0
// Scroll to domNode if domNode is not in viewport when scrolled to top of document
if (
getScrollTargetState(domNode, viewportHeight, getScrollPaddingTop) !==
ScrollTargetState.InViewport
) {
// Scroll into view doesn't scroll horizontally by default when not needed
domNode.scrollIntoView()
}
},
{
// We will force layout by querying domNode position
dontForceLayout: true,
onlyHashChange: focusAndScrollRef.onlyHashChange,
}
)
// Mutate after scrolling so that it can be read by `disableSmoothScrollDuringRouteTransition`
focusAndScrollRef.onlyHashChange = false
focusAndScrollRef.hashFragment = null
// Set focus on the element
domNode.focus()
}
componentDidMount() {
this.handlePotentialScroll()
}
componentDidUpdate() {
this.handlePotentialScroll()
}
render() {
return this.props.children
}
}
/**
* Fork of InnerScrollAndFocusHandlerOld using Fragment refs for scrolling.
* No longer focuses the first host descendant.
* Uses Fragment refs for scrolling.
* Does not focus the first host descendant.
*/
function InnerScrollHandlerNew(props: ScrollAndMaybeFocusHandlerProps) {
function InnerScrollAndMaybeFocusHandler(
props: ScrollAndMaybeFocusHandlerProps
) {
const childrenRef = React.useRef<FragmentInstance>(null)
useLayoutEffect(
......@@ -459,10 +277,6 @@ function InnerScrollHandlerNew(props: ScrollAndMaybeFocusHandlerProps) {
return <Fragment ref={childrenRef}>{props.children}</Fragment>
}
const InnerScrollAndMaybeFocusHandler = enableNewScrollHandler
? InnerScrollHandlerNew
: InnerScrollAndFocusHandlerOld
function ScrollAndMaybeFocusHandler({
children,
cacheNode,
......
......@@ -194,7 +194,6 @@ export const experimentalSchema = {
useSkewCookie: z.boolean().optional(),
after: z.boolean().optional(),
appNavFailHandling: z.boolean().optional(),
appNewScrollHandler: z.boolean().optional(),
coldCacheBadge: z.boolean().optional(),
preloadEntriesOnStart: z.boolean().optional(),
allowedRevalidateHeaderKeys: z.array(z.string()).optional(),
......
......@@ -469,7 +469,6 @@ export interface ExperimentalConfig {
*/
outputHashSalt?: string
appNewScrollHandler?: boolean
/**
* Shows a persistent "Cold cache" badge in the dev overlay after a load that
* filled an empty cache while streaming. Off by default while the badge's
......@@ -2156,7 +2155,6 @@ export const defaultConfig = Object.freeze({
},
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
experimental: {
appNewScrollHandler: true,
coldCacheBadge: false,
devValidationWorker: true,
useSkewCookie: false,
......
......@@ -2384,30 +2384,6 @@ function enforceExperimentalFeatures(
config.experimental.cachedNavigations = true
}
// appNewScrollHandler defaults to `true`. The env var lets us opt back out to
// keep test coverage of the old scroll handler on the non-experimental CI
// shards. Like the other env-var experimental toggles, opting out is surfaced
// in the reported experimental features.
// TODO: Remove this once the appNewScrollHandler opt-out is no longer needed
// for test coverage.
if (
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER === 'false' &&
// We do respect an explicit value in the user config.
(config.experimental.appNewScrollHandler === undefined ||
(isDefaultConfig && config.experimental.appNewScrollHandler))
) {
config.experimental.appNewScrollHandler = false
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'appNewScrollHandler',
false,
'disabled by `__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER`'
)
}
}
// TODO: Remove this once strictRouteTypes is the default.
if (
process.env.__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES === 'true' &&
......
......@@ -15,8 +15,6 @@
set -eo pipefail
experimental=false
while [ $# -gt 0 ]; do
case "$1" in
--mode=dev|--mode=start|--mode=deploy)
......@@ -41,7 +39,6 @@ while [ $# -gt 0 ]; do
exit 1
;;
--experimental)
experimental=true
export __NEXT_CACHE_COMPONENTS=true
;;
--headless)
......@@ -59,14 +56,6 @@ while [ $# -gt 0 ]; do
shift
done
# appNewScrollHandler defaults to `true`. Non-experimental runs opt out so
# local runs mirror the non-experimental CI shards and keep coverage of the old
# scroll handler; experimental runs leave it on via the default. An explicit
# value in the environment is respected either way.
if [ "$experimental" != true ]; then
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER="${__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER:-false}"
fi
# Resolves to `node_modules/.bin/jest` via `$PATH`. This relies on being
# invoked through pnpm (or another package runner), which prepends the
# workspace's `node_modules/.bin/` to `$PATH` before running the script.
......
......@@ -49,16 +49,15 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<main className="child">
+ client
- server
...
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<main className="child">
+ client
- server
...
...",
...
...",
"description": "Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Recoverable Error",
......@@ -111,14 +110,13 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
+ <main className="only">
...
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
+ <main className="only">
...
...",
...
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Recoverable Error",
......@@ -151,15 +149,14 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<script>
<Next.js Internal Component>
<RootLayout params={Promise}>
<html
- className="server-html"
>
...
...",
<script>
<Next.js Internal Component>
<RootLayout params={Promise}>
<html
- className="server-html"
>
...
...",
"description": "A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Console Error",
......@@ -187,14 +184,13 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<RootLayout params={Promise}>
<html
- className="server-html"
>
...
...",
<Next.js Internal Component>
<RootLayout params={Promise}>
<html
- className="server-html"
>
...
...",
"description": "A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Console Error",
......@@ -226,17 +222,16 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<header>
+ second
- <footer className="3">
...
...
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<header>
+ second
- <footer className="3">
...
...
...",
...
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Recoverable Error",
......@@ -348,16 +343,15 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Page params={Promise} searchParams={Promise}>
<table>
<tbody>
<tr>
> test
...
<Next.js Internal Component>
<Page params={Promise} searchParams={Promise}>
<table>
<tbody>
<tr>
> test
...
...",
...
...",
"description": "In HTML, text nodes cannot be a child of <tr>.
This will cause a hydration error.",
"environmentLabel": null,
......@@ -460,18 +454,17 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<Suspense fallback={<p>}>
<header>
+ <main className="second">
- <footer className="3">
...
...
<Next.js Internal Component>
<Mismatch params={Promise} searchParams={Promise}>
<div className="parent">
<Suspense fallback={<p>}>
<header>
+ <main className="second">
- <footer className="3">
...
...
...",
...
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Recoverable Error",
......@@ -575,16 +568,15 @@ describe('Error overlay for hydration errors in App router', () => {
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Next.js Internal Component>
<Page params={Promise} searchParams={Promise}>
<Next.js Internal Component>
<Page params={Promise} searchParams={Promise}>
<div>
<div>
<div>
> <p>
> <div>
...
> <p>
> <div>
...
...",
...
...",
"description": "In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
......
......@@ -4,11 +4,6 @@ import stripAnsi from 'strip-ansi'
import { retry } from 'next-test-utils'
const bundlerName = process.env.IS_TURBOPACK_TEST ? 'Turbopack' : 'Webpack'
const enableNewScrollHandler =
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER !== 'false'
const innerScrollAndMaybeFocusHandlerName = enableNewScrollHandler
? 'InnerScrollHandlerNew'
: 'InnerScrollAndFocusHandlerOld'
function setupLogCapture() {
const logs: string[] = []
......@@ -382,26 +377,25 @@ describe(`Terminal Logging (${bundlerName})`, () => {
https://react.dev/link/hydration-mismatch
...
<RenderFromTemplateContext>
<ScrollAndMaybeFocusHandler cacheNode={{rsc:{...}, ...}}>
<${innerScrollAndMaybeFocusHandlerName} focusAndScrollRef={{scrollRef:null, ...}} cacheNode={{rsc:{...}, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name="hydration-..." loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary>
<RedirectErrorBoundary router={{...}}>
<InnerLayoutRouter url="/hydration..." tree={[...]} params={{}} cacheNode={{rsc:{...}, ...}} ...>
<SegmentViewNode type="page" pagePath="hydration-...">
<SegmentTrieNode>
<ClientPageRoot Component={function Page} serverProvidedParams={{...}}>
<Page params={Promise} searchParams={Promise}>
<div>
<p>
+ client
- server
...
<ScrollAndMaybeFocusHandler cacheNode={{rsc:{...}, ...}}>
<InnerScrollAndMaybeFocusHandler focusAndScrollRef={{scrollRef:null, ...}} cacheNode={{rsc:{...}, ...}}>
<ErrorBoundary errorComponent={undefined} errorStyles={undefined} errorScripts={undefined}>
<LoadingBoundary name="hydration-..." loading={null}>
<HTTPAccessFallbackBoundary notFound={undefined} forbidden={undefined} unauthorized={undefined}>
<RedirectBoundary>
<RedirectErrorBoundary router={{...}}>
<InnerLayoutRouter url="/hydration..." tree={[...]} params={{}} cacheNode={{rsc:{...}, ...}} ...>
<SegmentViewNode type="page" pagePath="hydration-...">
<SegmentTrieNode>
<ClientPageRoot Component={function Page} serverProvidedParams={{...}}>
<Page params={Promise} searchParams={Promise}>
<div>
<p>
+ client
- server
...
...
...
...
at <unknown> (https://react.dev/link/hydration-mismatch)
at p (<anonymous>)
......
......@@ -27,7 +27,7 @@ describe('server-side dev errors', () => {
if (/^[✓⚠△] /.test(trimmed)) return false
// Individual entries under the `- Experiments` header are indented and
// use status glyphs (✓ enabled, ⨯ disabled, · value), e.g.
// ` ⨯ appNewScrollHandler (disabled by ...)`. Only these banner entries
// ` ⨯ exampleFlag (disabled by ...)`. Only these banner entries
// are indented; real dev errors start at column 0 (`⨯ ReferenceError:
// ...`), so key off the leading indentation to avoid dropping them.
if (/^\s+[✓⚠△⨯·] /.test(item)) return false
......
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
const enableNewScrollHandler =
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER !== 'false'
// The new handler leaves focus on the clicked link; the old handler focuses the
// navigated segment.
describe('navigation-focus', () => {
const { next } = nextTestSetup({
files: __dirname,
......@@ -18,17 +13,9 @@ describe('navigation-focus', () => {
await retry(async () => {
// Good debug info is a moving target. Use Playwright traces to find out
// what was focused if this fails
if (enableNewScrollHandler) {
expect(
await browser.eval(() => document.activeElement.getAttribute('href'))
).toBe('/interactive-segment')
} else {
expect(
await browser.eval(() =>
document.activeElement.getAttribute('data-testid')
)
).toBe('segment-container')
}
expect(
await browser.eval(() => document.activeElement.getAttribute('href'))
).toBe('/interactive-segment')
})
})
......@@ -37,17 +24,9 @@ describe('navigation-focus', () => {
await browser.elementByCss('a[href="/scrollable-segment"]').click()
await retry(async () => {
if (enableNewScrollHandler) {
expect(
await browser.eval(() => document.activeElement.getAttribute('href'))
).toBe('/scrollable-segment')
} else {
expect(
await browser.eval(() =>
document.activeElement.getAttribute('data-testid')
)
).toBe('segment-container')
}
expect(
await browser.eval(() => document.activeElement.getAttribute('href'))
).toBe('/scrollable-segment')
})
})
......
import { nextTestSetup } from 'e2e-utils'
import { getTitle, retry, waitFor } from 'next-test-utils'
// bump this every time you want to validate flakiness: 1
describe('app dir - navigation', () => {
const { next, isNextDev, isNextStart, isNextDeploy } = nextTestSetup({
files: __dirname,
......
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe.each([false, true])(
'parallel-routes-empty-fragment-scroll (appNewScrollHandler: %s)',
(appNewScrollHandler) => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
experimental: {
appNewScrollHandler,
},
},
})
it('preserves scroll when an empty intercepted modal is the only changed slot', async () => {
const browser = await next.browser('/modal')
describe('parallel-routes-empty-fragment-scroll', () => {
const { next } = nextTestSetup({
files: __dirname,
})
await browser.eval('window.scrollTo(0, 1200)')
const initialScroll = await browser.eval('window.scrollY')
expect(initialScroll).toBeGreaterThan(0)
it('preserves scroll when an empty intercepted modal is the only changed slot', async () => {
const browser = await next.browser('/modal')
await browser.elementByCss('#open-empty-modal').click()
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open`)
})
await browser.eval('window.scrollTo(0, 1200)')
const initialScroll = await browser.eval('window.scrollY')
expect(initialScroll).toBeGreaterThan(0)
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
)
expect(await browser.eval('window.scrollY')).toBe(initialScroll)
await browser.elementByCss('#open-empty-modal').click()
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open`)
})
it('does not blur focus when the empty slot cannot handle scroll', async () => {
const browser = await next.browser('/modal')
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
)
expect(await browser.eval('window.scrollY')).toBe(initialScroll)
})
it('does not blur focus when the empty slot cannot handle scroll', async () => {
const browser = await next.browser('/modal')
await browser.eval(`
await browser.eval(`
window.scrollTo(0, 1200)
document.getElementById('focus-target').focus({ preventScroll: true })
document.getElementById('open-empty-modal').click()
`)
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open`)
})
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
)
expect(await browser.eval('document.activeElement.id')).toBe(
'focus-target'
)
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open`)
})
it('consumes a missing hash without scrolling or blurring', async () => {
const browser = await next.browser('/modal')
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
)
expect(await browser.eval('document.activeElement.id')).toBe('focus-target')
})
const initialScroll = await browser.eval(`
it('consumes a missing hash without scrolling or blurring', async () => {
const browser = await next.browser('/modal')
const initialScroll = await browser.eval(`
window.scrollTo(0, 1200)
document.getElementById('focus-target').focus({ preventScroll: true })
document.getElementById('open-modal-missing-hash').click()
window.scrollY
`)
await retry(async () => {
expect(await browser.url()).toBe(
`${next.url}/modal/visible#missing-target`
)
})
await retry(async () => {
expect(await browser.elementByCss('#visible-modal').text()).toBe(
'Visible modal'
)
})
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
await retry(async () => {
expect(await browser.url()).toBe(
`${next.url}/modal/visible#missing-target`
)
expect(await browser.eval('window.scrollY')).toBe(initialScroll)
expect(await browser.eval('document.activeElement.id')).toBe(
'focus-target'
})
await retry(async () => {
expect(await browser.elementByCss('#visible-modal').text()).toBe(
'Visible modal'
)
})
it('scrolls to a real hash target', async () => {
const browser = await next.browser('/modal')
await browser.eval(
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
)
expect(await browser.eval('window.scrollY')).toBe(initialScroll)
expect(await browser.eval('document.activeElement.id')).toBe('focus-target')
})
await browser.elementByCss('#open-empty-modal-real-hash').click()
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open#hash-target`)
})
it('scrolls to a real hash target', async () => {
const browser = await next.browser('/modal')
await retry(async () => {
const targetTop = await browser.eval(
"document.getElementById('hash-target').getBoundingClientRect().top"
)
expect(Math.abs(targetTop)).toBeLessThan(1)
})
await browser.elementByCss('#open-empty-modal-real-hash').click()
await retry(async () => {
expect(await browser.url()).toBe(`${next.url}/modal/open#hash-target`)
})
await retry(async () => {
const targetTop = await browser.eval(
"document.getElementById('hash-target').getBoundingClientRect().top"
)
expect(Math.abs(targetTop)).toBeLessThan(1)
})
}
)
})
})
import { nextTestSetup, type Playwright } from 'e2e-utils'
import { check, assertNoConsoleErrors, retry } from 'next-test-utils'
const enableNewScrollHandler =
process.env.__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER !== 'false'
describe('router autoscrolling on navigation', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
......@@ -319,12 +316,6 @@ describe('router autoscrolling on navigation', () => {
expect(
await browser.eval('document.documentElement.scrollHeight')
).toBeGreaterThan(0)
if (enableNewScrollHandler) {
await waitForScrollToComplete(browser, { x: 0, y: 0 })
} else {
await expect(
waitForScrollToComplete(browser, { x: 0, y: 0 })
).rejects.toThrow()
}
await waitForScrollToComplete(browser, { x: 0, y: 0 })
})
})
......@@ -39,8 +39,6 @@ describe('Config Experimental Warning', () => {
experimental: {
// We enable this in some CI shards
strictRouteTypes: false,
// We disable this in some CI shards
appNewScrollHandler: true,
},
},
})
......@@ -103,8 +101,6 @@ describe('Config Experimental Warning', () => {
workerThreads: false,
// We enable this in some CI shards
strictRouteTypes: false,
// We disable this in some CI shards
appNewScrollHandler: true,
}
})
`,
......
......@@ -35,7 +35,7 @@ function extractErrorBlock(output: string, errorTitle: string): string {
// path (e.g. `⨯ ./app/file.js`). In prod mode, errors start with a bare
// file-path line above the title. Match `⨯ ./` specifically so we don't latch
// onto unrelated `⨯` markers in the startup output, such as the experimental
// features list (e.g. `⨯ appNewScrollHandler (disabled by ...)`).
// features list (e.g. `⨯ exampleFlag (disabled by ...)`).
const markerIdx = beforeTitle.lastIndexOf('⨯ ./')
let startIdx: number
if (markerIdx !== -1) {
......
......@@ -499,10 +499,6 @@ export class NextInstance {
if (process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS) {
process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS = process.env.NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS
}
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
}
`
)
......
......@@ -433,11 +433,6 @@ export class NextDeployInstance extends NextInstance {
`NEXT_PRIVATE_EXPERIMENTAL_CACHED_NAVIGATIONS=${process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS}`
)
}
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.IS_TURBOPACK_TEST) {
additionalEnv.push(`IS_TURBOPACK_TEST=1`)
}
......
......@@ -1541,8 +1541,7 @@ const nextjsClientComponentNames = [
'HTTPAccessFallbackBoundary',
'HTTPAccessFallbackErrorBoundary',
'InnerLayoutRouter',
'InnerScrollAndFocusHandlerOld',
'InnerScrollHandlerNew',
'InnerScrollAndMaybeFocusHandler',
'RedirectBoundary',
'RedirectErrorBoundary',
'RenderFromTemplateContext',
......
......@@ -52,7 +52,6 @@ describe('build-output-prerender', () => {
✓ Running next.config.js took N
- Cache Components enabled
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
· staticGenerationMaxConcurrency: 1
✓ strictRouteTypes (enabled by \`__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES\`)"
`)
......@@ -62,7 +61,6 @@ describe('build-output-prerender', () => {
✓ Running next.config.js took N
- Cache Components enabled
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
· staticGenerationMaxConcurrency: 1"
`)
} else {
......@@ -71,7 +69,6 @@ describe('build-output-prerender', () => {
✓ Running next.config.js took N
- Cache Components enabled
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
· staticGenerationMaxConcurrency: 1
✓ strictRouteTypes (enabled by \`__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES\`)"
`)
......@@ -193,7 +190,6 @@ describe('build-output-prerender', () => {
- Cache Components enabled
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
· staticGenerationMaxConcurrency: 1
......@@ -208,7 +204,6 @@ describe('build-output-prerender', () => {
- Cache Components enabled
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
......@@ -222,7 +217,6 @@ describe('build-output-prerender', () => {
- Cache Components enabled
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
......@@ -376,22 +370,19 @@ describe('build-output-prerender', () => {
"▲ Next.js x.y.z (Turbopack)
✓ Running next.config took N
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ strictRouteTypes (enabled by \`__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES\`)"
`)
} else if (isRspack) {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z (Rspack)
✓ Running next.config took N
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)"
- Experiments (use with caution):"
`)
} else {
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
"▲ Next.js x.y.z (webpack)
✓ Running next.config took N
- Experiments (use with caution):
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
✓ strictRouteTypes (enabled by \`__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES\`)"
`)
}
......@@ -459,7 +450,6 @@ describe('build-output-prerender', () => {
✓ Running next.config took N
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
✓ strictRouteTypes (enabled by \`__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES\`)
......@@ -472,7 +462,6 @@ describe('build-output-prerender', () => {
✓ Running next.config took N
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
......@@ -484,7 +473,6 @@ describe('build-output-prerender', () => {
✓ Running next.config took N
- Experiments (use with caution):
✓ allowDevelopmentBuild (enabled by \`--debug-prerender\`)
⨯ appNewScrollHandler (disabled by \`__NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER\`)
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
⨯ serverMinification (disabled by \`--debug-prerender\`)
✓ serverSourceMaps (enabled 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