fix: a new view opens at its top instead of the last view's scroll offset
CI and images / lint (push) Successful in 2s
CI and images / extension-version (push) Successful in 2s
CI and images / frontend-build (push) Successful in 21s
CI and images / backend-lint-and-test (push) Successful in 31s
CI and images / integration (push) Successful in 2m17s
CI and images / sign-extension (push) Successful in 3s
CI and images / build-agent (push) Successful in 6s
CI and images / build-web (push) Successful in 1m39s
CI and images / smoke-web (push) Successful in 55s
CI and images / promote (push) Skipped

The router had no scrollBehavior, so Settings entered from a scrolled feed
opened scrolled too, its heading and tab strip under the nav. Back/forward
restores the saved position, and a new query on the same view keeps its
place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR
This commit is contained in:
2026-09-24 16:03:38 -04:00
co-authored by Claude Opus 5.5
parent 7cc34b5724
commit ee59133b42
2 changed files with 40 additions and 2 deletions
+23 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import router, { FRONT_DOOR } from '../src/router.js'
import router, { FRONT_DOOR, scrollBehavior } from '../src/router.js'
describe('router', () => {
it('FRONT_DOOR is the post feed', () => {
@@ -74,4 +74,26 @@ describe('router', () => {
expect(r.name).toBe('series-read')
expect(r.meta.immersive).toBe(true)
})
describe('scrollBehavior', () => {
const at = (path) => ({ path, hash: '', matched: [{}] })
it('opens a new view at its top, not at the last view\'s offset', () => {
expect(scrollBehavior(at('/settings'), at('/latest'), null)).toEqual({ top: 0 })
})
it('back and forward return to where the entry was left', () => {
const saved = { left: 0, top: 1234 }
expect(scrollBehavior(at('/latest'), at('/settings'), saved)).toBe(saved)
})
it('a new query on the same view keeps its place', () => {
expect(scrollBehavior(at('/gallery'), at('/gallery'), null)).toBe(false)
})
it('the first navigation of a page load opens at the top', () => {
const initial = { path: '/', hash: '', matched: [] }
expect(scrollBehavior(at('/latest'), initial, null)).toEqual({ top: 0 })
})
})
})