-
fix(web): recover from stale lazy chunks after a redeploy (#225)
Publish Container Image / Build and publish container image (push) Has been cancelled发布于
2026-06-11 15:37:28 +00:00 - fix(web): recover from stale lazy chunks after a redeploy
Opening a lazily-loaded panel (e.g. Add Raster Layer) on the deployed web
viewer could fail with "Failed to fetch dynamically imported module" while
working in incognito. Each GitHub Pages redeploy writes new content-hashed
chunks and deletes the previous build's chunks; a browser that cached an
earlier build (hashed assets are cached for hours) then dynamically imports a
panel whose chunk references a now-deleted chunk, which 404s.Register a
vite:preloadErrorhandler that reloads the page once to pull the
current build's import graph, with a cooldown guard so a genuinely broken
build does not loop. Web-only; the desktop build bundles its chunks locally.- Address review feedback
- Guard sessionStorage access in the vite:preloadError handler with try/catch,
mirroring diagnostics.ts. When storage is blocked (private modes, Safari ITP,
sandboxed iframes) the cooldown loop-guard cannot persist, so skip the reload
and let Vite surface the error rather than risk a refresh loop. Flagged by
Claude and CodeRabbit.
- Address Claude review feedback
- Extract isTauri into a tiny side-effect-free ./is-tauri module shared by
tauri-io (re-export) and stale-chunk-reload, removing the duplicate copy
without pulling tauri-io's heavy deps (shpjs/fflate) into the eager bundle. - Log the failed-chunk payload when reloading, and warn when the storage guard
is unavailable, so stale-chunk recoveries are observable. Read it from
event.payload (Vite uses a plain Event, not CustomEvent.detail). - Note the strict cooldown boundary in the reload test.
Co-authored-by: giswqs giswqs@users.noreply.github.com
下载附件