fix: poll for containers after route transition animation

Sidebar Right now polls every 100ms (up to 1s) for containers to
appear, instead of a single 200ms retry that missed animations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-30 09:35:06 +01:00
parent 0f80ac1415
commit eac6416569

View File

@@ -415,12 +415,19 @@ export function useControllerNav(containerRef?: { value: HTMLElement | null }) {
if (dest) {
focusEl(dest)
} else {
// Containers may not be rendered yet (async load after route change)
// Retry after a short delay
setTimeout(() => {
// Containers not rendered yet (route transition / animation in progress)
// Poll until they appear, up to 1s
let attempts = 0
const poll = setInterval(() => {
attempts++
const retryContainers = getContainers()
if (retryContainers[0]) focusEl(retryContainers[0])
}, 200)
if (retryContainers[0]) {
clearInterval(poll)
focusEl(retryContainers[0])
} else if (attempts >= 10) {
clearInterval(poll)
}
}, 100)
}
return
}