Commit 3a4833af authored by Jimmy Lai's avatar Jimmy Lai

test: add failing test for #79571 - parallel routes sticky header blocks scroll-to-top

parent daca04d0
import Link from 'next/link'
export default function DefaultHeader() {
return (
<nav>
<Link href="/page-a" id="header-link-a">
Go to Page A
</Link>
{' | '}
<Link href="/page-b" id="header-link-b">
Go to Page B
</Link>
</nav>
)
}
import Link from 'next/link'
export default function HeaderPageA() {
return (
<nav>
<span id="header-page-a">Header: Page A</span>
{' | '}
<Link href="/page-a" id="header-link-a">
Go to Page A
</Link>
{' | '}
<Link href="/page-b" id="header-link-b">
Go to Page B
</Link>
</nav>
)
}
import Link from 'next/link'
export default function HeaderPageB() {
return (
<nav>
<span id="header-page-b">Header: Page B</span>
{' | '}
<Link href="/page-a" id="header-link-a">
Go to Page A
</Link>
{' | '}
<Link href="/page-b" id="header-link-b">
Go to Page B
</Link>
</nav>
)
}
export default function RootLayout({
children,
header,
}: {
children: React.ReactNode
header: React.ReactNode
}) {
return (
<html>
<body>
<div
style={{
position: 'sticky',
top: 0,
background: 'white',
zIndex: 100,
borderBottom: '1px solid #ccc',
padding: '10px',
}}
id="sticky-header"
>
{header}
</div>
<main>{children}</main>
</body>
</html>
)
}
import Link from 'next/link'
export default function PageA() {
return (
<div>
<h1 id="page-a-title">Page A</h1>
{/* Tall content to enable scrolling */}
<div
style={{
height: '2000px',
background: 'linear-gradient(#e0e0e0, #a0a0a0)',
}}
>
<p>Tall content to enable scrolling</p>
</div>
<Link href="/page-b" id="link-to-b">
Go to Page B
</Link>
</div>
)
}
export default function PageB() {
return (
<div>
<h1 id="page-b-title">Page B Content</h1>
{/* Tall content so the browser doesn't auto-scroll when page height changes */}
<div
style={{
height: '3000px',
background: 'linear-gradient(#c0d0e0, #8090a0)',
}}
>
<p>Tall content on page B</p>
</div>
</div>
)
}
import Link from 'next/link'
export default function Home() {
return (
<div>
<h1>Home Page</h1>
<Link href="/page-a" id="link-to-a">
Go to Page A
</Link>
</div>
)
}
/** @type {import('next').NextConfig} */
const nextConfig = {}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('parallel-routes-sticky-header-scroll', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// Reproduces https://github.com/vercel/next.js/issues/79571
// When a parallel route slot is rendered inside a sticky header,
// navigating between pages should still scroll to the top.
// The bug: all new CacheNodes share a single scrollRef, and the
// sticky header slot consumes it before the main content can scroll.
it('should scroll to the top when navigating between pages with a parallel route in a sticky header', async () => {
const browser = await next.browser('/page-a')
// Wait for page-a content to be visible
await browser.waitForElementByCss('#page-a-title')
// Scroll to the bottom of the page where the "Go to Page B" link is
await browser.eval('document.getElementById("link-to-b").scrollIntoView()')
// Verify we have actually scrolled down
await retry(async () => {
const scrollY = await browser.eval('window.scrollY')
expect(scrollY).toBeGreaterThan(500)
})
// Click the "Go to Page B" link at the bottom of the page
await browser.elementByCss('#link-to-b').click()
// Wait for Page B content to appear
await browser.waitForElementByCss('#page-b-title')
// The page should have scrolled back to the top.
// This fails because the sticky header's parallel route slot consumes the
// shared scrollRef (set in ppr-navigations.ts accumulateScrollRef) before
// the main content slot's scroll handler can use it.
await retry(async () => {
const scrollY = await browser.eval('window.scrollY')
expect(scrollY).toBe(0)
})
})
})
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