perf: enable route-level code splitting#298
Merged
Merged
Conversation
Turn on TanStack Router autoCodeSplitting so each route's component ships as its own lazy chunk instead of one monolithic bundle, and set defaultPreload: 'intent' so a route's chunk is prefetched on link hover/focus (no navigation latency on first visit). Measured (vite build): - entry chunk: 613.59 kB -> 84.03 kB - login page initial JS: ~892 kB -> ~608 kB raw (~280 -> ~203 kB gzip) - heavy feature code now demand-loaded: DraftingPage (49 kB), project detail (33 kB), projects (19 kB), resources, export, etc. routeTree.gen.ts is unchanged - this plugin version splits via a build-time transform, not by rewriting the generated tree. Closes #293
There was a problem hiding this comment.
Pull request overview
This PR enables TanStack Router’s automatic route-level code splitting in the Vite build and configures the router to preload split route chunks on user intent (hover/focus), reducing initial bundle size while keeping navigation responsive.
Changes:
- Enable
autoCodeSplitting: truein@tanstack/router-plugin/vite. - Set
defaultPreload: 'intent'on the router to preload route chunks on link hover/focus.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
vite.config.ts |
Enables TanStack Router automatic route-level code splitting at build time. |
src/lib/router.ts |
Configures default preload strategy (intent) to reduce perceived navigation latency with split chunks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
@kaseywright I just requested a Copilot review. I will wait for it and then I will ask for your review on this PR again |
kaseywright
approved these changes
Jun 9, 2026
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.
What
Enables TanStack Router
autoCodeSplittingso each route's component ships as its own lazy chunk instead of one monolithic bundle, plusdefaultPreload: 'intent'so a route's chunk is prefetched on link hover/focus — code-splitting without adding navigation latency on first visit.Closes #293.
Measured (per the ticket's "measure before/after" guardrail)
Real
vite buildnumbers:Heavy feature code is now demand-loaded, not in the initial bundle:
DraftingPage(49 kB), project detail (33 kB), projects (19 kB), resources/select(31 kB), export, users, legal, etc. A user who never opens the drafting editor never downloads TipTap.Verified at runtime (production build, real browser)
/legal/privacyfetched thelegal+privacychunks on demand (not present in the initial load) and rendered correctly — no blank screen, no broken Suspense.Notes
routeTree.gen.tsis intentionally unchanged — this@tanstack/router-pluginversion splits route components via a build-time transform, not by rewriting the generated tree. Diff is just the two config lines.logger). Deferring/lazy-initializing it would cut ~76 kB gzip from every page's initial load — bigger than this change. Worth a separate ticket; kept out here to stay focused and avoid premature scope.