cherry-pick(4.5-stable): Fix crash from withheld exiting layout animations in experimental proxy (#10073) - #10207
Merged
Conversation
…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>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe 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. ChangesLayout animation reconciliation
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
bartlomiejbloniarz
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-picking #10073