diff --git a/node_modules/@remix-run/dev/dist/vite/plugin.js b/node_modules/@remix-run/dev/dist/vite/plugin.js index 3f025ab..6d51763 100644 --- a/node_modules/@remix-run/dev/dist/vite/plugin.js +++ b/node_modules/@remix-run/dev/dist/vite/plugin.js @@ -154,6 +154,7 @@ const remixVitePlugin = (options = {}) => { let cssModulesManifest = {}; let ssrBuildContext; let viteChildCompiler = null; + let cachedPluginConfig; let resolvePluginConfig = async () => { var _options$future; let rootDirectory = viteUserConfig.root ?? process.env.REMIX_ROOT ?? process.cwd(); @@ -292,6 +293,7 @@ const remixVitePlugin = (options = {}) => { viteUserConfig = _viteUserConfig; viteCommand = viteConfigEnv.command; let pluginConfig = await resolvePluginConfig(); + cachedPluginConfig = pluginConfig; return { appType: "custom", experimental: { @@ -390,22 +392,32 @@ const remixVitePlugin = (options = {}) => { (_vite$httpServer = vite.httpServer) === null || _vite$httpServer === void 0 ? void 0 : _vite$httpServer.on("listening", () => { setTimeout(showUnstableWarning, 50); }); + // We cache the pluginConfig here to make sure we're only invalidating virtual modules when necessary. + // This requires a separate cache from `cachedPluginConfig`, which is updated by remix-hmr-updates. If + // we shared the cache, it would already be refreshed by remix-hmr-updates at this point, and we'd + // have no way of comparing against the cache to know if the virtual modules need to be invalidated. + let localCached; + // Let user servers handle SSR requests in middleware mode if (vite.config.server.middlewareMode) return; return () => { vite.middlewares.use(async (req, res, next) => { try { - // Invalidate all virtual modules - vmods.forEach(vmod$1 => { - let mod = vite.moduleGraph.getModuleById(vmod.resolve(vmod$1)); - if (mod) { - vite.moduleGraph.invalidateModule(mod); - } - }); + let pluginConfig = await resolvePluginConfig(); + if (JSON.stringify(localCached) !== JSON.stringify(pluginConfig)) { + // Invalidate all virtual modules + localCached = pluginConfig; + vmods.forEach(vmod$1 => { + let mod = vite.moduleGraph.getModuleById(vmod.resolve(vmod$1)); + if (mod) { + vite.moduleGraph.invalidateModule(mod); + } + }); + } let { url } = req; - let [pluginConfig, build] = await Promise.all([resolvePluginConfig(), vite.ssrLoadModule(serverEntryId)]); + let build = await vite.ssrLoadModule(serverEntryId); let handle = adapter.createRequestHandler(build, { mode: "development", criticalCss: await styles.getStylesForUrl(vite, pluginConfig, cssModulesManifest, build, url) @@ -476,7 +488,7 @@ const remixVitePlugin = (options = {}) => { // Ensure we're operating on the transformed code to support MDX etc. async transform(code, id, options) { if (options !== null && options !== void 0 && options.ssr) return; - let pluginConfig = await resolvePluginConfig(); + let pluginConfig = cachedPluginConfig || (await resolvePluginConfig()); let route = getRoute(pluginConfig, id); if (!route) return; let serverExports = ["loader", "action", "headers"]; @@ -501,7 +513,7 @@ const remixVitePlugin = (options = {}) => { } // Don't transform files that don't need the proxy - if (!code.includes("@remix-run/react") && !code.includes("LiveReload")) { + if (!(code.includes("@remix-run/react") && code.includes("LiveReload"))) { return; } @@ -558,7 +570,7 @@ const remixVitePlugin = (options = {}) => { code = result.code; let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/; if (refreshContentRE.test(code)) { - let pluginConfig = await resolvePluginConfig(); + let pluginConfig = cachedPluginConfig || (await resolvePluginConfig()); code = addRefreshWrapper(pluginConfig, code, id); } return { @@ -574,6 +586,8 @@ const remixVitePlugin = (options = {}) => { modules }) { let pluginConfig = await resolvePluginConfig(); + // Update the config cache any time there is a file change + cachedPluginConfig = pluginConfig; let route = getRoute(pluginConfig, file); server.ws.send({ type: "custom",