-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure metadata doesn't break scroll-to-top on navigation #74748
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,7 +374,9 @@ describe('Error overlay for hydration errors in App router', () => { | |
const { session, browser } = sandbox | ||
await session.openRedbox() | ||
|
||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
await retry(async () => { | ||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
}) | ||
|
||
// FIXME: Should also have "text nodes cannot be a child of tr" | ||
expect(await session.getRedboxDescription()).toMatchInlineSnapshot( | ||
|
@@ -439,7 +441,6 @@ describe('Error overlay for hydration errors in App router', () => { | |
<RedirectBoundary> | ||
<RedirectErrorBoundary router={{...}}> | ||
<InnerLayoutRouter url="/" tree={[...]} cacheNode={{lazyData:null, ...}} segmentPath={[...]}> | ||
<__next_metadata_boundary__> | ||
<ClientPageRoot Component={function Page} searchParams={{}} params={{}}> | ||
<Page params={Promise} searchParams={Promise}> | ||
> <table> | ||
|
@@ -567,7 +568,9 @@ describe('Error overlay for hydration errors in App router', () => { | |
const { session, browser } = sandbox | ||
await session.openRedbox() | ||
|
||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
await retry(async () => { | ||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
}) | ||
Comment on lines
-570
to
+573
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already did that in some other instances where we assert on multiple errors. |
||
|
||
const description = await session.getRedboxDescription() | ||
expect(description).toContain( | ||
|
@@ -665,7 +668,9 @@ describe('Error overlay for hydration errors in App router', () => { | |
const { session, browser } = sandbox | ||
await session.openRedbox() | ||
|
||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
await retry(async () => { | ||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
}) | ||
|
||
const description = await session.getRedboxDescription() | ||
expect(description).toEqual(outdent` | ||
|
@@ -718,7 +723,9 @@ describe('Error overlay for hydration errors in App router', () => { | |
const { session, browser } = sandbox | ||
await session.openRedbox() | ||
|
||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
await retry(async () => { | ||
expect(await getRedboxTotalErrorCount(browser)).toBe(2) | ||
}) | ||
|
||
const description = await session.getRedboxDescription() | ||
expect(description).toContain( | ||
|
@@ -895,19 +902,18 @@ describe('Error overlay for hydration errors in App router', () => { | |
<RedirectBoundary> | ||
<RedirectErrorBoundary router={{...}}> | ||
<InnerLayoutRouter url="/" tree={[...]} cacheNode={{lazyData:null, ...}} segmentPath={[...]}> | ||
<__next_metadata_boundary__> | ||
<ClientPageRoot Component={function Page} searchParams={{}} params={{}}> | ||
<Page params={Promise} searchParams={Promise}> | ||
<ClientPageRoot Component={function Page} searchParams={{}} params={{}}> | ||
<Page params={Promise} searchParams={Promise}> | ||
<div> | ||
<div> | ||
<div> | ||
<div> | ||
<div> | ||
<Mismatch> | ||
<p> | ||
<span> | ||
... | ||
+ client | ||
- server" | ||
<Mismatch> | ||
<p> | ||
<span> | ||
... | ||
+ client | ||
- server" | ||
`) | ||
} else { | ||
expect(fullPseudoHtml).toMatchInlineSnapshot(` | ||
|
@@ -916,19 +922,18 @@ describe('Error overlay for hydration errors in App router', () => { | |
<RedirectBoundary> | ||
<RedirectErrorBoundary router={{...}}> | ||
<InnerLayoutRouter url="/" tree={[...]} cacheNode={{lazyData:null, ...}} segmentPath={[...]}> | ||
<__next_metadata_boundary__> | ||
<ClientPageRoot Component={function Page} searchParams={{}} params={{}}> | ||
<Page params={Promise} searchParams={Promise}> | ||
<ClientPageRoot Component={function Page} searchParams={{}} params={{}}> | ||
<Page params={Promise} searchParams={Promise}> | ||
<div> | ||
<div> | ||
<div> | ||
<div> | ||
<div> | ||
<Mismatch> | ||
<p> | ||
<span> | ||
... | ||
+ client | ||
- server" | ||
<Mismatch> | ||
<p> | ||
<span> | ||
... | ||
+ client | ||
- server" | ||
`) | ||
} | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Metadata } from 'next' | ||
|
||
export const metadata: Metadata = { | ||
keywords: ['new-metadata'], | ||
} | ||
export default function Page() { | ||
return ( | ||
<> | ||
{ | ||
// Repeat 500 elements | ||
Array.from({ length: 500 }, (_, i) => ( | ||
<div key={i}>{i}</div> | ||
)) | ||
} | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
import webdriver from 'next-webdriver' | ||
import webdriver, { type BrowserInterface } from 'next-webdriver' | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { check } from 'next-test-utils' | ||
import { check, assertNoConsoleErrors, retry } from 'next-test-utils' | ||
|
||
describe('router autoscrolling on navigation', () => { | ||
const { next, isNextDev } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
type BrowserInterface = Awaited<ReturnType<typeof webdriver>> | ||
|
||
const getTopScroll = async (browser: BrowserInterface) => | ||
await browser.eval('document.documentElement.scrollTop') | ||
|
||
const getLeftScroll = async (browser: BrowserInterface) => | ||
await browser.eval('document.documentElement.scrollLeft') | ||
|
||
const waitForScrollToComplete = ( | ||
browser, | ||
const waitForScrollToComplete = async ( | ||
browser: BrowserInterface, | ||
options: { x: number; y: number } | ||
) => | ||
check(async () => { | ||
) => { | ||
await retry(async () => { | ||
const top = await getTopScroll(browser) | ||
const left = await getLeftScroll(browser) | ||
return top === options.y && left === options.x | ||
? 'success' | ||
: JSON.stringify({ top, left }) | ||
}, 'success') | ||
expect({ top, left }).toEqual({ top: options.y, left: options.x }) | ||
}) | ||
await assertNoConsoleErrors(browser) | ||
} | ||
|
||
const scrollTo = async ( | ||
browser: BrowserInterface, | ||
|
@@ -93,6 +91,23 @@ describe('router autoscrolling on navigation', () => { | |
await browser.eval(`window.router.push("/10/100/100/1000/page2")`) | ||
await waitForScrollToComplete(browser, { x: 0, y: 0 }) | ||
}) | ||
|
||
it('should scroll to top of document with new metadata', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
|
||
// scroll to bottom | ||
await browser.eval( | ||
`window.scrollTo(0, ${await browser.eval('document.documentElement.scrollHeight')})` | ||
) | ||
// Just need to scroll by something | ||
expect(await getTopScroll(browser)).toBeGreaterThan(0) | ||
|
||
await browser.elementByCss('[href="/new-metadata"]').click() | ||
expect( | ||
await browser.eval('document.documentElement.scrollHeight') | ||
).toBeGreaterThan(0) | ||
await waitForScrollToComplete(browser, { x: 0, y: 0 }) | ||
}) | ||
}) | ||
|
||
describe('horizontal scroll', () => { | ||
|
@@ -153,7 +168,7 @@ describe('router autoscrolling on navigation', () => { | |
return ( | ||
content + | ||
` | ||
\\\\ Add this meaningless comment to force refresh | ||
// Add this meaningless comment to force refresh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't a comment and just triggered a build error polluting test assertions i.e. fixes
|
||
` | ||
) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Fragment Refs, we wouldn't have this problem. We'd just iterate over the children and skip over metadata.
Or rather skip over any hoistable