unexpected ContextConsumer or ContextProvider behavior
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
When use two or more contexts that created by createContext
,in the child-tree of cxt2.Provider,i use cxt1.Provider to set a new context of cxt1,i expect only the child consumer got the new cxt1,but the result is that the cxt2.Provider’s next sibling’s child-tree got an unexpected cxt2.Provider’s new context
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below: createContext issue
What is the expected behavior? ContextProvider only affect the children node.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? React 16.3.0-alpha.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Yeah, that’s what we were thinking too. Just had to step away for meetings right after writing the test 😅 Thanks Brandon!
@bvaughn I took a look, and from what I can tell the problem is related to
popProvider
:https://github.com/facebook/react/blob/cbf729659e784792c7b57e8e8a0e88ed6359c604/packages/react-reconciler/src/ReactFiberNewContext.js#L53-L55
previousProviderFiber
ends up being the wrong provider (UidContext2
), so whencontext.currentValue
is updated to matchpreviousProviderFiber.pendingProps.value
it’s being updated from the wrong provider.