diff --git a/packages/remix-dev/compiler/compileBrowser.ts b/packages/remix-dev/compiler/compileBrowser.ts index 47c0f26904e..19cb58ba3fb 100644 --- a/packages/remix-dev/compiler/compileBrowser.ts +++ b/packages/remix-dev/compiler/compileBrowser.ts @@ -28,6 +28,7 @@ import { } from "./plugins/cssBundleEntryModulePlugin"; import { writeFileSafe } from "./utils/fs"; import invariant from "../invariant"; +import { hmrPlugin } from "./plugins/hmrPlugin"; export type BrowserCompiler = { // produce ./public/build/ @@ -132,6 +133,7 @@ const createEsbuildConfig = ( entryPoints["react-dom/client"] = "react-dom/client"; entryPoints["react-refresh/runtime"] = "react-refresh/runtime"; entryPoints["remix:hmr"] = "remix:hmr"; + plugins.push(hmrPlugin()); } return { diff --git a/packages/remix-dev/package.json b/packages/remix-dev/package.json index 48baf48febe..996c8ad370f 100644 --- a/packages/remix-dev/package.json +++ b/packages/remix-dev/package.json @@ -44,6 +44,7 @@ "fs-extra": "^10.0.0", "get-port": "^5.1.1", "gunzip-maybe": "^1.4.2", + "http-proxy": "^1.18.1", "inquirer": "^8.2.1", "jsesc": "3.0.2", "json5": "^2.2.1", @@ -60,6 +61,7 @@ "prettier": "2.7.1", "pretty-ms": "^7.0.1", "proxy-agent": "^5.0.0", + "react-refresh": "^0.14.0", "recast": "^0.21.5", "remark-frontmatter": "4.0.1", "remark-mdx-frontmatter": "^1.0.1", diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index 8075d402fdc..804f8573c69 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -890,6 +890,7 @@ export function Scripts(props: ScriptProps) { ? `__remixContext.a=${deferredScripts.length};` : ""); + // TODO: change to be dynamic imports for routes let routeModulesScript = !isStatic ? " " : `${matches @@ -1527,6 +1528,15 @@ function convertRouterFetcherToRemixFetcher( return fetcher; } +export let Hmr = () => { + let [hydrated, setHydrated] = React.useState(false); + React.useEffect(() => { + setHydrated(true); + }, []); + if (!hydrated) return null; + return