Skip to content

Commit

Permalink
fix(react,dev): dev chunking and refresh race condition (#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori authored Apr 26, 2023
1 parent 54a7329 commit 438cb1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-buses-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@remix-run/dev": patch
"@remix-run/react": patch
---

fix(react,dev): dev chunking and refresh race condition
33 changes: 17 additions & 16 deletions packages/remix-dev/compiler/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ const createEsbuildConfig = (
}
}

if (
ctx.options.mode === "development" &&
ctx.config.future.unstable_dev !== false
) {
let defaultsDirectory = path.resolve(
__dirname,
"..",
"..",
"config",
"defaults"
);
entryPoints["__remix_entry_dev"] = path.join(
defaultsDirectory,
"entry.dev.ts"
);
}

let matchPath = ctx.config.tsconfigPath
? createMatchPath(ctx.config.tsconfigPath)
: undefined;
Expand Down Expand Up @@ -175,22 +192,6 @@ const createEsbuildConfig = (
];

if (ctx.options.mode === "development" && ctx.config.future.unstable_dev) {
// TODO prebundle deps instead of chunking just these ones
let isolateChunks = [
require.resolve("react"),
require.resolve("react/jsx-dev-runtime"),
require.resolve("react/jsx-runtime"),
require.resolve("react-dom"),
require.resolve("react-dom/client"),
require.resolve("react-refresh/runtime"),
require.resolve("@remix-run/react"),
"remix:hmr",
];
entryPoints = {
...entryPoints,
...Object.fromEntries(isolateChunks.map((imprt) => [imprt, imprt])),
};

plugins.push(hmrPlugin(ctx));
plugins.push(cssBundleUpdatePlugin(channels));
}
Expand Down
13 changes: 13 additions & 0 deletions packages/remix-dev/config/defaults/entry.dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-nocheck
/* eslint-disable */

export default () => {
import("react");
import("react/jsx-dev-runtime");
import("react/jsx-runtime");
import("react-dom");
import("react-dom/client");
import("react-refresh/runtime");
import("@remix-run/react");
import("remix:hmr");
};
2 changes: 1 addition & 1 deletion packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ if (import.meta && import.meta.hot) {
setTimeout(() => {
Object.assign(window.__remixManifest, assetsManifest);
window.$RefreshRuntime$.performReactRefresh();
}, 0);
}, 1);
}
});
router.revalidate();
Expand Down

0 comments on commit 438cb1b

Please sign in to comment.