How do stop pre-fetch ALL components?
When accessing http://localhost:3000/ and inspecting the network tab in dev tools, there are a lot of requests all the js file
For example,
It literally pre-fetch all components of the whole project. Is there a way to stop this? Here is the .cta file
16 Replies
other-emerald•4mo ago
probably needs autoCodeSplitting:true in the router-plugin config?
genetic-orangeOP•4mo ago
Hmm, things are not that simple. My setup is almost the same as this demo which is code-based routing and it showed the same problem for pre-fetching.
To confirm the problem, I apply this patch to the code which simply adds a Dummy page to the app. As long as the component is included by
createRoute
, it will be fetched. It wasn't even included in the route tree.
As suggested, I tried the automatic code splitting and I realised it only works for file-based routing. Does it mean I HAVE to do it manually like this guide https://tanstack.com/router/latest/docs/framework/react/guide/code-splitting#code-based-splitting showed?other-emerald•4mo ago
yes
we cannot possibly automatically split your code based routes
this needs conventions, and those are given by file based routing
genetic-orangeOP•4mo ago
Can the files be grouped and fetched in one request, instead of hundreads of small fetches?
other-emerald•4mo ago
which files
i think you are looking at the dev server, right?
you should run a build and then a preview
in case of non-split (either code or file based) you will just see a single bundle being built
genetic-orangeOP•4mo ago
Oh thanks, that make sense. I guess it only bundles the files in production.
other-emerald•4mo ago
yes
genetic-orangeOP•4mo ago
Is there a better example than https://tanstack.com/router/latest/docs/framework/react/guide/code-splitting#code-based-splitting ?
I am having a hard time translating this to a real probject. What does the import fn take?
genetic-orangeOP•4mo ago
Here is the diff
other-emerald•4mo ago
import
is just a regular ESM importgenetic-orangeOP•4mo ago
Given this file structure
other-emerald•4mo ago
just
import('./pages/Dummy');
its just the path to your filegenetic-orangeOP•4mo ago
Thank you very much, much appreciated!
Do you think I could submit a PR to fix the doc https://tanstack.com/router/latest/docs/framework/react/guide/code-splitting#code-based-splitting? Is it a mistake?
other-emerald•4mo ago
not a mistake, this just implies that the file is named
posts.lazy.tsx
you can name it whatever you likegenetic-orangeOP•4mo ago
but it doesn't match with the code above?
other-emerald•4mo ago
ah right
yes so one needs to be changed then
// src/posts.tsx
should be // src/posts.lazy.tsx