perf: split vendor bundle into lazy chunks via manualChunks#145
Conversation
Single index chunk had grown to ~5 MB (1.4 MB gzip) because all node_modules fell into one Rollup output chunk. This adds a manualChunks function that bins every major library into its own named chunk (vendor-react, vendor-radix, vendor-tanstack, vendor-supabase, vendor-framer, vendor-icons, vendor-i18n, vendor-sentry, vendor-mapbox, vendor-sip, vendor-elevenlabs, vendor-forms, vendor-date, vendor-pdf, vendor-zod, vendor-dnd, vendor-virtual, vendor-ui-utils, vendor-xlsx, vendor-panels, vendor-dompurify, vendor-protobuf, vendor-hotkeys, vendor-utils, vendor-polyfills, vendor-router). Result: app chunk 5 013 KB → 1 075 KB (gzip 1 410 KB → 303 KB). All vendor chunks are separately cacheable. Tests 48/48 pass. https://claude.ai/code/session_01Gwdas9LekmByg4mbQzymUr
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughO PR otimiza a estratégia de divisão de chunks do Vite para produção. Altera a assinatura do callback ChangesOtimização de chunks Vite
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
No issues found across 1 file
Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more
Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 106acbe3de
ℹ️ 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".
| ) return "vendor-polyfills"; | ||
|
|
||
| // Everything else in node_modules goes to a single misc vendor chunk | ||
| return "vendor-misc"; |
There was a problem hiding this comment.
Avoid circular dependency between vendor chunks
The catch-all vendor-misc assignment creates a circular chunk graph with vendor-react (the current build emits Circular chunk: vendor-misc -> vendor-react -> vendor-misc), which means React core now depends on the misc bundle and defeats intended isolation/caching while risking brittle init order across chunks. This is introduced by routing all unmatched node_modules modules into one bucket; React’s transitive deps should stay in the React chunk (or be excluded from the misc catch-all) to break the cycle.
Useful? React with 👍 / 👎.
| if (!id.includes("node_modules")) return; | ||
|
|
||
| // React core — smallest, cached permanently | ||
| if (/\/react\/|\/react-dom\/|\/scheduler\//.test(id)) return "vendor-react"; |
There was a problem hiding this comment.
* Narrow React-core matcher to avoid capturing scoped /react libs
The React rule if (/\/react\/|\/react-dom\/|\/scheduler\//.test(id)) is overly broad and matches scoped packages that end with /react/ (e.g. @elevenlabs/react, @sentry/react) before their dedicated chunk rules run. With function-form manualChunks, this causes unintended dependency merging and cross-chunk links (in this build, vendor-react imports vendor-elevenlabs), which hurts caching boundaries and can force optional SDK code into the React chunk path. Restrict this matcher to the actual React packages (or move scoped */react rules ahead of it).
Useful? React with 👍 / 👎.
Summary
manualChunksfunction tovite.config.tsthat bins every major node_modules library into its own named, separately-cacheable chunkvendor-misccatch-allmotion-domandmotion-utilsalongsideframer-motion(framer-motion v12 ships these as separate npm packages)Result
78% reduction in main app chunk. Each vendor chunk is independently cacheable between deploys.
Test plan
npm run buildsucceeds (37s)https://claude.ai/code/session_01Gwdas9LekmByg4mbQzymUr
Generated by Claude Code
Summary by cubic
Split vendor code into lazy, named chunks using
vitemanualChunksto shrink the main app bundle and improve caching. Main chunk reduced by 78% (5,013 KB → 1,075 KB; gzip 1,410 KB → 303 KB), with vendor chunks cached across deploys.manualChunksinvite.config.tsto group majornode_moduleslibs into separatevendor-*chunks (+vendor-misc).motion-domandmotion-utilsalongsideframer-motionv12.vendor-mapbox(~1.6 MB) andvendor-misc(polyfills likecore-js).chunkSizeWarningLimitset to 600 KB; build and tests pass.Written for commit 106acbe. Summary will update on new commits. Review in cubic
Summary by CodeRabbit