Repository navigation
Replies: 2 comments
|
i'd start with the route imports, since you found that production loads everything too if they're all coming through something like then i'd lazy-load the routes, rather than each component. for react, with a default export: import { lazy, Suspense } from "react"
const Reports = lazy(() => import("./pages/Reports"))
function ReportsRoute() {
return (
<Suspense fallback={<div>loading...</div>}>
<Reports />
</Suspense>
)
}the also check that devtools' "disable cache" is unchecked when comparing refreshes. if it's still slow,
can you share how your routes are imported? that should help narrow down where the 40mb is coming from |
|
This is the classic Webpack→Vite difference, and HMR being fast is the clue: in dev, Vite serves your app as unbundled ES modules, so on first load (and every full refresh) the browser has to fetch your entire eagerly-imported module graph before first paint. Webpack was bundling — and in your case evidently code-splitting — so a refresh felt instant by comparison. HMR only swaps the changed modules, which is why it feels fine. In rough order of impact:
Measure with the Network tab on a refresh: count the requests. Dev-mode Vite apps commonly load hundreds (or thousands) of module requests — the fixes above are about shrinking that graph, not about server speed. Your production build (Rollup) bundles everything, which is why this only shows up in dev. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
We recently migrated our project from Webpack to Vite and noticed a significant slowdown in the DX. Specifically, the initial load or a full page refresh takes about 2–4 seconds.
This isn’t about HMR (which works fine) — the issue is with the very first load or when refreshing the app. In our workflow, we often need to refresh the page to re-run queries, and waiting several seconds each time is disruptive.
With Webpack, only the modules for the current view were loaded. In Vite, it seems the entire codebase is loaded in dev, which makes page navigation snappy but makes refreshes quite slow for us (we end up loading ~40MB of JS). To be clear, this doesn't happen in
productionwhere only the files needed for the view are loaded.I’m wondering if there are solutions or ongoing work in this area. I came across related discussions:
From what I understand, one workaround is to switch to dynamic imports for all components, e.g.:
But that feels like a cumbersome change just for improving dev-time reloads.
Is there any recommended approach, or possibly a config/setting planned that could address this?
Thanks in advance!
EDIT: Some correction to what I wrote: after some investigation, it looks like it's loaded everything in
prodtoo, but since it's bundled together and super minified and compressed, it does in half second rather than 4. Then I'm not sure how Webpack was solving this problem for the dev server but it was a better experience.All reactions