Dev server performance issues with [email protected] in Vite – eager loading of all routes #13463
Replies: 1 comment 3 replies
-
Great question @bk-mja ! We definitely strive for a near-zero startup time. Unfortunately, a core part of what React Router does is the routing part and that relies on having knowledge of all routes. Otherwise we wouldn't what route would match a particular URL. We did ship a way for the client to lazily discover routes in Remix and React Router ("lazy route discovery" or "fog of war"). That said, we haven't tried to optimize how the server build gets all of those routes. We can definitely look into that. Also, we have some prototypes of what RSC in React Router might look like and are hopeful that RSC can provide a way to actually solve this problem once and for all (i.e. making server-side route access truly lazy/on-demand). So stay tuned for that!
Out of curiosity, could you share some additional stats?
Ideally, if you had a reproduction you could share that would be immensely helpful so we can test it out on different machines to account for speed differences in hardware. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm running into a performance bottleneck during development with [email protected] (framework mode) and [email protected]. Every time we restart the dev server, it's painfully slow—Vite appears to be transforming every single file in our /app directory on startup.
After digging in with Vite debug flags and vite-plugin-inspect, I found the cause: the virtual:react-router/server-build module is importing all routes eagerly. In our app, that's over 300 routes, each importing many components, so this adds significant overhead.
My understanding was that Vite transforms files on-demand during dev, not all at once. But in this case, due to the way routes are imported, it looks like everything is being pulled in up front on server start. That seems to defeat the purpose of Vite’s fast dev experience.
My questions:
Is there a way to make route imports on the server lazy, to avoid eagerly loading everything at dev startup?
Are there known patterns or workarounds for optimizing this in a large app using React Router’s framework mode?
Or is my understanding of how Vite dev server works in this context flawed?
Environment:
[email protected] (framework mode)
[email protected]
Custom Node server
~300 routes, each importing multiple components. Configured in the routes.ts file as per the framerwork docs
I'm happy to share more details about our setup if helpful.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions