You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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