-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Interaction between Remix, Lastpass, and <link rel=stylesheet> and (possibly) @import #4175
Comments
I believe this is a very common issue with React 18 that mostly affects Remix apps because Remix puts React in charge of rendering the entire document. It is apparently also an issue in other frameworks as well. Apparently React 18.2 might fix some of these bugs. Have you tried 18.2? |
However, it appears that Remix users are reporting the issue persists in React 18.2: |
Yes, we're using the latest remix and React 18.2.0. |
Some notes to anybody arriving here:
|
I was able to reproduce this by:
import fontStyles from "@fontsource/inter/variable.css";
export const links: LinksFunction = () => [
{
rel: "stylesheet",
href: fontStyles,
},
];
It appears that the Emotion styles are being removed and never re-added for client-side rendering? The workaround by @giltayar works but as mentioned not being able to utilize the newer React features is a bit cumbersome. Edit: After testing some more on Chrome it started happening as well (not sure why though). Edit: I did some more research and found this workaround that allowed me to use the React 18 features. I found this by looking at: facebook/react#24430 function hydrate() {
const emotionCache = createEmotionCache({ key: "css" });
startTransition(() => {
document.querySelectorAll("html > script").forEach((s) => {
s.parentNode!.removeChild(s);
});
hydrateRoot(
document,
<StrictMode>
<CacheProvider value={emotionCache}>
<RemixBrowser />
</CacheProvider>
</StrictMode>
);
});
} |
react issue reference: facebook/react#24430 |
Had some similar issues, I came up with this to silence the errors but do not recommend using this in production as it will kill a lot of browser plugin functionality. function clearBrowserPluginInjectionsBeforeHydration() {
if (document.body.dataset) {
Object.keys(document.body.dataset).map((attribute) => {
delete document.body.dataset[attribute];
});
}
setTimeout(
() =>
document.querySelectorAll("html > script, html > input").forEach((s) => {
s.parentNode?.removeChild(s);
}),
0
);
}
function hydrate() {
startTransition(() => {
clearBrowserPluginInjectionsBeforeHydration();
hydrateRoot(
document,
<StrictMode>
<ClientCacheProvider>
<RemixBrowser />
</ClientCacheProvider>
</StrictMode>
);
});
} |
Sadly, the workaround with hydrate instead of hydrateRoot does not work anymore with Remix 1.7.X |
@nicolaserny Weird, I'm using remix 1.7.2 with the |
@KasparRosin, I don't think it's an order issue. First, I see the style tag in the head section. After the hydrate call, the style tag is completely removed (so I have no more CSS styles). I tested with remix 1.7.5 and react 18.2.0 with Chrome + extensions such as Loom. I will try to create a basic example. |
@KasparRosin It's pretty easy to reproduce. I downloaded the Remix styled component example: https://github.com/remix-run/examples/tree/main/styled-components. |
This is probably because one of your browser extensions is injecting code : https://remix.run/pages/gotchas#browser-extensions-injecting-code |
This isn't just a warning, this is a breakage. My app doesn't function properly. I cannot leverage React 18 hydration. Styles entirely broken. Given the original reporter is using emotion, guessing his is too? |
I can confirm emotion actually broke from this and it wasn't just a harmless/annoying warning (react-select uses it and the drop-downs become unusable). My only options were rolling back to React 17 rendering, or wrapping anything that uses emotion in a |
In our case we use Chakra which leverages emotion for everything. So this is sadly neither just a gotcha nor something we can easily work around. I haven't seen a lot of activity on the React side for this (facebook/react#24430). We are stuck for the moment. |
I also had Hydration Error when I enable lastpass extension. I tried to moved back to the old pages folder and the error was gone. |
I've made a repo with a blend of the Chakra-UI & Emotion examples provided by Remix with a workaround that fixes the issue where styles are missing on client-side rendering if hydration fails. The only major change is that I added the client context from the Emotion example and adjusted the |
Given this, would it be a crazy idea to hydrate from a
And in
The only issue I see with this is that you don't get the functionality of To work around
Update: I tried hydrating from the div and so far it has solved the problem for everyone who has reported issues and hasn't lead to any other bugs. |
With the new "defer" feature of Remix, it's seems important to solve this issue because "defer" can't be used without hydrateRoot. |
@adamzerner Hey what remix version are you using? I have a |
@zolzaya |
Has anyone tried this solution? https://github.com/kiliman/remix-hydration-fix |
Can you show an example of usage of this hook? How is data retrieved from the meta function? |
Closing as a dup of #4822 |
What version of Remix are you using?
1.7.0
Steps to Reproduce
git clone https://github.com/giltayar/remix-import-css-lastpass-hydration-error-reproduction
npm install
npm run dev
Now...
root.tsx
and comment in the<link rel=stylesheet>
.Or...
root.tsx
and comment in the<style>
tag.Expected Behavior
Opening the page in Chrome or Firefox: No errors in the console
Actual Behavior
Errors in console*:
For Firefox, DevTools must be open (with "disable cache" checked in the Network tab). For Chrome, even closed will trigger the problematic behavior (!)
and...
Note that the error also happened to me when using a
@import
in an "emotion css" global rule (that is how I found it out). After much research, I found the problem also occurs withlink rel
. You have a reproduction of both in this repo.Also note that Lastpass Definitely triggers the problem, but playing around with this reproduction shows me that all the other parameters are fluid in regards to reproducability:
links
function,link rel
inhead
, or using@import
.The text was updated successfully, but these errors were encountered: