@@ -7,14 +7,11 @@ import getMuiTheme from 'material-ui/styles/getMuiTheme'
7
7
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
8
8
import injectTapEventPlugin from 'react-tap-event-plugin'
9
9
10
- // Needed for onTouchTap
11
- // http://stackoverflow.com/a/34015469/988941
12
- try {
13
- if ( typeof window !== 'undefined' ) {
14
- injectTapEventPlugin ( )
15
- }
16
- } catch ( e ) {
17
- // do nothing
10
+ // Make sure react-tap-event-plugin only gets injected once
11
+ // Needed for material-ui
12
+ if ( ! process . tapEventInjected ) {
13
+ injectTapEventPlugin ( )
14
+ process . tapEventInjected = true
18
15
}
19
16
20
17
const styles = {
@@ -24,17 +21,23 @@ const styles = {
24
21
}
25
22
}
26
23
27
- const _muiTheme = getMuiTheme ( {
24
+ const muiTheme = {
28
25
palette : {
29
26
accent1Color : deepOrange500
30
27
}
31
- } )
28
+ }
32
29
33
30
class Main extends Component {
34
31
static getInitialProps ( { req } ) {
35
- const userAgent = req ? req . headers [ 'user-agent' ] : navigator . userAgent
36
- const isServer = ! ! req
37
- return { isServer, userAgent}
32
+ // Ensures material-ui renders the correct css prefixes server-side
33
+ let userAgent
34
+ if ( process . browser ) {
35
+ userAgent = navigator . userAgent
36
+ } else {
37
+ userAgent = req . headers [ 'user-agent' ]
38
+ }
39
+
40
+ return { userAgent }
38
41
}
39
42
40
43
constructor ( props , context ) {
@@ -58,6 +61,8 @@ class Main extends Component {
58
61
}
59
62
60
63
render ( ) {
64
+ const { userAgent } = this . props
65
+
61
66
const standardActions = (
62
67
< FlatButton
63
68
label = 'Ok'
@@ -66,12 +71,8 @@ class Main extends Component {
66
71
/>
67
72
)
68
73
69
- const { userAgent } = this . props
70
- /* https://github.com/callemall/material-ui/issues/3336 */
71
- const muiTheme = getMuiTheme ( getMuiTheme ( { userAgent : userAgent } ) , _muiTheme )
72
-
73
74
return (
74
- < MuiThemeProvider muiTheme = { muiTheme } >
75
+ < MuiThemeProvider muiTheme = { getMuiTheme ( { userAgent , ... muiTheme } ) } >
75
76
< div style = { styles . container } >
76
77
< Dialog
77
78
open = { this . state . open }
0 commit comments