-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Style] Address server sider rendering issues #3009
[Style] Address server sider rendering issues #3009
Conversation
Any change we can make this contextual? maybe with theme? I mean globals hurt SSR. so a contextual userAgent can be passed down from the root with each request. the theme object is already on it. so maybe add it to the them? |
Yeah, I agree! This PR is WIP, this first commit can be merged like this, but I'm gonne push new commits to address this. |
I see. Thanks a lot. This will surely close a huge number of issues 😁 😁 |
@@ -144,13 +144,13 @@ const CircularProgress = React.createClass({ | |||
_rotateWrapper(wrapper) { | |||
if (this.props.mode !== 'indeterminate') return; | |||
|
|||
AutoPrefix.set(wrapper.style, 'transform', 'rotate(0deg)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we can't call muiTheme.prefix()
rather than calling it on the imported auto-prefix
from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some issue when trying to do so. That's definitely something we should address.
I have updated the PR, I'm happy with it. |
It's good for now 👍 👍 We'll address more issues when we decide on transformers 👍 Feel free to merge 😁 |
Awesome, I'm gonna add a section on the doc for the server side rendering before merging. |
Added. |
- `'all'` to prefix for all user agents | ||
- `false` to disable the prefixer | ||
|
||
We rely on the [muiTheme](/#/customization/themes) context to pread the user agent to all of our component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'pread' / 'spread'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
All good 👍 👍 Thanks a lot @oliviertassinari |
@newoga Do you want to have a final look at this PR before merging? |
@oliviertassinari Sorry, I looked earlier and I think I was good for now in terms of a first iteration. I'll do one last quick check! 😄 |
@oliviertassinari @alitaheri Yup, let's get this in 👍 I'm not too familiar with server side rendering with React so I can't comment too much in that regard, but I think this is a good first step. We can look at more approaches to refactoring Part of #2986 motivation was developing an approach for removing auto prefixing from the transformation cycle. Since this PR solves it with a similar but different means, maybe we should hold off on #2986? I can create a new PR (or modify #2986) that doesn't expose the composition and customization of style transformers but still puts our own version of |
@newoga Awesome 🎉.
This PR is making us one step closer to the goal of #2986. |
Yes I agree 👍 👍 |
[Style] Address server sider rendering issues
Yay! I have been trying to do server-side rendering and am facing this very same issue. Do you know when this will be released on npm? |
By the way. I the only advantage of this PR for my project is to remove the warning. |
I just upgraded to 14.3, and the warning "Material UI: userAgent should be supplied in the muiTheme context for server-side rendering." is back. I had this working before using this hack:
How am I supposed to set the userAgent to get SSR working again? (now checksums don't match, and I get the warning, once). I'm using the decorator in main component App.jsx:
"my-material-ui.config.js":
|
@tomasztomys Just want to make sure. I noticed your |
I get weird spacing issues in the mismatch error:
This is how I set it up. const muiTheme = getMuiTheme(null, {
userAgent: 'all',
});
...
export default themeDecorator(muiTheme)(App); |
Okay, there's a PR (#3112) that's related to this that I'm going to review soon. I'll see what I find. |
Changing from
to
fixed it, thank you :-) |
For future reference in case somebody else is reading all 1000 posts related to this topic, this worked better for me. Defining my custom theme directly and passing the
import getMuiTheme from 'material-ui/lib/styles/getMuiTheme';
import themeDecorator from 'material-ui/lib/styles/theme-decorator';
import MuiThemeProvider from 'material-ui/lib/MuiThemeProvider';
import * as Colors from 'material-ui/lib/styles/colors';
const muiTheme = getMuiTheme({
palette: {
primary1Color: Colors.indigo500,
...etc...
},
}, {
userAgent: 'false'
}); return (
<MuiThemeProvider muiTheme={muiTheme}>
<AppBar ...etc... />
</MuiThemeProvider>
) export default themeDecorator(muiTheme)(MyComponent); |
This PR introduce many changes.
userAgent
variable to themuiTheme
. We can use the following values:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36
'all'
to prefix for all user agentsfalse
to disable the prefixerautoPrefixer.all()
autoPrefixer.getPrefixer()
autoPrefixer.getPrefix()
Fix #2530, #2336 and #2316.