-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Merged
oliviertassinari
merged 5 commits into
mui:master
from
oliviertassinari:server-side-rendering
Jan 22, 2016
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0f98ee
[Style] Only display the warning once
oliviertassinari 805ee6f
[Style] Move the prefix tool to the muiTheme context
oliviertassinari 800a365
[Style] Remove the usage of autoprefix.all()
oliviertassinari a6c0985
[Style] Add option for user agent false and all
oliviertassinari a10b76b
[Docs] Add a Server Rendering section
oliviertassinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
docs/src/app/components/pages/get-started/ServerRendering.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import MarkdownElement from '../../MarkdownElement'; | ||
import serverRenderingText from './serverRendering.md'; | ||
|
||
const ServerRendering = () => ( | ||
<MarkdownElement text={serverRenderingText} /> | ||
); | ||
|
||
export default ServerRendering; |
55 changes: 55 additions & 0 deletions
55
docs/src/app/components/pages/get-started/serverRendering.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## Server Rendering | ||
|
||
When using Material UI with server rendering, we must use the same environment for the server and the client. | ||
This has two technical implications. | ||
|
||
### Autoprefixer | ||
|
||
First, Material UI has to use the same user agent for the auto prefixer. | ||
On the client side, the default value is `navigator.userAgent`. | ||
But on the server side, the `navigator` is `undefined`. You need to provide it to Material UI. | ||
|
||
The `userAgent` can take one of the following values: | ||
- a regular user agent like | ||
`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 agents | ||
- `false` to disable the prefixer | ||
|
||
We rely on the [muiTheme](/#/customization/themes) context to spread the user agent to all of our component. | ||
For instance, you can provide it like this: | ||
|
||
```js | ||
import getMuiTheme from 'material-ui/lib/styles/getMuiTheme'; | ||
import themeDecorator from 'material-ui/lib/styles/theme-decorator'; | ||
import colors from 'material-ui/lib/styles/colors'; | ||
|
||
const muiTheme = getMuiTheme({ | ||
palette: { | ||
primary1Color: colors.green500, | ||
primary2Color: colors.green700, | ||
primary3Color: colors.green100, | ||
}, | ||
}, { | ||
avatar: { | ||
borderColor: null, | ||
}, | ||
userAgent: req.headers['user-agent'], | ||
}); | ||
|
||
class Main extends React.Component { | ||
render() { | ||
return ( | ||
<div>Hello world</div> | ||
); | ||
} | ||
} | ||
|
||
export default themeDecorator(muiTheme)(Main) | ||
``` | ||
|
||
### process.env.NODE_ENV | ||
|
||
You also need to use the same `process.env.NODE_ENV` value for the client side and server side. | ||
Otherwise, the checksums won't match. | ||
In order to make sure our style transformations are only applied once, | ||
we add an additional property to each style when `process.env.NODE_ENV !== 'production'`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 importedauto-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.