-
Notifications
You must be signed in to change notification settings - Fork 3
Issue with react-intl's context and shouldComponentUpdate #1
Comments
Haha exactly, this is what I thought. Nice try but your idea seems to work only when you have a single component unfortunatly :( |
I went on with the extended PureRenderMixin as for this issue, facebook/react#2517, eventually I'd fallback to props. I'm open to find better alternatives :-) |
props is just not manageable for my very large SPA :( I'll have to reload the full page for now :( |
Let's go for the reload :-) @caridy is right when he says the level of complexity raised by this is not worth the hassle. |
I've found a workaround: :) |
👍 reload for the win! |
In this issue we are discussing an approach to skip the |
At Netflix we have this same problem, where e.g. if voice gets enabled on an XBOX, or if our locale changes, or if we switch to a kids' experience, we want to force a global re-render without respecting shouldComponentUpdate. There are lots of external events across all of our platforms (web, mobile, TV) which should have this behaviour. We've currently got a flawed solution in place using context. We've inserted a layer underneath It would be really nice to have a |
/cc @sebmarkbage, can you chime in here? |
Yea, this is broken and one reason context is undocumented. I think that future versions of React will include an explicit determination of a context key change which will deeply force and update of every component that reads from that context key. Context will be completely removed from shouldComponentUpdate since it doesn't make sense.
|
cool, thanks @sebmarkbage. guys, as you can see, we will get this for free with the current implementation of react-intl, no magic is needed, just wait until react gets refactored. |
Thanks @sebmarkbage, looking forward to that update. |
@sebmarkbage agree with that solution. Since React has contextTypes for each componant using context you could easily know which components to re-render. @eplawless have you checked my workaround here? |
I solved this problem using subscribe/listen pattern in js-lingui. HOC So, even if any component above return false in Cool thing is that even the Component which uses Trans component (translated message) don't need to update itself and still all translated texts inside will update on change of messages/language:
The subscribe pattern is really simple, you can see it here: https://github.com/lingui/js-lingui/blob/master/packages/lingui-react/src/I18nProvider.js#L64 I also used the same pattern when experimenting with hot reloading of message catalogs (https://github.com/lingui/js-lingui/blob/master/packages/example-usecase/src/App.js#L27) but I have a feeling, there must be a simpler way to do it :) |
After fetching the new locale data, components using
shouldComponentUpdate
(as those using theReact.addons.PureRenderMixin
) may block the update of the components, since they are not aware of the changed context. This problem is described here.The text was updated successfully, but these errors were encountered: