diff --git a/runtime/src/app/app.ts b/runtime/src/app/app.ts index 95b882fd0..e8a3f7198 100644 --- a/runtime/src/app/app.ts +++ b/runtime/src/app/app.ts @@ -200,7 +200,7 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h if (deep_linked) { scroll = { x: 0, - y: deep_linked.getBoundingClientRect().top + y: deep_linked.getBoundingClientRect().top + scrollY }; } } diff --git a/test/apps/scroll/src/routes/a-third-tall-page.svelte b/test/apps/scroll/src/routes/a-third-tall-page.svelte new file mode 100644 index 000000000..6da07f25f --- /dev/null +++ b/test/apps/scroll/src/routes/a-third-tall-page.svelte @@ -0,0 +1,5 @@ +

A third tall page

+ +link +
+link diff --git a/test/apps/scroll/test.ts b/test/apps/scroll/test.ts index f787d189c..30c269ffb 100644 --- a/test/apps/scroll/test.ts +++ b/test/apps/scroll/test.ts @@ -81,6 +81,26 @@ describe('scroll', function() { assert.ok(scrollY > 0); }); + it('scrolls to a deeplink on a new page no matter the previous scroll position', async () => { + await r.load('/a-third-tall-page#top'); + await r.sapper.start(); + await r.sapper.prefetchRoutes(); + + await r.page.click('a#top'); + await r.wait(); + const firstScrollY = await r.page.evaluate(() => window.scrollY); + + await r.load('/a-third-tall-page#bottom'); + await r.sapper.start(); + await r.sapper.prefetchRoutes(); + + await r.page.click('a#bottom'); + await r.wait(); + const secondScrollY = await r.page.evaluate(() => window.scrollY); + + assert.equal(firstScrollY, secondScrollY); + }); + it('survives the tests with no server errors', () => { assert.deepEqual(r.errors, []); });