mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
This PR clarifies the logic for adjust mutable ranges of phis and their operands during LeaveSSA. Previously we had logic in several places to determine whether/how to extend the ranges of each phi and its operands: this occurred while traversing reassignmentPhis (in 2+ places) and rewritePhis, as well as in rewritePlace(). This was kind of a band-aid to make things work, but the logic was imprecise. The actual rules are as follows: If there is a back-edge, or the phi id is unnamed, then were extend the ranges of the phi and its operands to min(starts) and max(ends). This ensures that the operands are computed as one unit, ie put into a single reactive scope. For loops this is necessary because...looping! For unnamed values this is necessary because of the way we collapse logical and ternary expressions back to a hierarchical ReactiveFunction — we need to make sure the final mutable range extends from the start of the final instruction up to the end of the logical/ternaries value blocks. Otherwise this is a phi where operands come from predecessors and are named. If the phi is mutated later, then we have to extend the end of each operand's range to account for the fact that they can be mutated later. Else, we leave the operands alone. Behavior doesn't change, but we consolidate all of the mutable range logic in one place.
test262
@ 83a46bfe0e
React Forget
React Forget is an experimental Babel plugin to automatically memoize React Hooks and Components.
Development
# tsc --watch
$ yarn dev
# in another terminal window
$ yarn test --watch
Notes
An overview of the implementation can be found in the Architecture Overview.
This transform
- needs plugin-syntax-jsx as a dependency to inherit the syntax from.
- should be run before plugin-transform-react-jsx
- assume the enforcement of rules of hooks, i.e.
- only call hooks from React functions
- only call hooks at the top level
- https://www.npmjs.com/package/eslint-plugin-react-hooks
Scaffolding
- https://github.com/facebook/flow/tree/master/packages/babel-plugin-transform-flow-enums
- https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-jsx/src/create-plugin.ts
Reference