React: Why does React warn about multiple renderers using the same context provider?

Created on 3 Aug 2020  路  2Comments  路  Source: facebook/react

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

Steps To Reproduce

  1. Using multiple react renderers
  2. Using the same context provider between that react renderers

Link to code example: https://codesandbox.io/s/multiple-reconciler-using-same-context-v8kq1?file=/src/App.js

The current behavior

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.

The expected behavior

Don't show any warning.

Question

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) 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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabegreenberg picture gabegreenberg  路  119Comments

iammerrick picture iammerrick  路  94Comments

fdecampredon picture fdecampredon  路  139Comments

AdamKyle picture AdamKyle  路  148Comments

sophiebits picture sophiebits  路  107Comments