Skip to content

cherry-pick(4.5-stable): Fix crash from withheld exiting layout animations in experimental proxy (#10073) - #10207

Merged
tjzel merged 1 commit into
4.5-stablefrom
@tjzel/4.5-stable/cherry-pick-#10073
Aug 25, 2026
Merged

tjzel merged 1 commit into
4.5-stablefrom
@tjzel/4.5-stable/cherry-pick-#10073

Conversation

@tjzel

@tjzel tjzel commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Cherry-picking #10073

…xy (#10073)

## Summary

Closes #9822.

On iOS release builds with `ENABLE_SHARED_ELEMENT_TRANSITIONS: true`
(the default on `main`), the Suspense + Layout Animation Crash example
crashes within ~1–2 seconds with `EXC_BAD_ACCESS` inside
`LayoutAnimationsProxy_Experimental::updateLightTree`. This is the
experimental-proxy counterpart of #9820/#9821: when React re-creates a
tag whose exiting removal the proxy is still withholding (a
re-suspending Suspense boundary deletes a subtree and later re-creates
it with the same fiber tags), the proxy's bookkeeping is contradicted
and corrupts both the light tree and the mounting layer's view registry.

Unlike the legacy proxy — whose `nodeForTag_` tracks every node of a
withheld subtree, so the #9821 reconcile could catch any re-created tag
— the experimental proxy only kept `ANIMATING` roots in `lightNodes_`.
Two whole classes of withheld views were invisible to any reconcile:

- **`WAITING` interior nodes** (e.g. FlatList cell containers kept alive
under an exiting item) — tracked in neither `lightNodes_` nor
`deadNodes`,
- **settled `DEAD` nodes** — already moved to `deadNodes` and erased
from `lightNodes_`, but still mounted until the end-of-transaction
cleanup, which runs *after* an incoming `Create` would have
re-registered the tag.

A `Create` for such a tag passed straight through against a
still-registered old view. Diagnosing with a mutation-stream replay
showed the resulting "double Create" (an iOS `RCTComponentViewRegistry`
overwrite) as the single divergence source; the wrong view then got
recycled by the old node's deferred `Delete`, and subsequent
transactions faulted on null light nodes / stale indices.

The fix mirrors #9821, adapted to the experimental proxy's bookkeeping:

- `reconcileContradictedRemovals` runs at the start of
`pullTransaction`: an incoming `Create`/`Insert` targeting a withheld
tag — found in `lightNodes_` (any non-live state) or in `deadNodes` —
flushes that node's withheld Remove/Delete immediately, before the tag
is re-registered, mirroring the `deadNodes` cleanup in `handleRemovals`.
- `WAITING` subtree members are now registered in `lightNodes_` (both
the kept-subview branch of `startAnimationsRecursively` and the
kept-root branch of `handleRemovals`), so the reconcile can find them —
matching the legacy proxy's per-node bookkeeping.
- `endAnimationsRecursively` and `maybeDropAncestors` erase the deleted
node's `lightNodes_` entry (guarded so a re-registered live node is
never touched). This also fixes a pre-existing stale-entry leak for
animating descendants force-ended together with an exiting ancestor.
- `endLayoutAnimation` replaces an unchecked `lightNodes_[tag]` lookup
with a guarded `find` — the old code would default-insert a null node
and dereference it in release, where the assert is compiled out.

## Test plan

Uses the Suspense + Layout Animation Crash example added in #9821, with
`ENABLE_SHARED_ELEMENT_TRANSITIONS` left at its default (`true`):

1. build `fabric-example` for iOS in Release,
2. open the example and tap Start stress.

Before this change the app crashes within ~1–2 seconds; three
consecutive runs on `main` produced the exact stack reported in #9822
(`SIGSEGV` in `updateLightTree` ← `pullTransaction` ←
`RCTMountingManager performTransaction`). After it, the same stress ran
through hundreds of mode switches (several minutes) with no crash, and a
replay of ~525k logged mutations from an instrumented run showed no
registry overwrites and no index divergence between the emitted
mutations and the mounted hierarchy.

(cherry picked from commit 7225372)
Co-authored-by: Tomasz Żelawski <tzelawski@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1fd51c61-49d5-4b94-95a0-84195e13d39c

📥 Commits

Reviewing files that changed from the base of the PR and between 4da1f39 and eedea3b.

📒 Files selected for processing (2)
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved layout animation handling when elements are removed and quickly reinserted.
    • Prevented outdated exit animations from interfering with newly rendered elements.
    • Improved cleanup of nested elements and related animations during rapid UI updates.
    • Prevented crashes and inconsistent visual states when an element changes while its removal animation is still in progress.

Walkthrough

The experimental layout animation proxy now reconciles reinserted tags with withheld exiting removals, removes stale subtrees and ancestors, safely handles reconciled nodes, and preserves mappings when replacement nodes exist.

Changes

Layout animation reconciliation

Layer / File(s) Summary
Contradicted removal reconciliation
packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp, packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h
pullTransaction reconciles Create and Insert mutations before light-tree updates. The new helper removes stale exiting or DEAD nodes, recursive subtrees, and empty ancestors. Waiting subtree members remain discoverable through lightNodes_.
Node lifecycle and mapping cleanup
packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp
endLayoutAnimation safely handles nodes already reconciled or absent. Reinsertion restores waiting nodes. Cleanup erases mappings only when they still reference the deleted node.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant pullTransaction
  participant reconcileContradictedRemovals
  participant lightNodes_
  participant endLayoutAnimation
  pullTransaction->>reconcileContradictedRemovals: reconcile Create or Insert mutations
  reconcileContradictedRemovals->>lightNodes_: locate withheld or dead nodes
  reconcileContradictedRemovals->>pullTransaction: emit recursive cleanup mutations
  pullTransaction->>endLayoutAnimation: finish animation for a node
  endLayoutAnimation->>lightNodes_: preserve replacement mapping during cleanup
Loading

Possibly related PRs

Suggested reviewers: bartlomiejbloniarz

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the cherry-pick and the crash fix for withheld exiting layout animations in the experimental proxy.
Description check ✅ Passed The description states that the pull request cherry-picks the related change, which is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch @tjzel/4.5-stable/cherry-pick-#10073

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tjzel
tjzel merged commit 9be1217 into 4.5-stable Aug 25, 2026
21 checks passed
@tjzel
tjzel deleted the @tjzel/4.5-stable/cherry-pick-#10073 branch August 25, 2026 12:46
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.

3 participants