A cause of client/server className mismatch in SSR with react-apollo
See original GitHub issueIf you are using react-apollo’s getDataFromTree
, be aware that it does a full render traversal of the page in order to trigger all of the data fetching. This includes Material-UI classname generation. For the subsequent renderToString
, be sure to use a fresh generateClassName
and JssProvider
, so that the sequence numbers in the classNames are reset to 0.
I have to say that debugging this has been one of my more miserable experiences in recent memory, taking about 2 days. withStyles
is extremely complex, and there are legitimate causes for “redundant” classname generation, like multiple themes, that have to be understood and ruled out. I ultimately found that emitting trace logs from it allowed me to diff client and server behavior. It might make sense to add such a trace capability to withStyles. I found it useful to emit trace for just one component, selected by name, showing each invocation, the stylesCreator index, whether it generated, and what the first emitted classname was.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:44 (22 by maintainers)
Top GitHub Comments
To be noted,
@material-ui/styles
is no longer using the index counter for the static style sheets. It’s hashing the class names instead. So, people will only see the issue with dynamic styles going forward.