Files
react/scripts/merge-fork
Andrew ClarkandGitHub c3d7a7e3d7 Bugfix: Offscreen instance is null during setState (#24734)
* [FORKED] Bugfix: Offscreen instance is null during setState

During a setState, we traverse up the return path and check if any
parent Offscreen components are currently hidden. To do that, we must
access the Offscreen fiber's `stateNode` field.

On a mounted Offscreen fiber, the `stateNode` is never null, so usually
we don't need to refine the type. When a fiber is unmounted, though,
we null out its `stateNode` field to prevent memory cycles. However,
we also null out its `return` field, so I had assumed that an unmounted
Offscreen fiber would never be reachable.

What I didn't consider is that it's possible to call `setState` on a
fiber that never finished mounting. Because it never mounted, it was
never deleted. Because it was never deleted, its `return` field was
never disconnected.

This pattern is always accompanied by a warning but we still need to
account for it. There may also be other patterns where an unmounted
Offscreen instance is reachable, too.

The discovery also suggests it may be better for memory
usage if we don't attach the `return` pointer until the commit phase,
though in order to do that we'd need some other way to track the return
pointer during initial render, like on the stack.

The fix is to add a null check before reading the instance
during setState.

* Add previous commit to list of forked revisions
2022-06-15 22:13:22 -04:00
..

merge-fork

Script for syncing changes between forked modules.

Basic example

yarn merge-fork --base-dir=packages/react-reconciler/src ReactFiberWorkLoop

This will take all the changes in ReactFiberWorkLoop.new.js and apply them to ReactFiberWorkLoop.old.js.

Syncing multiple modules at once

You can merge multiple modules at a time:

yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop \
  ReactFiberBeginWork \
  ReactFiberCompleteWork \
  ReactFiberCommitWork

Syncing modules with different names

You can provide explicit "old" and "new" file names. This only works for one module at a time:

yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  --old=ReactFiberExpirationTime.js \
  --new=ReactFiberLane.js

Syncing modules in the opposite direction (old -> new)

The default is to merge changes from the new module to the old one. To merge changes in the opposite direction, use --reverse.

yarn merge-fork \
  --reverse \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop

Comparing changes to an older base rev

By default, the changes are compared to HEAD. You can use --base-ref to compare to any rev. For example, while working on a PR, you might make multiple commits to the new fork before you're ready to backport them to the old one. In that case, you want to compare to the merge base of your PR branch:

yarn merge-fork \
  --base-ref=$(git merge-base HEAD origin/main)
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop