Unverified Commit 050936c0 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

test(fix: Prevent page to scroll to top during data HMR) (#35744)

* fix: Prevent page to scroll to top during data HMR

* Add test for scroll position with gssp refreshing
parent 600e0b3e
......@@ -9,6 +9,8 @@ export default function Gsp(props) {
<>
<p id="change">change me</p>
<p id="props">{JSON.stringify(props)}</p>
<div style={{ height: 1000, width: 50, background: 'cyan' }}></div>
<p id="scroll-target">bottom</p>
</>
)
}
......
......@@ -163,7 +163,44 @@ describe('GS(S)P Server-Side Change Reloading', () => {
originalContent.replace('count = 1', 'count = 2')
)
await check(
async () =>
JSON.parse(await browser.elementByCss('#props').text()).count + '',
'2'
)
expect(await browser.eval('window.beforeChange')).toBe('hi')
await next.patchFile(page, originalContent)
})
it('should keep scroll position when updating from change in getStaticProps', async () => {
const browser = await webdriver(next.url, '/another')
await browser.eval(
'document.getElementById("scroll-target").scrollIntoView()'
)
const scrollPosition = await browser.eval(
'document.documentElement.scrollTop'
)
await browser.eval(`window.beforeChange = 'hi'`)
const props = JSON.parse(await browser.elementByCss('#props').text())
expect(props.count).toBe(1)
const page = 'pages/another/index.js'
const originalContent = await next.readFile(page)
await next.patchFile(
page,
originalContent.replace('count = 1', 'count = 2')
)
await check(
async () =>
JSON.parse(await browser.elementByCss('#props').text()).count + '',
'2'
)
expect(await browser.eval('window.beforeChange')).toBe('hi')
expect(await browser.eval('document.documentElement.scrollTop')).toBe(
scrollPosition
)
await next.patchFile(page, originalContent)
})
......
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