Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/core/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class View {
}

scrollToPosition({ x, y }) {
this.scrollRoot.scrollTo(x, y)
this.scrollRoot.scrollTo({ left: x, top: y, behavior: "instant" })
}

scrollToTop() {
Expand Down
26 changes: 26 additions & 0 deletions src/tests/fixtures/scroll_restoration_with_smooth_scroll.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scroll Restoration with Smooth Scroll</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<style>
html {
scroll-behavior: smooth;
}
li {
min-height: 50vh;
}
</style>
</head>
<body>
<ul>
<li id="one">One</li>
<li id="two">Two</li>
<li id="three">Three</li>
<li id="four">Four</li>
<li id="five">Five</li>
</ul>
</body>
</html>
16 changes: 16 additions & 0 deletions src/tests/functional/scroll_restoration_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@ test("returning from history", async ({ page }) => {
const { y: yAfterReturning } = await scrollPosition(page)
expect(yAfterReturning).not.toEqual(0)
})

test("returning from history with scroll-behavior: smooth restores scroll position instantly", async ({ page }) => {
await page.goto("/src/tests/fixtures/scroll_restoration_with_smooth_scroll.html")
await scrollToSelector(page, "#three")
const { y: yAfterScrolling } = await scrollPosition(page)
expect(yAfterScrolling).not.toEqual(0)

await page.goto("/src/tests/fixtures/bare.html")
await page.goBack()

// Scroll position should be restored instantly, not animated
// If scroll-behavior: smooth was applied, the position would still be 0 or near 0
// immediately after goBack() because the animation would be in progress
const { y: yAfterReturning } = await scrollPosition(page)
expect(yAfterReturning).not.toEqual(0)
})