Skip to content
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

Support sharing context objects between concurrent renderers #12779

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented May 11, 2018

As a workaround to support multiple concurrent renderers, we categorize some renderers as primary and others as secondary. We only expect there to be two concurrent renderers at most: React Native (primary) and Fabric (secondary); React DOM (primary) and React ART (secondary). Secondary renderers store their context values on separate fields.

@acdlite acdlite requested a review from sebmarkbage May 11, 2018 00:34
@acdlite acdlite changed the title Support concurrent primary and secondary renderers. Support concurrent primary and secondary renderers that use the same context objects May 11, 2018
@acdlite acdlite changed the title Support concurrent primary and secondary renderers that use the same context objects Support sharing context objects between concurrent renderers May 11, 2018
@pull-bot
Copy link

pull-bot commented May 11, 2018

React: size: 🔺+0.5%, gzip: 🔺+0.2%

ReactDOM: size: 🔺+0.4%, gzip: 🔺+0.6%

Details of bundled changes.

Comparing: 6565795...82255ac

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.8% +1.0% 56.89 KB 57.35 KB 15.77 KB 15.93 KB UMD_DEV
react.production.min.js 🔺+0.5% 🔺+0.2% 7.08 KB 7.11 KB 3 KB 3.01 KB UMD_PROD
react.development.js +1.0% +1.1% 47.53 KB 47.99 KB 13.44 KB 13.59 KB NODE_DEV
react.production.min.js 🔺+0.6% 🔺+0.3% 5.61 KB 5.65 KB 2.44 KB 2.44 KB NODE_PROD
React-dev.js +1.0% +1.2% 47.6 KB 48.06 KB 13.06 KB 13.22 KB FB_WWW_DEV
React-prod.js 🔺+0.4% 🔺+0.2% 13.41 KB 13.47 KB 3.77 KB 3.77 KB FB_WWW_PROD

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.2% +0.1% 640.38 KB 641.75 KB 147.27 KB 147.47 KB UMD_DEV
react-dom.production.min.js 🔺+0.4% 🔺+0.6% 102.04 KB 102.44 KB 32.45 KB 32.63 KB UMD_PROD
react-dom.development.js +0.2% +0.1% 624.74 KB 626.11 KB 143.14 KB 143.34 KB NODE_DEV
react-dom.production.min.js 🔺+0.4% 🔺+0.4% 100.46 KB 100.85 KB 31.62 KB 31.74 KB NODE_PROD
ReactDOM-dev.js +0.2% +0.1% 649.84 KB 651.33 KB 146.01 KB 146.22 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.3% 🔺+0.3% 302.82 KB 303.82 KB 54.92 KB 55.07 KB FB_WWW_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.3% +0.2% 443.31 KB 444.74 KB 96.28 KB 96.5 KB UMD_DEV
react-art.production.min.js 🔺+0.4% 🔺+0.3% 92.37 KB 92.75 KB 28.1 KB 28.18 KB UMD_PROD
react-art.development.js +0.4% +0.3% 369.14 KB 370.57 KB 77.61 KB 77.83 KB NODE_DEV
react-art.production.min.js 🔺+0.7% 🔺+0.3% 56.86 KB 57.26 KB 17.43 KB 17.48 KB NODE_PROD
ReactART-dev.js +0.4% +0.3% 378.06 KB 379.61 KB 77.3 KB 77.53 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.5% 🔺+0.4% 185.48 KB 186.48 KB 30.48 KB 30.6 KB FB_WWW_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.4% +0.2% 374.55 KB 375.92 KB 78.53 KB 78.72 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.7% 🔺+0.5% 56.62 KB 57.01 KB 17.19 KB 17.28 KB UMD_PROD
react-test-renderer.development.js +0.4% +0.3% 365.37 KB 366.74 KB 75.85 KB 76.05 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.7% 🔺+0.4% 55.83 KB 56.23 KB 16.89 KB 16.96 KB NODE_PROD
ReactTestRenderer-dev.js +0.4% +0.3% 374.55 KB 376.04 KB 75.66 KB 75.86 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.4% +0.3% 345.35 KB 346.69 KB 71.25 KB 71.43 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.8% 🔺+0.5% 48.59 KB 48.97 KB 14.66 KB 14.74 KB NODE_PROD
react-reconciler-persistent.development.js +0.4% +0.3% 344.62 KB 345.96 KB 70.96 KB 71.14 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.8% 🔺+0.7% 47.53 KB 47.91 KB 14.44 KB 14.54 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.3% +0.2% 485.7 KB 487.18 KB 103.65 KB 103.85 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.4% 🔺+0.4% 234.99 KB 235.99 KB 39.16 KB 39.3 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.3% +0.2% 485.41 KB 486.89 KB 103.57 KB 103.77 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.5% 🔺+0.4% 221.4 KB 222.4 KB 37.02 KB 37.15 KB RN_OSS_PROD
ReactFabric-dev.js +0.3% +0.2% 468.07 KB 469.63 KB 99.23 KB 99.46 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.5% 🔺+0.4% 207 KB 208 KB 34.4 KB 34.53 KB RN_FB_PROD
ReactFabric-dev.js +0.3% +0.2% 468.1 KB 469.67 KB 99.24 KB 99.47 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.5% 🔺+0.4% 207.04 KB 208.04 KB 34.42 KB 34.55 KB RN_OSS_PROD

