Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 3bf058c

Browse files
authored
fix deeplinks no matter previous scroll position (#1139)
1 parent d7b8ae1 commit 3bf058c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

runtime/src/app/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h
200200
if (deep_linked) {
201201
scroll = {
202202
x: 0,
203-
y: deep_linked.getBoundingClientRect().top
203+
y: deep_linked.getBoundingClientRect().top + scrollY
204204
};
205205
}
206206
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>A third tall page</h1>
2+
3+
<a href="tall-page#foo" id="top">link</a>
4+
<div style="height: 9999px"></div>
5+
<a href="tall-page#foo" id="bottom">link</a>

test/apps/scroll/test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ describe('scroll', function() {
8181
assert.ok(scrollY > 0);
8282
});
8383

84+
it('scrolls to a deeplink on a new page no matter the previous scroll position', async () => {
85+
await r.load('/a-third-tall-page#top');
86+
await r.sapper.start();
87+
await r.sapper.prefetchRoutes();
88+
89+
await r.page.click('a#top');
90+
await r.wait();
91+
const firstScrollY = await r.page.evaluate(() => window.scrollY);
92+
93+
await r.load('/a-third-tall-page#bottom');
94+
await r.sapper.start();
95+
await r.sapper.prefetchRoutes();
96+
97+
await r.page.click('a#bottom');
98+
await r.wait();
99+
const secondScrollY = await r.page.evaluate(() => window.scrollY);
100+
101+
assert.equal(firstScrollY, secondScrollY);
102+
});
103+
84104
it('survives the tests with no server errors', () => {
85105
assert.deepEqual(r.errors, []);
86106
});

0 commit comments

Comments
 (0)