-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vite and defer seem to lead to Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
and TypeError: window.__remixClearCriticalCss is not a function
#7863
Comments
Check out #7842 |
The above fixes the issue on |
@Fireclunge - the preamble log, or the remixClearCriticalCss is not a function log? or both? When loading all routes, or specific routes? |
The preamble log. Some of my routes go through multiple loaders each often each calling APIs from an external backend at each layer so i'm not sure if its the complexity that's causing the error or something else entirely. The build code seems to fail here; if (!window.__vite_plugin_react_preamble_installed__) {
throw new Error( "..." )
} |
@Fireclunge I'm on a fairly large codebase (656 routes + large component libraries) and it seems to be working on my side. index 3f025ab..b07df68 100644
--- a/node_modules/@remix-run/dev/dist/vite/plugin.js
+++ b/node_modules/@remix-run/dev/dist/vite/plugin.js
@@ -515,7 +515,7 @@ const remixVitePlugin = (options = {}) => {
load(id) {
if (id === vmod.resolve(remixReactProxyId)) {
// TODO: ensure react refresh is initialized before `<Scripts />`
- return ['import { createElement } from "react";', 'export * from "@remix-run/react";', 'export const LiveReload = process.env.NODE_ENV !== "development" ? () => null : ', '() => createElement("script", {', ' type: "module",', " suppressHydrationWarning: true,", " dangerouslySetInnerHTML: { __html: `", ` import RefreshRuntime from "${vmod.url(hmrRuntimeId)}"`, " RefreshRuntime.injectIntoGlobalHook(window)", " window.$RefreshReg$ = () => {}", " window.$RefreshSig$ = () => (type) => type", " window.__vite_plugin_react_preamble_installed__ = true", " `}", "});"].join("\n");
+ return ['import { createElement } from "react";', 'export * from "@remix-run/react";', 'export const LiveReload = process.env.NODE_ENV !== "development" ? () => null : ', '() => createElement("script", {', ' type: "module",', " async: true,", " suppressHydrationWarning: true,", " dangerouslySetInnerHTML: { __html: `", ` import RefreshRuntime from "${vmod.url(hmrRuntimeId)}"`, " RefreshRuntime.injectIntoGlobalHook(window)", " window.$RefreshReg$ = () => {}", " window.$RefreshSig$ = () => (type) => type", " window.__vite_plugin_react_preamble_installed__ = true", " `}", "});"].join("\n");
}
}
}, { |
@Fireclunge have you swapped |
I reinstalled using the above patch file to make sure it wasn't a skill issue and regardless of the ordering of |
I found out what was causing the error. One of my libraries was throwing a
This was messing with the turnary logic in the patch when testing for Here's my patch file that 'fixes' diff --git a/node_modules/@remix-run/dev/dist/vite/plugin.js b/node_modules/@remix-run/dev/dist/vite/plugin.js
index 3f025ab..518e8e3 100644
--- a/node_modules/@remix-run/dev/dist/vite/plugin.js
+++ b/node_modules/@remix-run/dev/dist/vite/plugin.js
@@ -515,7 +515,7 @@ const remixVitePlugin = (options = {}) => {
load(id) {
if (id === vmod.resolve(remixReactProxyId)) {
// TODO: ensure react refresh is initialized before `<Scripts />`
- return ['import { createElement } from "react";', 'export * from "@remix-run/react";', 'export const LiveReload = process.env.NODE_ENV !== "development" ? () => null : ', '() => createElement("script", {', ' type: "module",', " suppressHydrationWarning: true,", " dangerouslySetInnerHTML: { __html: `", ` import RefreshRuntime from "${vmod.url(hmrRuntimeId)}"`, " RefreshRuntime.injectIntoGlobalHook(window)", " window.$RefreshReg$ = () => {}", " window.$RefreshSig$ = () => (type) => type", " window.__vite_plugin_react_preamble_installed__ = true", " `}", "});"].join("\n");
+ return ['import { createElement } from "react";', 'export * from "@remix-run/react";', 'export const LiveReload = () => createElement("script", {', ' type: "module",', " async: true,", " suppressHydrationWarning: true,", " dangerouslySetInnerHTML: { __html: `", ` import RefreshRuntime from "${vmod.url(hmrRuntimeId)}"`, " RefreshRuntime.injectIntoGlobalHook(window)", " window.$RefreshReg$ = () => {}", " window.$RefreshSig$ = () => (type) => type", " window.__vite_plugin_react_preamble_installed__ = true", " `}", "});"].join("\n");
}
}
}, { Obviously not a proper fix, but hopefully gives some insight into how this happened |
@Fireclunge I had an issue where I had a |
Perfect, working on migrating loader functions to |
It seems I can still reproduce this intermittently by reloading a page for 10 to 20 times even without defer. |
This is fixed by #7919. |
I can still see the error after updating Remix to |
I think |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
I had a similar issue with my Remix 2.10.3 / 2.10.2 and 2.8.1 and turns out : I had to change the remix() plugin section of the vite.config file to include !process.env.VITEST ? remix () : react check my public repo for setup https://github.com/anyuruf/kinstree-remix |
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
npm i && npm run dev
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
andTypeError: window.__remixClearCriticalCss is not a function
appear in console.loader.ts
, uncomment thejson()
path and notice that document reloads no longer throw errors.Expected Behavior
No issues in the console
Actual Behavior
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
andTypeError: window.__remixClearCriticalCss is not a function
in the console.The text was updated successfully, but these errors were encountered: