TanStackT
TanStackโ€ข10mo agoโ€ข
10 replies
urgent-maroon

Automatic code splitting not working as expected

I'm using tanstack start for a project and I noticed that the automatic code splitting doesn't seem to be working as expected. In the network tab I notice it downloading components and imports that are not used in the route that the user loaded (I created a completely new empty test route to ensure its not importing anything), but components/imports from other pages are still downloaded.

For example, this userProgress component is being fetched even though it's not used on this page, and searching throughout my project I can see it's only imported in other different routes (i.e. it's not accidentally being imported in some shared component or layout).

I would expect that this component would only be fetched when loading a page that imports it, or prefetching that page (e.g. on hover for a link). But it seems that automatic code splitting is not functioning and everything is always being fetched regardless of if it is used.

I've also tried setting the tsr: { autoCodeSplitting: true } option but that made no difference (I believe this is enabled by default in tanstack start)

Any help resolving this will be much appreciated ๐Ÿ˜ƒ
image.png
image.png
Was this page helpful?