[RFC] FIX: Context pollutes mutable global state#13875
Closed
leebyron wants to merge 2 commits intofacebook:masterfrom
Closed
[RFC] FIX: Context pollutes mutable global state#13875leebyron wants to merge 2 commits intofacebook:masterfrom
leebyron wants to merge 2 commits intofacebook:masterfrom
Conversation
The new context API stores the provided values on the shared context instance. When used in a synchronous context, this is not an issue. However when used in an concurrent context this can cause a "push provider" from one react render to have an effect on an unrelated concurrent react render. I've encountered this bug in production when using renderToNodeStream, which asks ReactPartialRenderer for bytes up to a high water mark before yielding. If two Node Streams are created and read from in parallel, the state of one can polute the other. I wrote a failing test to illustrate the conditions under which this happens. I'm also concerned that the experimental concurrent/async React rendering on the client could suffer from the same issue.
Fixes facebook#13874 This is just a strawman approach for a fix for facebook#13874 that avoids mutating global context by giving each context instance a unique key it can use to store its value in a context object that's scoped to the current render.
|
React: size: 🔺+0.5%, gzip: 🔺+0.5% Details of bundled changes.Comparing: 4f0bd45...d137b03 react
react-dom
scheduler
Generated by 🚫 dangerJS |
leebyron
added a commit
to leebyron/react
that referenced
this pull request
Oct 17, 2018
…storage") Fixes facebook#13874 Alternative to facebook#13875 This straw-man approach also avoids mutating global context by giving each ReactPartialRenderer it's own mutable state and using context instances as keys into that mutable state.
Contributor
Author
|
Closing in favor of #13877 which is a simpler and probably more efficient fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13874
This is just a straw-man approach for a fix for #13874 that avoids mutating global context by giving each context instance a unique key it can use to store its value in a context object that's scoped to the current render.