Skip to content
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

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

Merged
merged 4 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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>
</>
)
}
Expand Down
Expand Up @@ -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)
})

Expand Down