Generated by 🚫 dangerJS

@@ -11,6 +11,7 @@

let React = require('react');
let ReactDOM = require('react-dom');
let ReactART = require('react-art');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

_changedBits: 0,
_changedBits_secondary: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_changedBits2? every byte counts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol ok

@sophiebits
Copy link
Collaborator

What if I want three?

@acdlite acdlite force-pushed the support-concurrent-primary-and-secondary-renderers branch from a211b39 to 2537883 Compare May 11, 2018 01:12
As a workaround to support multiple concurrent renderers, we categorize
some renderers as primary and others as secondary. We only expect
there to be two concurrent renderers at most: React Native (primary) and
Fabric (secondary); React DOM (primary) and React ART (secondary).
Secondary renderers store their context values on separate fields.
Only warn for two concurrent primary or two concurrent secondary renderers.
@acdlite acdlite force-pushed the support-concurrent-primary-and-secondary-renderers branch from 2537883 to 82255ac Compare May 11, 2018 01:20
@acdlite
Copy link
Collaborator Author

acdlite commented May 11, 2018

@sophiebits Too bad! :P

If we decide later we want to support this in the general case, what we'd do is have each renderer expose a function to reset its stack upon interruption. Kinda slow, but that's effectively what would happen if everything shared the same renderer (i.e. that's what happens when one root interrupts another root).

warning(
context._currentRenderer === null ||
context._currentRenderer === rendererSigil,
'Detected multiple renderers concurrently rendering the ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bumping into this with test renderer when the context object is reused, but resetModules() is called between tests. Seems confusing.

bors bot referenced this pull request in mythmon/corsica-tree-status May 24, 2018
20: Update react monorepo to v16.4.0 r=renovate[bot] a=renovate[bot]

This Pull Request renovates the package group "react monorepo".


-   [react-dom](https://github.com/facebook/react) (`dependencies`): from `16.3.2` to `16.4.0`
-   [react](https://github.com/facebook/react) (`dependencies`): from `16.3.2` to `16.4.0`

# Release Notes
<details>
<summary>facebook/react</summary>

### [`v16.4.0`](https://github.com/facebook/react/blob/master/CHANGELOG.md#&#8203;1640-May-23-2018)
[Compare Source](facebook/react@8e5f12c...v16.4.0)
##### React

* Add a new [experimental](`https://github.com/reactjs/rfcs/pull/51`) `React.unstable_Profiler` component for measuring performance. ([@&#8203;bvaughn] in [#&#8203;12745](`https://github.com/facebook/react/pull/12745`))
##### React DOM

* Add support for the Pointer Events specification. ([@&#8203;philipp-spiess] in [#&#8203;12507](`https://github.com/facebook/react/pull/12507`))
* Properly call `getDerivedStateFromProps()` regardless of the reason for re-rendering. ([@&#8203;acdlite] in [#&#8203;12600](`https://github.com/facebook/react/pull/12600`) and [#&#8203;12802](`https://github.com/facebook/react/pull/12802`))
* Fix a bug that prevented context propagation in some cases. ([@&#8203;gaearon] in [#&#8203;12708](`https://github.com/facebook/react/pull/12708`))
* Fix re-rendering of components using `forwardRef()` on a deeper `setState()`. ([@&#8203;gaearon] in [#&#8203;12690](`https://github.com/facebook/react/pull/12690`))
* Fix some attributes incorrectly getting removed from custom element nodes. ([@&#8203;airamrguez] in [#&#8203;12702](`https://github.com/facebook/react/pull/12702`))
* Fix context providers to not bail out on children if there's a legacy context provider above. ([@&#8203;gaearon] in [#&#8203;12586](`https://github.com/facebook/react/pull/12586`))
* Add the ability to specify `propTypes` on a context provider component. ([@&#8203;nicolevy] in [#&#8203;12658](`https://github.com/facebook/react/pull/12658`))
* Fix a false positive warning when using `react-lifecycles-compat` in `<StrictMode>`. ([@&#8203;bvaughn] in [#&#8203;12644](`https://github.com/facebook/react/pull/12644`))
* Warn when the `forwardRef()` render function has `propTypes` or `defaultProps`. ([@&#8203;bvaughn] in [#&#8203;12644](`https://github.com/facebook/react/pull/12644`))
* Improve how `forwardRef()` and context consumers are displayed in the component stack. ([@&#8203;sophiebits] in [#&#8203;12777](`https://github.com/facebook/react/pull/12777`))
* Change internal event names. This can break third-party packages that rely on React internals in unsupported ways. ([@&#8203;philipp-spiess] in [#&#8203;12629](`https://github.com/facebook/react/pull/12629`))
##### React Test Renderer

* Fix the `getDerivedStateFromProps()` support to match the new React DOM behavior. ([@&#8203;koba04] in [#&#8203;12676](`https://github.com/facebook/react/pull/12676`))
* Fix a `testInstance.parent` crash when the parent is a fragment or another special node. ([@&#8203;gaearon] in [#&#8203;12813](`https://github.com/facebook/react/pull/12813`))
* `forwardRef()` components are now discoverable by the test renderer traversal methods. ([@&#8203;gaearon] in [#&#8203;12725](`https://github.com/facebook/react/pull/12725`))
* Shallow renderer now ignores `setState()` updaters that return `null` or `undefined`. ([@&#8203;koba04] in [#&#8203;12756](`https://github.com/facebook/react/pull/12756`))
##### React ART

* Fix reading context provided from the tree managed by React DOM. ([@&#8203;acdlite] in [#&#8203;12779](`https://github.com/facebook/react/pull/12779`))
##### React Call Return (Experimental)

* This experiment was deleted because it was affecting the bundle size and the API wasn't good enough. It's likely to come back in the future in some other form. ([@&#8203;gaearon] in [#&#8203;12820](`https://github.com/facebook/react/pull/12820`))
##### React Reconciler (Experimental)

* The [new host config shape](https://github.com/facebook/react/blob/c601f7a64640290af85c9f0e33c78480656b46bc/packages/react-noop-renderer/src/createReactNoop.js#L82-L285) is flat and doesn't use nested objects. ([@&#8203;gaearon] in [#&#8203;12792](`https://github.com/facebook/react/pull/12792`))

---


</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).

Co-authored-by: Renovate Bot <[email protected]>
bors bot referenced this pull request in mozilla/delivery-console May 24, 2018
164: Update react monorepo to v16.4.0 r=rehandalal a=renovate[bot]

This Pull Request renovates the package group "react monorepo".


-   [react-dom](https://github.com/facebook/react) (`dependencies`): from `16.3.2` to `16.4.0`
-   [react](https://github.com/facebook/react) (`dependencies`): from `16.3.2` to `16.4.0`

# Release Notes
<details>
<summary>facebook/react</summary>

### [`v16.4.0`](https://github.com/facebook/react/blob/master/CHANGELOG.md#&#8203;1640-May-23-2018)
[Compare Source](facebook/react@8e5f12c...v16.4.0)
##### React

* Add a new [experimental](`https://github.com/reactjs/rfcs/pull/51`) `React.unstable_Profiler` component for measuring performance. ([@&#8203;bvaughn] in [#&#8203;12745](`https://github.com/facebook/react/pull/12745`))
##### React DOM

* Add support for the Pointer Events specification. ([@&#8203;philipp-spiess] in [#&#8203;12507](`https://github.com/facebook/react/pull/12507`))
* Properly call `getDerivedStateFromProps()` regardless of the reason for re-rendering. ([@&#8203;acdlite] in [#&#8203;12600](`https://github.com/facebook/react/pull/12600`) and [#&#8203;12802](`https://github.com/facebook/react/pull/12802`))
* Fix a bug that prevented context propagation in some cases. ([@&#8203;gaearon] in [#&#8203;12708](`https://github.com/facebook/react/pull/12708`))
* Fix re-rendering of components using `forwardRef()` on a deeper `setState()`. ([@&#8203;gaearon] in [#&#8203;12690](`https://github.com/facebook/react/pull/12690`))
* Fix some attributes incorrectly getting removed from custom element nodes. ([@&#8203;airamrguez] in [#&#8203;12702](`https://github.com/facebook/react/pull/12702`))
* Fix context providers to not bail out on children if there's a legacy context provider above. ([@&#8203;gaearon] in [#&#8203;12586](`https://github.com/facebook/react/pull/12586`))
* Add the ability to specify `propTypes` on a context provider component. ([@&#8203;nicolevy] in [#&#8203;12658](`https://github.com/facebook/react/pull/12658`))
* Fix a false positive warning when using `react-lifecycles-compat` in `<StrictMode>`. ([@&#8203;bvaughn] in [#&#8203;12644](`https://github.com/facebook/react/pull/12644`))
* Warn when the `forwardRef()` render function has `propTypes` or `defaultProps`. ([@&#8203;bvaughn] in [#&#8203;12644](`https://github.com/facebook/react/pull/12644`))
* Improve how `forwardRef()` and context consumers are displayed in the component stack. ([@&#8203;sophiebits] in [#&#8203;12777](`https://github.com/facebook/react/pull/12777`))
* Change internal event names. This can break third-party packages that rely on React internals in unsupported ways. ([@&#8203;philipp-spiess] in [#&#8203;12629](`https://github.com/facebook/react/pull/12629`))
##### React Test Renderer

* Fix the `getDerivedStateFromProps()` support to match the new React DOM behavior. ([@&#8203;koba04] in [#&#8203;12676](`https://github.com/facebook/react/pull/12676`))
* Fix a `testInstance.parent` crash when the parent is a fragment or another special node. ([@&#8203;gaearon] in [#&#8203;12813](`https://github.com/facebook/react/pull/12813`))
* `forwardRef()` components are now discoverable by the test renderer traversal methods. ([@&#8203;gaearon] in [#&#8203;12725](`https://github.com/facebook/react/pull/12725`))
* Shallow renderer now ignores `setState()` updaters that return `null` or `undefined`. ([@&#8203;koba04] in [#&#8203;12756](`https://github.com/facebook/react/pull/12756`))
##### React ART

* Fix reading context provided from the tree managed by React DOM. ([@&#8203;acdlite] in [#&#8203;12779](`https://github.com/facebook/react/pull/12779`))
##### React Call Return (Experimental)

* This experiment was deleted because it was affecting the bundle size and the API wasn't good enough. It's likely to come back in the future in some other form. ([@&#8203;gaearon] in [#&#8203;12820](`https://github.com/facebook/react/pull/12820`))
##### React Reconciler (Experimental)

* The [new host config shape](https://github.com/facebook/react/blob/c601f7a64640290af85c9f0e33c78480656b46bc/packages/react-noop-renderer/src/createReactNoop.js#L82-L285) is flat and doesn't use nested objects. ([@&#8203;gaearon] in [#&#8203;12792](`https://github.com/facebook/react/pull/12792`))

---


</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).

Co-authored-by: Renovate Bot <[email protected]>
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Support concurrent primary and secondary renderers.

As a workaround to support multiple concurrent renderers, we categorize
some renderers as primary and others as secondary. We only expect
there to be two concurrent renderers at most: React Native (primary) and
Fabric (secondary); React DOM (primary) and React ART (secondary).
Secondary renderers store their context values on separate fields.

* Add back concurrent renderer warning

Only warn for two concurrent primary or two concurrent secondary renderers.

* Change "_secondary" suffix to "2"

#EveryBitCounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants