Skip to content

fix: recover from stale Vite chunk load failures#349

Merged
danshapiro merged 5 commits into
mainfrom
replacement/chunk-error-recovery-main-20260518
May 18, 2026
Merged

fix: recover from stale Vite chunk load failures#349
danshapiro merged 5 commits into
mainfrom
replacement/chunk-error-recovery-main-20260518

Conversation

@danshapiro
Copy link
Copy Markdown
Owner

Supersedes #337. PR #337 is stale/dev-based and carries unrelated old dev/fresh-agent history; this replacement branch is rebuilt from current origin/main and only ports the focused chunk-recovery work.

Ported commits/content:

  • 4ae106c feat: add withChunkErrorRecovery utility with broad chunk-error detection and circuit breaker
  • aa6e1f0 feat: add global vite:preloadError and unhandledrejection listener for chunk-error recovery
  • 890dcfb fix: wrap all 5 lazy imports with chunk-error recovery
  • 55c9db5 fix: reload page on chunk-load errors in ErrorBoundary Try Again with circuit breaker
  • fdbefe5 refactor: export shouldReload, add try/catch on sessionStorage, make initChunkErrorRecovery idempotent, add unit test coverage

Scope:

  • Detect stale Vite chunk-load failures across lazy imports, preload errors, and unhandled promise rejections.
  • Reload once through a sessionStorage circuit breaker instead of repeatedly reloading.
  • Add focused client unit coverage for the recovery utility, global recovery setup, and ErrorBoundary Try Again behavior.

Verification:

  • PASS: FRESHELL_TEST_SUMMARY="chunk recovery focused tests" npm run test:vitest -- --run test/unit/client/lib/import-retry.test.ts test/unit/client/lib/chunk-error-recovery.test.ts test/unit/client/components/ui/error-boundary.test.tsx (32 tests).
  • PARTIAL: PORT=3345 npm run build passed client typecheck and Vite client build, then failed server compilation in unchanged /home/user/code/freshell/.worktrees/chunk-error-recovery-main-20260518/server/mcp/freshell-tool.ts at lines 73 and 472. The same syntax exists on current origin/main; this branch does not touch that file.

Dan Shapiro added 5 commits May 18, 2026 00:33
…tion and circuit breaker

(cherry picked from commit 4ae106c)
…r chunk-error recovery

(cherry picked from commit aa6e1f0)
…initChunkErrorRecovery idempotent, add unit test coverage

(cherry picked from commit fdbefe5)
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3786f3804

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/import-retry.ts
Comment on lines +19 to +20
} catch {
return true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent reload loops when sessionStorage is blocked

When sessionStorage access throws (for example, users with storage/cookies disabled), shouldReload() currently returns true unconditionally, so every chunk-load failure triggers another window.location.reload() with no working cooldown. In that environment, a stale-chunk condition can trap the app in repeated reloads and make it unusable; the fallback path should use a non-persistent in-memory breaker or return false after the first attempted reload instead of always allowing reload.

Useful? React with 👍 / 👎.

@danshapiro danshapiro merged commit 8cd9ccf into main May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant