You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a React Router 7 app, using MUI (with Emotion as the styling engine) pretty much exclusively for UI components and styles. I'm trying to get MUI/Emotion styling working between server-side and client-side renderings of the page, and running into a snag:
When rendering my Root Route, I'm using a HydrateFallback as the initial server rendering and while the clientLoader is running. However, while the initial server-rendered version of the page has the expected MUI styling for the components I use (e.g. a ProgressCircular), it seems that as soon as the clientLoader starts running, the styles (i.e. all the <style> tags inserted by Emotion initially) disappear entirely, only to reappear after the clientLoader finishes.
Since I'm using HydrateFallback, my current interpretation of this is that the DOM rendered for the HydrateFallback doesn't include the MUI/Emotion elements needed to render the <style> tags immediately when the hydration starts. However, I have wrapped the contents of HydrateFallback with a <CacheProvider> and <ThemeProvider>, identical to the normal page content.
Also, it's not clear to me why a new page is being rendered at all: by my reading of the React Router 7 docs, at least, it seems that the server-rendered version is theoretically what should be getting rendered up until the completion of the clientLoader -- am I misunderstanding that part?
Here are some further details:
Versions/Libraries:
@mui/material: 5.15.19
@emotion/cache: 11.14.0
@emotion/react: 11.14.0
@emotion/server: 11.11.0
@emotion/styled: 11.11.0
entry.server.tsx: using the default
entry.client.tsx: does some setup of hosting- and analytics-related variables, then performs the hydration via:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone!
I'm working on a React Router 7 app, using MUI (with Emotion as the styling engine) pretty much exclusively for UI components and styles. I'm trying to get MUI/Emotion styling working between server-side and client-side renderings of the page, and running into a snag:
When rendering my Root Route, I'm using a
HydrateFallback
as the initial server rendering and while theclientLoader
is running. However, while the initial server-rendered version of the page has the expected MUI styling for the components I use (e.g. aProgressCircular
), it seems that as soon as theclientLoader
starts running, the styles (i.e. all the<style>
tags inserted by Emotion initially) disappear entirely, only to reappear after theclientLoader
finishes.Since I'm using
HydrateFallback
, my current interpretation of this is that the DOM rendered for theHydrateFallback
doesn't include the MUI/Emotion elements needed to render the<style>
tags immediately when the hydration starts. However, I have wrapped the contents ofHydrateFallback
with a<CacheProvider>
and<ThemeProvider>
, identical to the normal page content.Also, it's not clear to me why a new page is being rendered at all: by my reading of the React Router 7 docs, at least, it seems that the server-rendered version is theoretically what should be getting rendered up until the completion of the
clientLoader
-- am I misunderstanding that part?Here are some further details:
Versions/Libraries:
@mui/material
: 5.15.19@emotion/cache
: 11.14.0@emotion/react
: 11.14.0@emotion/server
: 11.11.0@emotion/styled
: 11.11.0entry.server.tsx: using the default
entry.client.tsx: does some setup of hosting- and analytics-related variables, then performs the hydration via:
React Router 7 config:
root.tsx
Any help with unraveling this conundrum would be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions