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
[V5] Getting FOUC with default Remix template #1734
Comments
Hello! I think this was a problem on emotion cache i've made a repository that interacts with the emotion cache |
@johnsiras at the first sight the code in your repo doesn’t look different to what I had and in my case it didn’t work. EDIT: I have tried your code out but I'm still getting FOUC: |
maybe try going upgrading down on some packages, cause i updated it all the packages to latest. |
Well, I don't think that will be a solution, but I downgraded react to Btw. In your repo you should use some of Mantine components to see FOUC. I can see it with a simple button. |
Fixed in 5.0 |
Not fixed yet? |
I don't think this is an issue with mantine, had the same problem today and updated my repo to work with v5, I did not have enough time to fully understand what is going on but here are some of the things that I found. import { RemixBrowser } from '@remix-run/react';
import { hydrate } from 'react-dom';
import { ClientProvider } from '@mantine/remix';
hydrate(
<ClientProvider>
<RemixBrowser />
</ClientProvider>,
document
); Remix does not seem to be running the entry.client.tsx for error pages and because of that the ClientProvider cannot set the tags on the head. I worked around it by moving this step to a component inside the route. // ~/app/components/Document.tsx
const clientStyleData = useContext(ClientStyleContext);
const mantineCache = useEmotionCache()
useEffect(() => {
const cache = mantineCache
cache.sheet.container = document.head;
const tags = cache.sheet.tags;
cache.sheet.flush();
tags.forEach((tag) => {
(cache.sheet as any)._insertTag(tag);
});
clientStyleData?.reset();
}, []); This works and the tags are applied but the global styles for some reason are not. I think it is because the cache does not change so I created a context with a cacheProvider and different emotion cache that I recreate manually just to force the global styles to be added and it works. I'll probably spend some more time on this in the weekend, maybe we don't need an additional emotion cache and can flag emotion to reapply the global styles using the mantine cache. |
Thanks for the investigation @correiarmjoao, please share what you will be able to find |
As far as I've tested, this only happens with I have either a |
Update: I added a custom Works with React 18 and Mantine 5. @rtivital what would be the consequences of making |
It should be fine, could not think of any issues with that. |
@elkevinwolf This works like a charm for me (Remix 1.6.7 and Mantine 5.1.0)! |
it works fine when I share cache between when I eliminate emotion cache, modals work as expected but FOUC annoys. p.s. this happens when your build targets production environment. dev env works fine |
replaced
with
and this fixed all issues. |
@zemd can you please share a repo with a working example? |
@viczam sorry, but no. also the latest update broke styles again, and I had to switch back to react17 |
Using Mantine v5.2.4 and still getting the same error as OP plus a warning from React for using
But not perceiving any FOUC. Tried switching to
But this breaks other things and triggers several hydration warnings and errors:
This is the repository: |
I believe that you need to have an explicit Edit: Just confirmed it with my own working solution. Edit2: Possibly its just reacting to the different value of |
Thank you so much. Adding Here is the complete file:
Maybe Mantine docs should add this to their Remix guide. |
I do not really know why it makes it work, need to test it out. Did it resolve your issue with React 18? |
It seems the default of It doesn't matter where you initialize the emotion cache eg. client entry or root or MantineProvider, and testing it earlier, I didn't need a ClientProvider either for everything to work. It's really a credit to Remix for having such good control over the html. So the React 18 template is simpler than 17, but I'm not exactly an expert on what makes emotion tick in SSR/browser-side, so I can't yet PR the template repo. It just seems to have perfect compatibility with React 18 to me (portals/modals aside, possibly). |
Okay, thanks @dsschneidermann, I'll wiggle things around and see whether we can fix it, |
Can this be re-opened? I’m having this issue with latest template and have tried everything mentioned in this thread. Happy to help if I can provide more info. I’m getting hydration errors in production but things work fine in development |
@stephen776, please provide a repository with minimal reproduction, I do not see any issues in mantine-remix-template |
Please disregard. My issue was unrelated. |
@rtivital For a repository with minimal reproduction, please see: https://github.com/alukach/mantine-remix-rendering-issue Description can be found here: mantinedev/remix-template#4 |
I only experience FOUC with devtools open in firefox. If it's closed, FOUC goes away. In chorme, the font is a little jumpy with dev tools open but no flash. Nothing with devtools closed. |
It's finally working for me. Here is what I did:
- <ClientProvider>
+ <ClientProvider emotionCache={emotionCache}>
- const server = createStylesServer();
+ const server = createStylesServer(emotionCache);
```tsx
<MantineProvider
+ emotionCache={emotionCache}
theme={theme} It works now 🎉 @richardanewman I assume you don't see it with dev tools because all assets are cached and your (JS) load happens instantaneously and consequently adding client side stylesheets as well. |
Thank you! This was such a pain to fix. I also had the issue of Mantine not playing well with Cloudflare Pages. I wrote up a guide so that others don't need to go through the pain: how to make remix work with mantine and cloudflare pages. |
What package has an issue
@mantine/core
Describe the bug
I'm getting FOUC using default Remix template with updated Remix, React and Mantine (
5.0.0-alpha.19
) packages. I've tried usingnpm
andyarn
as well. The issueis visible on intiial page load as well as on error/catch boundries.A solution I'm currently using along with
npm
(remix-run/remix#1136 (comment)) doesn't work anymore due to changes in Mantine's Emotion cache. Therefore I have tried to implement caching based on this approach from Chakra UI: https://chakra-ui.com/getting-started/remix-guide#2-provider-setup. Sadly with no luck. The only difference is that I don't get errors in browser console due to mismatches in<head>
but FOUC is still present.The error I get using
injectStylesIntoStaticMarkup
:In which browser did the problem occur
Chrome
If possible, please include a link to a codesandbox with the reproduced problem
No response
Do you know how to fix the issue
No
Are you willing to participate in fixing this issue and create a pull request with the fix
No response
Possible fix
No response
The text was updated successfully, but these errors were encountered: