Non-Bug: JSS server rendering produces font families with escaped quote characters.
See original GitHub issueFunction createMuiTheme() created the font families with escaped " characters:
fontFamily: "\"Roboto\", \"Helvetica\", \"Arial\", sans-serif"
which is converted to"
by JSS functionSheetsRegistry.toString()
instead of ", and this style will be ignore during initial render by browser causing the font to flip.
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
- output of
createMuiTheme()
:
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif'
// or
fontFamily: "'Roboto', 'Helvetica', 'Arial', sans-serif"
- style written to
index.html
<style id="jss-server-side">html {
...
.jss49 {
....
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
}
Current Behavior
- output of
createMuiTheme()
:
fontFamily: "\"Roboto\", \"Helvetica\", \"Arial\", sans-serif"
- style written to
index.html
<style id="jss-server-side">html {
...
.jss49 {
....
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
}
This style will be ignored by the browser and replaced when the hydration completed with the correct font, causing the screen to flip.
Steps to Reproduce
Please run createMuiTheme() and observe the result.
I suggest this is a bug because material-ui decision to use JSS should mean it should provide what JSS need to work.
SSR
rendering part
renderToHtml: (render, Comp, meta) => {
const sheetsRegistry = new SheetsRegistry()
const sheetsManager = new Map()
const theme = createMuiTheme() // <-- this is the problem
\\ the font families were created with escaped quote characters:
\\ `fontFamily: "\"Roboto\", \"Helvetica\", \"Arial\", sans-serif"`
const generateClassName = createGenerateClassName()
const html = render(
<JssProvider registry={sheetsRegistry} generateClassName={generateClassName}>
<MuiThemeProvider theme={theme} sheetsManager={sheetsManager}>
<Comp />
</MuiThemeProvider>
</JssProvider>
)
meta.jssStyles = sheetsRegistry.toString() // <-- this will convert escaped quote characters \" to " instead of "
return html
},
–> Link: N/A
Context
initial font rendered by the client is incorrect, causing the screen to flip.
Your Environment
Tech | Version |
---|---|
Material-UI | v3.1.0 |
React | 16.5.1 |
Browser | Google Chrome v69.0.3497.100 (64-bit) |
TypeScript | N/A |
etc. |
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Non-Bug: JSS server rendering produces font families with ...
Function createMuiTheme() created the font families with escaped " characters: fontFamily: "\"Roboto\", \"Helvetica\", \"Arial\", sans-serif" ...
Read more >Server-side rendering JSS apps in integrated mode
Run JSS applications using the Sitecore-hosted Node.js rendering engine.
Read more >R News
The parser no longer marks strings containing octal or hex escapes as being in UTF-8 when entered in a UTF-8 locale. On platforms...
Read more >Read more
BUG FIXES: • stack() now gives an error if no vector column is selected, rather than returning a 1-column data frame (contrary to...
Read more >R: doc/NEWS.2 - Fossies
153 154 • dt(1e160, 1.2, log=TRUE) no longer gives -Inf. 155 156 • On Windows the untar() function now quotes the directory name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can check out #12827 for the support of CSS variables in the theme. Bulma, Bootstrap, Material-UI are competing libraires. There is little use cases for using two at the same time. I agree on your point regarding CSS-in-JS. In the next style iterations I want to allow people to use different styles backend, JSS, emotion, etc.
@oliviertassinari
Yes, I am currently injecting muiTheme through emotion theme provider.
Currently each component library brings it’s own css-in-js framework (jss, emotion, styled-components, etc.) and theme provider/consumer. Even if you only need to use one component, you’ll have to add all the dependencies and add clutter to your react dom tree, and passing/sync the theme. This lead to higher development and maintenance efforts, higher bundle size, higher client’s computation and memory footprint.
Imagine that one can have a universal theme of CSS custom variables that are automatically accessible by all components:
The CSS variables can also be injected to component using css/sass/css-modules (e.g. bootstrap, bulma. etc.).
Isn’t that powerful?