-
Hi, I have recently migrated to Vite however the experience is not really that great. When I start my server it optimizes a bunch of dependencies which is fine. However when i navigate between pages, it optimizes more dependencies but it takes anywhere from 2s-10s. Sometimes it blocks the navigation completely and i have to click the link again, sometimes it redirects after a second but an error shows up for a second that something is not yet available (for example Is there a way to fix it? Like force to optimize all possible dependencies beforehand? Or is it a problem in vite with remix itself? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 23 replies
-
Maybe Vite's warmup support can help. https://vitejs.dev/guide/performance#warm-up-frequently-used-files If you think the remix plugin is to blame you can confirm by installing vite-plugin-inspect which will show the timings of each plugin. https://www.npmjs.com/package/vite-plugin-inspect |
Beta Was this translation helpful? Give feedback.
-
Vite provides Personally, I had a problem with e2e testing where some random window refresh during navigation makes tests too flaky, so I attempted to manually setup https://github.com/hi-ogawa/ytsub-v3/blob/f5074646e1ef45e671ea2f3fe28c236239173956/vite.config.ts#L71-L75 export default defineConfig({
plugins: [
// had to disable since false-positive error during optimizeDeps discovery?
// https://github.com/remix-run/remix/pull/8267
remix().filter((plugin) => plugin.name !== "remix-dot-server"),
],
optimizeDeps: {
// add this to crawl all routes
entries: ["./app/entry-client.tsx", "./app/root.tsx", "./app/routes/**/*"],
},
}); This worked in my case, but I have a little doubt that maybe some server only dependencies leak to client due to this. I haven't tested it but I think using It would be interesting if more people try |
Beta Was this translation helpful? Give feedback.
-
Hopefully this ends up getting fixed in React Router 7.... |
Beta Was this translation helpful? Give feedback.
-
I experienced significative time improvements on page load, on the dev server, after I disabled |
Beta Was this translation helpful? Give feedback.
-
Remix 2.12.0 added |
Beta Was this translation helpful? Give feedback.
I think I've figured this out now. The solution is to (1) add your routes to
optimizeDeps.entries
as suggested by @hi-ogawa and then (2) patchpackages/remix-dev/vite/plugin.ts
:{ name: "remix-dot-server", enforce: "pre", resolveId(id, importer, options) { + if (options?.scan) return // might need @ts-expect-error for this // ... rest of the plugin code ... } }
The issue was that the
if (options?.ssr) return
check was not being triggered during dependency optimization since thessr
field is omitted from theoptions
during that pass. So to fix it, we can detect if the optimization pass is happening directly viaoptions?.scan
.Going to verify that this is the fix and …