Skip to content

Commit

Permalink
Optimize dependencies found through route module graphs (#9921)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Aug 29, 2024
1 parent 93d1c9d commit 8152c40
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .changeset/hot-dogs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@remix-run/dev": patch
---

Automatically optimize dependencies during development

Now Remix will tell Vite to find dependencies by crawling imports starting with your route modules.
This should resolve most (if not all) `504 Outdated Dependency` errors that could previously break HMR.

For users who were previously working around this limiation, you no longer need to explicitly add routes to Vite's `optimizeDeps.entries` nor do you need to disable the `remix-dot-server` plugin.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"vite": "5.1.3",
"vite-tsconfig-paths": "^4.2.2",
"wait-on": "^7.0.1",
"wrangler": "^3.24.0"
"wrangler": "^3.72.3"
},
"engines": {
"node": ">=18.0.0"
Expand Down
10 changes: 9 additions & 1 deletion packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
: undefined,
},
optimizeDeps: {
entries: Object.values(ctx.remixConfig.routes).map((route) =>
path.join(ctx.remixConfig.appDirectory, route.file)
),
include: [
// Pre-bundle React dependencies to avoid React duplicates,
// even if React dependencies are not direct dependencies.
Expand Down Expand Up @@ -1497,7 +1500,12 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
name: "remix-dot-server",
enforce: "pre",
async resolveId(id, importer, options) {
if (options?.ssr) return;
// https://vitejs.dev/config/dep-optimization-options
let isOptimizeDeps =
viteCommand === "serve" &&
(options as { scan?: boolean })?.scan === true;

if (options?.ssr || isOptimizeDeps) return;

let isResolving = options?.custom?.["remix-dot-server"] ?? false;
if (isResolving) return;
Expand Down
185 changes: 183 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8152c40

Please sign in to comment.