Repository navigation
Conversation
…l rerender if the context changes
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
|
While I'm not sure this solution will pass muster, it is elegant in its way. My hunch is teh team will not like the leakiness of passing all context (requested or not) to each component. However it does solve the issue succinctly... Why not pass the unmasked context only to SCU, at least that limits the use of context to a particularly small and readonly place. |
|
For properties, components define propTypes, but they can still get properties that they do not define. In fact this is the basis for a number of generic Higher Order Components, as they pass along all properties to a wrapped component, whether they know about these properties or not. The same reasoning can be applied to contexts, whereby through contextTypes, a component defines what it expects to be in the context, but not implying that nothing else can be in the context. |
|
I haven't looked at this at all but if we did want to do something like it, we'd need to do it against the |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
I applied this update to master as well: #7225 |
|
This is great!
Exit Question: Would this make Cross Posted with #7225 |
|
Closing out since you made the other one against master. Discussion can happen there. |
|
I agree. Many HOC has its implementation of shouldComponentUpdate. The currently implementation of context won't work with them as not contextTypes can be specified in HOC, and hence they won't get propagated. |
I am using context to propagate locale and routing information. My problem is that some pure components stop subtree rendering when the context changes (because pure components only check state and props). This is a problem for many people as per issue #2517.
I reasoned that not masking the context for intermediate components would be better than masking, and the defined contextTypes would only be used for validating, not for filtering. This is similar to how propTypes work, where the properties specified are validated but the ones not specified are still available to the component. i have updated the tests to reflect this update.
Since components that are not interested in context would typically not use the context argument, not masking the context would not cause any existing component to break, unless said components explicitly are checking that the context param is undefined. This would, however, create an opportunity for a refinement of pure component, say a ContextAwarePureComponent which would compare state, props and context in shouldComponentUpdate, allowing context updates to cause re-renders of pure components.
I am currently running in development with this patch, using radium and some react-bootstrap components, and did not experience any issue