I wrestled with this for a while before figuring out that somehow it's the Meteor version of React that's causing the problem.
I'm rendering a component that uses some components from Material UI, e.g. <Paper/>
. To set the styling of those components, you have to set muiTheme
in context. I do this at my top-level component, App
, like so:
// App.jsx
App = React.createClass({
childContextTypes: {
muiTheme: PropTypes.object,
themeManager: PropTypes.object,
},
getDefaultProps() {
return {
themeManager: new Material.Styles.ThemeManager();
}
},
getChildContext() {
return {
muiTheme: this.props.themeManager.getCurrentTheme(),
themeManager: this.props.themeManager,
}
},
render() {...}
}
In one part of my app, I render a Paper element:
// GroveCard.jsx
GroveCard = React.createClass({
propTypes: {
text: React.PropTypes.string,
}
contextTypes: {
muiTheme: React.PropTypes.object,
},
render() {
return (
<Paper zIndex={2}/>
{this.props.text}
</Paper>
);
});
This has been working fine when using the normal browserified version of react, but when using the react-runtime package it fails with this error:
Warning: owner-based and parent-based contexts differ (values: `undefined` vs `[object Object]`) for key (muiTheme) while mounting Paper (see: http://fb.me/react-context-by-parent)
debug.js:43 Exception from Tracker recompute function: undefined
debug.js:43 TypeError: Cannot read property 'component' of undefined
at getStyles (http://localhost:3000/packages/client-deps.js?13cafeead7e3aad3bdc018f78d6c11e639290d00:6475:47)
And line 6475 of that package, function getStyles
looks like...
getStyles: function getStyles() {
var styles = {
root: {
backgroundColor: this.context.muiTheme.component.paper.backgroundColor,
transition: this.props.transitionEnabled && Transitions.easeOut(),
boxSizing: 'border-box',
fontFamily: this.context.muiTheme.contentFontFamily,
WebkitTapHighlightColor: 'rgba(0,0,0,0)',
boxShadow: this._getZDepthShadows(this.props.zDepth),
borderRadius: this.props.circle ? '50%' : this.props.rounded ? '2px' : '0px'
}
};
return styles;
},
This error happens anywhere I use a component from Material. My hunch is that this is because React is a peer dependency for Material UI and I'm not declaring that, but I haven't verified that yet.