-
Notifications
You must be signed in to change notification settings - Fork 48.6k
React.createContext with SSR leads to concurrency problems in environments with co-routines #13854
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
Comments
This comment also describes this problem/limitation: https://github.com/facebook/react/blob/master/packages/react/src/ReactContext.js#L54 |
This is a possible workaround for environments with node-fibers (e.g. Meteor). currently testing...
|
The comment in React supports standard-compliant JavaScript environments, so using an environment with non-compliant concurrency primitives is going to cause problems. I see you opened an issue on the Meteor repo. I think that's the right place to report this, and hopefully the Meteor team can look into this for you. Thanks! |
@aweary while I understand that non-compliant environement might not need supported, i still think that this is a limitation of react and therefore belongs here as a feature request, or on a FR-board for react. I created a meteor package that monkey-patches React.createContext: https://github.com/panter/meteor-fiber-save-react-context/blob/master/fiber-save-react-context.js this of course does not belong in React, but maybe an api to facilitate such support? Maybe it could also help with the |
I think perhaps #14182 fixed this too? Try 16.6.3. |
@gaearon thank you! I tried to update my app to 16.6.3, but on concurrent server-renders I now get:
this does not happen if i just do one call to the server, only when another rendering is happening. Need to investigate more into that though. |
@gaearon actually this error above I opened an issue on meteor about that meteor/meteor#10364, but it's not a problem that cannot be solved easily from their side, unfortunatly. So personally, i need to stick with meteor 16.4.2 for the moment |
Yeah we don't really write code with the assumption that every render can be interrupted. We've started work on a new SSR that would support that (although through our own mechanism — Suspense) but it's going to be many months before it ships. |
@gaearon of course, i understand this ;-) but gladly this error (and the now fixed createContext bug) are the only problems i noticed so far. |
Is this still an issue with react ssr and meteor? |
@CaptainN: no, it works so far. #13854 (comment) can still happen on develop mode, but that's not severe as it not happens on production builds. Be aware that this concurrency problem might still arise in the future if you use fiber to yield (and yielding happens during one render) because that is a non-standard js runtime and most libraries do not expect to be run in such an environment. |
I'm getting a memory leak in my Meteor/React SSR code, which seems to have started after I migrated a bunch of data stuff to use hooks instead of a HoC. Do you think it's possible something similar to this issue in the hooks implementation is causing that? |
The problem is still there
|
First some context: i am using react SSR with meteor. Meteor uses node-fibers (co-routines, see https://github.com/laverdet/node-fibers), which enables async code to run synchronously without async/await or generators. So i think that React.renderToString could be interrupted by other code and this leads to the problem, but i am totally unsure.
Given the following code:
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If
<App />
gets rendered with different properties roughly at the same time, e.g.:execution 1:
<App foo="execution1" />
execution 2:
<App foo="execution2" />
then
SomeComponent
might render twice with the same props (either twice execution1 or execution2If 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:
See above
What is the expected behavior?
Context consumer should only respect the current tree and pick up the value from the parent provider even in environments with fibers (co-routines)
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.5.2
The text was updated successfully, but these errors were encountered: