forked from vercel/next.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue where layout-router wouldn't auto-scroll if we imported sty…
…les or fonts (vercel#45487) fixes vercel#42492
- Loading branch information
Showing
9 changed files
with
358 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/e2e/app-dir/autoscroll-with-css-modules/app/[num]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Link from 'next/link' | ||
import styles from './styles.module.css' | ||
|
||
export default function Page({ params: { num } }) { | ||
return ( | ||
<div> | ||
{new Array(100).fill(0).map((_, i) => ( | ||
<div | ||
key={i} | ||
style={{ | ||
height: 100, | ||
width: 100, | ||
background: 'pink', | ||
margin: 10, | ||
}} | ||
> | ||
<Link id="lower" href={`/${Number(num) - 1}`}> | ||
lower | ||
</Link> | ||
<div>{num}</div> | ||
<Link id="higher" href={`/${Number(num) + 1}`}> | ||
higher | ||
</Link> | ||
</div> | ||
))} | ||
<div className={styles.square} /> | ||
</div> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
test/e2e/app-dir/autoscroll-with-css-modules/app/[num]/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.square { | ||
/* height: 100px; | ||
width: 100px; | ||
background: pink; | ||
margin: 10px;*/ | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/autoscroll-with-css-modules/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function Layout({ children }: any) { | ||
return ( | ||
<html | ||
style={{ | ||
overflowY: 'scroll', | ||
}} | ||
> | ||
<head /> | ||
<body style={{ margin: 0 }}>{children}</body> | ||
</html> | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
test/e2e/app-dir/autoscroll-with-css-modules/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
import { check } from 'next-test-utils' | ||
|
||
createNextDescribe( | ||
'router autoscrolling on navigation', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
type BrowserInterface = Awaited<ReturnType<typeof next['browser']>> | ||
|
||
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, | ||
options: { x: number; y: number } | ||
) => | ||
check(async () => { | ||
const top = await getTopScroll(browser) | ||
const left = await getLeftScroll(browser) | ||
return top === options.y && left === options.x | ||
? 'success' | ||
: JSON.stringify({ top, left }) | ||
}, 'success') | ||
|
||
const scrollTo = async ( | ||
browser: BrowserInterface, | ||
options: { x: number; y: number } | ||
) => { | ||
await browser.eval(`window.scrollTo(${options.x}, ${options.y})`) | ||
await waitForScrollToComplete(browser, options) | ||
} | ||
|
||
describe('vertical scroll when page imports css modules', () => { | ||
it('should scroll to top of document when navigating between to pages without layout when', async () => { | ||
const browser: BrowserInterface = await next.browser('/1') | ||
|
||
await scrollTo(browser, { x: 0, y: 1000 }) | ||
expect(await getTopScroll(browser)).toBe(1000) | ||
|
||
await browser.elementById('lower').click() | ||
await waitForScrollToComplete(browser, { x: 0, y: 0 }) | ||
}) | ||
|
||
it('should scroll when clicking in JS', async () => { | ||
const browser: BrowserInterface = await next.browser('/1') | ||
|
||
await scrollTo(browser, { x: 0, y: 1000 }) | ||
expect(await getTopScroll(browser)).toBe(1000) | ||
|
||
await browser.eval(() => document.getElementById('lower').click()) | ||
await waitForScrollToComplete(browser, { x: 0, y: 0 }) | ||
}) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import("next").NextConfig} */ | ||
module.exports = { | ||
reactStrictMode: true, | ||
experimental: { appDir: true }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.