-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
build-storybook differences? #551
Comments
Would have to take a closer look, but my gut feeling is that it might relate to this: mobxjs/mobx-react#56. Could you remove the propTypes and check whether the dev setup is not "accidentally" working correctly as a result of propTypes? |
Not that MobX-react only supports direct observers, all components that use observable data, should be observers. Because react might schedule re-rendering both on the same stack or a separate stack, and in the latter case accessing an observable won't be tracked, hence not triggering a re-render |
@mweststrate - thanks for looking. I tried removing const Headline = observer(props => ( // <-- now wrapped in 'observer'
<h1>{props.store.toggle.toString()}</h1>
));
Headline.propTypes = {
store: React.PropTypes.shape({
toggle: React.PropTypes.bool.isRequired,
}),
}; The problem with this approach is that I'm using lots of third-party components in production, so I can't guarantee each will implement What I'm trying to figure out is why it works with Thanks for your help. |
If you have third party components that don't support observer, don't pass them observables, but convert the observables to plain objects in your |
yeah, that's actually what I'm currently doing. I guess knowing that React could re-schedule off-stack, the question is now why it does that in one environment, but not another... any ideas what triggers it? |
Something else that is a bit freaky too (maybe related to mobxjs/mobx-react#56) Under const Headline = props => (
<h1>{props.store.toggle.toString()}</h1>
);
/* commenting out .propTypes *stops* it working in dev */
// Headline.propTypes = {
// store: React.PropTypes.shape({
// toggle: React.PropTypes.bool.isRequired,
// }),
// }; So I guess that's exactly what mobxjs/mobx-react#56 relates to -- adding a interesting! |
d'oh, it suddenly makes sense.
So, in this case, .propTypes was causing a side-effect that unintentionally made the component appear to be observing (I guess inside the original call stack passing the prop?), but breaks as soon as Makes sense now! |
I'll go ahead and close this and the related issue, since this seems to be the intentional behaviour and a user-land issue. |
I'm trying to figure out a weird edge case I'm having, using mobx for store management inside stories.
Take this (highly convoluted) story:
When running in dev (
npm run dev
), clicking 'toggle' works fine...However, when running in production (
npm run build-storybook
and starting a local server), toggle suddenly stops working...My gut reaction is that it has something to do with transpilation differences. Stores built using MobX's
observer
function work differently depending on whether there's aprototype
chain (if there is, properties on the object are observable, but not the parent object itself). But that doesn't seem to be happening because in both cases, there's no prototype chain, and in other examples where the parent store is not fed in but used directly, it works as expected.It seems the observer chain is 'lost' somehow when the generator passes it to it.
I know it's a totally weird edge case, but are there any known differences between how code is rendered in dev vs. bundling?
The text was updated successfully, but these errors were encountered: