fix(site): guard category scroll spy after unmount (#5297)

* fix(site): recover stale tabs after deploys and guard category scroll spy

- Reload once when a lazy chunk from an older deploy fails to load
  (vite:preloadError), and when VitePress swaps in a new hashmap.json and
  loads the new deploy's page chunk into the old app. The second case
  caused 'useIconStyleContext must be used with useIconStyleProvider' and
  'useExternalLibs must be used with externalLibs context', because the new
  chunk brings its own copy of the theme with new Symbol injection keys.
- Guard the category list scroll spy against running after unmount and
  clear its pending timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G9u8FfuEnhMTXSiKPJV3kb

* revert(site): drop deploy recovery in favor of Vercel skew protection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G9u8FfuEnhMTXSiKPJV3kb

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Eric Fennis
2026-11-25 15:33:19 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 0d2d161eee
commit 46b0ba6837
2 changed files with 10 additions and 2 deletions
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { ref, computed, watch, onBeforeUnmount } from 'vue'
import { useData } from 'vitepress'
import VPLink from 'vitepress/dist/client/theme-default/components/VPLink.vue'
import { isActive } from 'vitepress/dist/client/shared.js'
@@ -42,11 +42,16 @@ const marker = ref()
const { setActiveLinkDebounced } = useActiveAnchor(container, marker)
let activeLinkTimeout: ReturnType<typeof setTimeout> | undefined
watch(headers, () => {
setTimeout(() => {
clearTimeout(activeLinkTimeout)
activeLinkTimeout = setTimeout(() => {
setActiveLinkDebounced()
}, 200)
})
onBeforeUnmount(() => clearTimeout(activeLinkTimeout))
</script>
<template>
@@ -20,6 +20,8 @@ export function useActiveAnchor(container, marker) {
window.removeEventListener('scroll', setActiveLinkDebounced);
});
function setActiveLink() {
// Can run from a debounced scroll handler or a timeout after the component unmounted.
if (!container.value) return;
const links = [].slice.call(container.value.querySelectorAll('.outline-link'));
const anchors = [].slice
.call(document.querySelectorAll('.content .header-anchor'))
@@ -48,6 +50,7 @@ export function useActiveAnchor(container, marker) {
}
}
function activateLink(hash) {
if (!container.value || !marker.value) return;
if (prevActiveLink) {
prevActiveLink.classList.remove('active');
}