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

prevent scroll when resetting page focus (#4065) #4846

Merged
merged 3 commits into from
May 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-vans-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix Safari scroll bug on ssr:false page reload
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function create_client({ target, session, base, trailing_slash }) {

getSelection()?.removeAllRanges();
root.tabIndex = -1;
root.focus();
root.focus({ preventScroll: true });

// restore `tabindex` as to prevent `root` from stealing input from elements
if (tabindex !== null) {
Expand Down
14 changes: 14 additions & 0 deletions packages/kit/test/apps/basics/src/routes/no-ssr/margin.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="container">
<span> ^this is not the top of the screen</span>
<div class="spacer" />
</div>

<style>
.container {
margin-top: 300px;
}

.spacer {
height: 1000px;
}
</style>
7 changes: 7 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ test.describe('Scrolling', () => {
await back();
expect(await page.evaluate(() => window.scrollY)).toBe(1000);
});

test('scroll position is top of page on ssr:false reload', async ({ page }) => {
await page.goto('/no-ssr/margin');
expect(await page.evaluate(() => window.scrollY)).toBe(0);
await page.reload();
expect(await page.evaluate(() => window.scrollY)).toBe(0);
});
});

test.describe.parallel('Imports', () => {
Expand Down