Auto-reload stale code-split chunks + CLAUDE.md production-hardening checklist#32
Merged
Merged
Conversation
A code-split SPA orphans content-hashed chunks for already-open tabs on every deploy; a tab on a previous build 404s when it lazily imports a route chunk the new deploy has replaced. Listen for Vite's `vite:preloadError` and reload once to pick up the current build, with a timestamp guard so a genuinely broken deploy (the chunk stays missing) can't reload-loop.
Agent-facing orientation, the template's conventions (committed generated API client, adapter-boundary coercion, global mutation errors, chunk auto-reload), and a framework-level "production hardening" checklist distilled from running a sibling SPA through a high-traffic live event: stale code-split chunks, total sort comparators, coercing nullable fields at one chokepoint, void-promise handling, intentional-cancellation noise, and API/consumer schema coordination.
The `vite:preloadError` listener now surfaces a one-shot "new version available" toast (sonner) with a Reload action instead of calling `location.reload()` directly. The router uses `defaultPreload: "intent"`, so this event also fires for speculative hover preloads — an auto-reload would reload the page when a user merely hovers a stale link and discard any unsaved work. The toast lets the user reload on their own terms; `preventDefault()` suppresses the now-handled uncaught preload errors. Drops the sessionStorage reload-loop guard (no auto-reload to loop).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Transfers two general-case lessons from a sibling SPA's live-event launch into the template.
Changes
fix: recover from stale code-split chunks (
vite:preloadError)A code-split SPA orphans content-hashed chunks for already-open tabs on every deploy; a tab on a previous build 404s when it lazily imports a route chunk the new deploy has replaced.
main.tsxnow listens for Vite'svite:preloadErrorand surfaces a one-shot "new version available" toast (sonner) with a Reload action.It prompts rather than force-reloading on purpose: the router uses
defaultPreload: "intent", so the event also fires for speculative hover preloads — an auto-reload would reload the page when a user merely hovers a stale link, discarding any unsaved work. The toast lets the user reload on their own terms;preventDefault()suppresses the otherwise-uncaught preload errors.docs: add
CLAUDE.mdAgent-facing orientation, the template's conventions, and a framework-level production hardening checklist distilled from running a sibling SPA through a high-traffic live event: stale code-split chunks, total sort comparators, coercing nullable fields at one chokepoint,
void-promise handling, intentional-cancellation (AbortError) noise, API/consumer schema coordination, and green-CI ≠ verified-in-prod.Test plan
pnpm lint— pass (4 pre-existingreact-refreshwarnings in__root.tsx, unrelated)pnpm format:check— passpnpm tsc --noEmit— passpnpm test:run— 2 passedpnpm build— succeeds