fix(deck): deep links land on the right slide without a flash

Seed the slide index from the URL hash synchronously at setup instead of
after mount, so opening …/#/7 renders slide 7 immediately (no flash of
slide 1 and no on-load transition).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Patrick Mulligan 2026-07-31 18:06:56 +02:00
commit 49ad78360a

View file

@ -12,7 +12,9 @@ export function useDeck(total: number) {
return m ? clamp(parseInt(m[1], 10) - 1) : 0
}
const index = ref(0)
// seed from the hash synchronously so deep links (…/#/7) land on the right
// slide at first paint — no flash of slide 1 and no on-load transition.
const index = ref(readHash())
const direction = ref<1 | -1>(1)
function goto(n: number) {
@ -43,7 +45,6 @@ export function useDeck(total: number) {
}
onMounted(() => {
index.value = readHash()
if (!window.location.hash) window.location.hash = '#/1'
window.addEventListener('keydown', onKey)
window.addEventListener('hashchange', onHash)