Repository navigation
Fix crash from withheld exiting layout animations in legacy proxy - #9821
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a release-only iOS crash in the legacy LayoutAnimationsProxy_Legacy when React reuses a tag that still has a withheld exiting Remove/Delete, by reconciling (flushing) contradicted removals at the start of each mounting transaction and hardening endLayoutAnimation against an unsafe node cast.
Changes:
- Add
reconcileContradictedRemovalsto flush withheld exiting removals when an incomingCreate/Inserttargets the same tag. - Replace a release-unsafe
react_native_assert+ cast inendLayoutAnimationwith a runtime guard. - Add a Suspense + layout animation crash repro example and register it in the common app; adjust
fabric-examplestatic flag to exercise the legacy proxy.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h | Declares the new reconciliation helper for contradicted removals. |
| packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp | Implements reconciliation at transaction start and hardens endLayoutAnimation against invalid node type assumptions in release. |
| apps/fabric-example/package.json | Sets ENABLE_SHARED_ELEMENT_TRANSITIONS to false to run the legacy proxy path in the example app. |
| apps/common-app/src/apps/reanimated/examples/SuspenseLayoutAnimationCrashExample.tsx | Adds a minimal repro/stress example for the Suspense + exiting layout animation crash scenario. |
| apps/common-app/src/apps/reanimated/examples/index.ts | Registers the new crash repro example in the examples list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
94504f5 to
7a30553
Compare
The legacy LayoutAnimationsProxy withholds Remove/Delete mutations for views animating out. When React re-creates or re-inserts a tag whose exiting removal is still withheld, the stale removal later fired against a hierarchy that no longer matched and unmounted the wrong, still-live view, crashing the mounting layer in iOS release builds. Reconcile such contradicted removals at the start of each transaction by flushing the withheld Remove/Delete before the tag is re-registered, and replace an unchecked MutationNode cast in endLayoutAnimation with a runtime guard (the assert guarding it is compiled out in release). Also tidy the repro example: keep ENABLE_SHARED_ELEMENT_TRANSITIONS at its default in fabric-example (the repro step to flip it stays in the PR test plan), alphabetize the lazy require, update copy that described the pre-fix crash, and clear the stress interval on unmount now that the example survives. Closes #9820.
7a30553 to
d38c3ec
Compare
LayoutAnimationsManager.stop() now actually cancels the running style animation with cancelAnimation() (firing the animation callbacks with finished=false) instead of only detaching the progress listener. Previously a cancelled exiting animation kept stepping invisibly and later delivered a stale _notifyAboutEnd with removeView=true for a tag whose native bookkeeping was gone - or already reused by a new animation. stop() no longer notifies native at all (native erases the tag before scheduling the stop); the restart path in start() still does, as its notify decrements the native count. withStyleAnimation now takes the completion callback as a parameter and composes it with its internal cancellation fan-out, so inner per-prop animation callbacks observe the cancellation and the manager no longer overwrites the callback slot the fan-out lives in. With cancellation propagated, endLayoutAnimation can no longer run for a tag whose MutationNode was replaced - upgrade the runtime guard back to an assert.
d38c3ec to
ddada44
Compare
|
I updated the code so that we actually cancel the layout animation running, instead of detaching from it and running it to completion in the background. This brought about an issue with the callback not accumulating callbacks of inner animations in a custom layout animation, so I had to update the callback flow. Here's an ai write up on that
|
onExitSettled |
|
|---|---|
| before this PR | fires ~400 ms later with true (animation was never really stopped) |
| this PR, without the parameter change | never fires (interrupted, fan-out disconnected) |
| this PR | fires immediately with false |
Same mechanism covers withSequence/withDelay inside layout-animation configs —
their cancel-the-remaining-segments logic is also delivered through that fan-out.
…tions in legacy proxy (#9976) ## Summary Cherry-pick of #9821 to `4.3-stable` (both commits). On iOS release builds, an app that runs exiting layout animations under a Suspense boundary that keeps re-suspending crashes inside React Native's mount transaction within a few seconds. This happens with ENABLE_SHARED_ELEMENT_TRANSITIONS set to false, which is where the legacy LayoutAnimationsProxy is active. The legacy proxy withholds Remove and Delete mutations for views that are animating out. When React later re-creates or re-inserts a tag whose exiting removal is still being withheld, the proxy kept the stale bookkeeping instead of reconciling it. The withheld removal then fired in a later frame against a hierarchy that no longer matched, unmounting the wrong, still-mounted view and corrupting the mounting layer. The first commit reconciles those contradicted removals at the start of each transaction: if an incoming Create or Insert targets a tag that still has a withheld exiting removal, that removal is flushed right away, before the tag is re-registered, instead of firing later against a stale hierarchy. The second commit makes `LayoutAnimationsManager.stop()` actually cancel the running style animation with `cancelAnimation()` (firing animation callbacks with `finished=false`) instead of only detaching the progress listener, so a cancelled exiting animation no longer keeps stepping invisibly and delivering a stale `_notifyAboutEnd` for a tag whose native bookkeeping is gone or reused. `withStyleAnimation` now takes the completion callback as a parameter and composes it with its internal cancellation fan-out. With cancellation propagated, the runtime guard in `endLayoutAnimation` is upgraded back to an assert. Conflicts resolved during cherry-pick: - `examples/index.ts` — re-applied the example registration in this branch's direct-import style (main uses lazy `require()`) - `LayoutAnimationsProxy_Legacy.cpp` — surrounding context differs on this branch; the guard is inserted directly after the node lookup - `animationsManager.ts` — `stopObservingProgress` has no `scheduleFlush` parameter on this branch; the new `stop()` body applies unchanged - the repro example is reformatted to this branch's Prettier config (single quotes, `bracketSameLine`) ## Test plan Same as #9821: set ENABLE_SHARED_ELEMENT_TRANSITIONS to false in apps/fabric-example, build fabric-example for iOS in Release, open the Suspense + Layout Animation Crash example, tap Start stress. Before the change the app crashes within seconds; after it, it keeps running. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Bartłomiej Błoniarz <[email protected]>
…tions in legacy proxy (#9985) ## Summary Cherry-pick of #9821 to `4.4-stable` (both commits). On iOS release builds, an app that runs exiting layout animations under a Suspense boundary that keeps re-suspending crashes inside React Native's mount transaction within a few seconds. This happens with ENABLE_SHARED_ELEMENT_TRANSITIONS set to false, which is where the legacy LayoutAnimationsProxy is active. The legacy proxy withholds Remove and Delete mutations for views that are animating out. When React later re-creates or re-inserts a tag whose exiting removal is still being withheld, the proxy kept the stale bookkeeping instead of reconciling it. The withheld removal then fired in a later frame against a hierarchy that no longer matched, unmounting the wrong, still-mounted view and corrupting the mounting layer. The first commit reconciles those contradicted removals at the start of each transaction: if an incoming Create or Insert targets a tag that still has a withheld exiting removal, that removal is flushed right away, before the tag is re-registered, instead of firing later against a stale hierarchy. The second commit makes `LayoutAnimationsManager.stop()` actually cancel the running style animation with `cancelAnimation()` (firing animation callbacks with `finished=false`) instead of only detaching the progress listener, so a cancelled exiting animation no longer keeps stepping invisibly and delivering a stale `_notifyAboutEnd` for a tag whose native bookkeeping is gone or reused. `withStyleAnimation` now takes the completion callback as a parameter and composes it with its internal cancellation fan-out. With cancellation propagated, the runtime guard in `endLayoutAnimation` is upgraded back to an assert. Both commits applied cleanly; the only adaptation is reformatting the repro example to this branch's oxfmt config (single quotes, `bracketSameLine`). ## Test plan Same as #9821: set ENABLE_SHARED_ELEMENT_TRANSITIONS to false in apps/fabric-example, build fabric-example for iOS in Release, open the Suspense + Layout Animation Crash example, tap Start stress. Before the change the app crashes within seconds; after it, it keeps running. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Bartłomiej Błoniarz <[email protected]>
…tions in legacy proxy (#9984) ## Summary Cherry-pick of #9821 to `4.5-stable` (both commits). On iOS release builds, an app that runs exiting layout animations under a Suspense boundary that keeps re-suspending crashes inside React Native's mount transaction within a few seconds. This happens with ENABLE_SHARED_ELEMENT_TRANSITIONS set to false, which is where the legacy LayoutAnimationsProxy is active. The legacy proxy withholds Remove and Delete mutations for views that are animating out. When React later re-creates or re-inserts a tag whose exiting removal is still being withheld, the proxy kept the stale bookkeeping instead of reconciling it. The withheld removal then fired in a later frame against a hierarchy that no longer matched, unmounting the wrong, still-mounted view and corrupting the mounting layer. The first commit reconciles those contradicted removals at the start of each transaction: if an incoming Create or Insert targets a tag that still has a withheld exiting removal, that removal is flushed right away, before the tag is re-registered, instead of firing later against a stale hierarchy. The second commit makes `LayoutAnimationsManager.stop()` actually cancel the running style animation with `cancelAnimation()` (firing animation callbacks with `finished=false`) instead of only detaching the progress listener, so a cancelled exiting animation no longer keeps stepping invisibly and delivering a stale `_notifyAboutEnd` for a tag whose native bookkeeping is gone or reused. `withStyleAnimation` now takes the completion callback as a parameter and composes it with its internal cancellation fan-out. With cancellation propagated, the runtime guard in `endLayoutAnimation` is upgraded back to an assert. Both commits applied cleanly; the only adaptation is reformatting the repro example to this branch's oxfmt config (single quotes, `bracketSameLine`). ## Test plan Same as #9821: set ENABLE_SHARED_ELEMENT_TRANSITIONS to false in apps/fabric-example, build fabric-example for iOS in Release, open the Suspense + Layout Animation Crash example, tap Start stress. Before the change the app crashes within seconds; after it, it keeps running. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Bartłomiej Błoniarz <[email protected]>
) ## Summary Closes #9820. On iOS release builds, an app that runs exiting layout animations under a Suspense boundary that keeps re-suspending crashes inside React Native's mount transaction within a few seconds. This happens with ENABLE_SHARED_ELEMENT_TRANSITIONS set to false, which is where the legacy LayoutAnimationsProxy is active. The legacy proxy withholds Remove and Delete mutations for views that are animating out. When React later re-creates or re-inserts a tag whose exiting removal is still being withheld, the proxy kept the stale bookkeeping instead of reconciling it. The withheld removal then fired in a later frame against a hierarchy that no longer matched, unmounting the wrong, still-mounted view and corrupting the mounting layer. This reconciles those contradicted removals at the start of each transaction: if an incoming Create or Insert targets a tag that still has a withheld exiting removal, that removal is flushed right away, before the tag is re-registered, instead of firing later against a stale hierarchy. It also replaces an unchecked MutationNode cast in endLayoutAnimation with a runtime guard, since the assert that used to guard it is compiled out in release builds and the node can legitimately be a plain Node after a reparenting move. ## Test plan Adds the Suspense + Layout Animation Crash example to fabric-example. To reproduce: 1. set ENABLE_SHARED_ELEMENT_TRANSITIONS to false in apps/fabric-example 2. build fabric-example for iOS in Release 3. open the example and tap Start stress Before this change the app crashes within a few seconds. After it, the example keeps running and animating under the same stress. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Bartłomiej Błoniarz <[email protected]>
…xy (software-mansion#10073) ## Summary Closes software-mansion#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 software-mansion#9820/software-mansion#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 software-mansion#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 software-mansion#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 software-mansion#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 software-mansion#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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <[email protected]>
…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 <[email protected]>
`endLayoutAnimation` returned early on the animation counter before it consumed `shouldRemove`, and the flag was not persisted anywhere. A tag can have several layout animations outstanding at once (`LayoutAnimation::count` is bumped for every animation started while a live entry exists), but only the exiting one passes `shouldRemove == true`. When the exiting animation was not the last to finish, its removal intent was dropped: the call that brought the counter to zero carried `shouldRemove == false`, the node never reached `DEAD`, and the withheld `Remove`/`Delete` mutations were never flushed. The view stayed mounted for the lifetime of the surface, still absorbing touches even though React considered it gone. Latch the intent into `LayoutAnimation::isExitingWhenSettled` before the counter can return early, and read it back once the tag settles, so the removal survives whichever animation happens to finish last. The field already carried exactly this meaning at settle time and is only read behind `isSettled()`, so existing readers are unaffected. Both proxies had the identical shape and both are fixed. This is the second of the two adjacent hardenings listed in software-mansion#9820; software-mansion#9821 landed the contradicted-removal reconciliation but not this one. Fixes software-mansion#10275
Summary
Closes #9820.
On iOS release builds, an app that runs exiting layout animations under a Suspense boundary that keeps re-suspending crashes inside React Native's mount transaction within a few seconds. This happens with ENABLE_SHARED_ELEMENT_TRANSITIONS set to false, which is where the legacy LayoutAnimationsProxy is active.
The legacy proxy withholds Remove and Delete mutations for views that are animating out. When React later re-creates or re-inserts a tag whose exiting removal is still being withheld, the proxy kept the stale bookkeeping instead of reconciling it. The withheld removal then fired in a later frame against a hierarchy that no longer matched, unmounting the wrong, still-mounted view and corrupting the mounting layer.
This reconciles those contradicted removals at the start of each transaction: if an incoming Create or Insert targets a tag that still has a withheld exiting removal, that removal is flushed right away, before the tag is re-registered, instead of firing later against a stale hierarchy. It also replaces an unchecked MutationNode cast in endLayoutAnimation with a runtime guard, since the assert that used to guard it is compiled out in release builds and the node can legitimately be a plain Node after a reparenting move.
Test plan
Adds the Suspense + Layout Animation Crash example to fabric-example. To reproduce:
Before this change the app crashes within a few seconds. After it, the example keeps running and animating under the same stress.
🤖 Generated with Claude Code