fix: pre-declare buffer shim to avoid Vite cold-start optimizer race #4

Merged
deiussum merged 2 commits from fix-vite-optimizer-cold-start-race into develop 2026-09-18 22:13:09 -05:00
Owner

Summary

  • Adds vite-plugin-node-polyfills/shims/buffer to optimizeDeps.include in vite.config.ts so it's known during Vite's initial dependency scan instead of being discovered mid-session.
  • Fixes a cold-start race first flagged during the rename-to-tesserow change: on a fresh node_modules/.vite cache, the late-discovered Buffer shim (needed by pdfkit's standalone browser bundle) forced a mid-session re-optimize that raced in-flight chunk requests (e.g. the shared @mui/icons-material createSvgIcon chunk), producing a transient 404 and a full page reload.
  • Dev-experience only - optimizeDeps doesn't affect production builds.
  • Full root-cause diagnosis and alternatives considered are preserved in openspec/changes/archive/2026-09-18-fix-vite-optimizer-cold-start-race/.

Test plan

  • Reproduced the race on a genuinely cold node_modules/.vite cache before the fix
  • Verified 3 separate cold-cache npm run vite:dev runs post-fix show zero race indicators
  • Verified npm start (Tauri dev) launches cleanly with no panics; icon-serving modules load with no optimizer errors
  • Verified npm run package (production build) still succeeds, unaffected by the dev-only config change

🤖 Generated with Claude Code

## Summary - Adds `vite-plugin-node-polyfills/shims/buffer` to `optimizeDeps.include` in `vite.config.ts` so it's known during Vite's initial dependency scan instead of being discovered mid-session. - Fixes a cold-start race first flagged during the `rename-to-tesserow` change: on a fresh `node_modules/.vite` cache, the late-discovered Buffer shim (needed by pdfkit's standalone browser bundle) forced a mid-session re-optimize that raced in-flight chunk requests (e.g. the shared `@mui/icons-material` `createSvgIcon` chunk), producing a transient 404 and a full page reload. - Dev-experience only - `optimizeDeps` doesn't affect production builds. - Full root-cause diagnosis and alternatives considered are preserved in `openspec/changes/archive/2026-09-18-fix-vite-optimizer-cold-start-race/`. ## Test plan - [x] Reproduced the race on a genuinely cold `node_modules/.vite` cache before the fix - [x] Verified 3 separate cold-cache `npm run vite:dev` runs post-fix show zero race indicators - [x] Verified `npm start` (Tauri dev) launches cleanly with no panics; icon-serving modules load with no optimizer errors - [x] Verified `npm run package` (production build) still succeeds, unaffected by the dev-only config change 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pdfkit's standalone browser bundle references the global Buffer, which
vite-plugin-node-polyfills injects during esbuild's build pass - one
phase after Vite's initial dependency scan. On a cold node_modules/.vite
cache, this was discovered mid-session, forcing a re-optimize that
raced in-flight chunk requests (e.g. the @mui/icons-material shared
createSvgIcon chunk), producing a transient 404 and a full-reload.
Declaring the shim in optimizeDeps.include makes it known upfront.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Preserves the diagnosis of the Vite dependency-optimizer cold-start
race (root cause, alternatives considered, and verification results)
alongside the fix landed in the previous commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
deiussum merged commit 982b866c09 into develop 2026-09-18 22:13:09 -05:00
deiussum deleted branch fix-vite-optimizer-cold-start-race 2026-09-18 22:13:09 -05:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
deiussum/tesserow-backup!4
No description provided.