I am currently developing a web app that uses both react-pixi and react-babylonjs. Both of these libraries use react-reconciler and have a custom renderer. I also use redux in my project, so they share the same Context in the two libraries.
It displays a warning on Console after every redux state updating, but everything works well, both renderers can trigger an update.
I want to know if there is any risk in doing this, or is this just a false warning?
React version: 16.13.1
Link to code example: https://codesandbox.io/s/multiple-reconciler-using-same-context-v8kq1?file=/src/App.js
It will throw a warning message after every state updating:
Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.
But everything works well, both renderers can trigger an update.
Don't show any warning.
React only supports two concurrent renderers at most鈥撀爋ne "primary" and one "secondary", e.g. React DOM (primary) and React ART (secondary) or React Native (primary) and Fabric (secondary). This is partially a practical constraint (in that it covers 99% of use cases) and partially an intentional trade off in that certain APIs (like Context or useMutableSource) are able to be more efficiently implemented because of it.
For example, rather than using a (slower) Map structure to maintain a (per-renderer) stack of context values, the Context API is able to store this stack on the context object using a designated field:
https://github.com/facebook/react/blob/93a0c2830534cfbc4e6be3ecc9c9fc34dee3cfaa/packages/react-reconciler/src/ReactFiberNewContext.new.js#L78-L111
Same for the useMutableSource API:
https://github.com/facebook/react/blob/93a0c2830534cfbc4e6be3ecc9c9fc34dee3cfaa/packages/react-reconciler/src/ReactMutableSource.new.js#L30-L62
Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.
This warning suggests that two renderers of the same type (presumably two primary renderers) are both using a context at the same time (concurrently). This might happen to work okay in some cases (e.g. if only the global/default context value is being used) but it may also break depending on how each renderer is using the context.
Hope this helps answer your question! tl;dr is that the warning is valid and important.
Thank you for such a detailed answer! now I understand.
Both of react-pixi and react-babylonjs have a custom renderer, plus the original react-dom, there are 3 renderers, seems I must give up one of them.
Most helpful comment
React only supports two concurrent renderers at most鈥撀爋ne "primary" and one "secondary", e.g. React DOM (primary) and React ART (secondary) or React Native (primary) and Fabric (secondary). This is partially a practical constraint (in that it covers 99% of use cases) and partially an intentional trade off in that certain APIs (like Context or
useMutableSource) are able to be more efficiently implemented because of it.For example, rather than using a (slower)
Mapstructure to maintain a (per-renderer) stack of context values, the Context API is able to store this stack on the context object using a designated field:https://github.com/facebook/react/blob/93a0c2830534cfbc4e6be3ecc9c9fc34dee3cfaa/packages/react-reconciler/src/ReactFiberNewContext.new.js#L78-L111
Same for the
useMutableSourceAPI:https://github.com/facebook/react/blob/93a0c2830534cfbc4e6be3ecc9c9fc34dee3cfaa/packages/react-reconciler/src/ReactMutableSource.new.js#L30-L62
This warning suggests that two renderers of the same type (presumably two primary renderers) are both using a context at the same time (concurrently). This might happen to work okay in some cases (e.g. if only the global/default context value is being used) but it may also break depending on how each renderer is using the context.
Hope this helps answer your question! tl;dr is that the warning is valid and important.