Skip to content

Stop driving the animation backend after Fabric binding teardown#57379

Open
rozele wants to merge 1 commit into
react:mainfrom
rozele:export-D110150994
Open

Stop driving the animation backend after Fabric binding teardown#57379
rozele wants to merge 1 commit into
react:mainfrom
rozele:export-D110150994

Conversation

@rozele

@rozele rozele commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary:
WARNING: Generated by Autopilot (alpha) - review carefully, verify the underlying claim before accepting.
Agent: React Native Agent | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/d5b9a66a-cdcf-42e7-abc9-823520d1bef6/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/18014401277724259/


AnimationBackendChoreographer registers a self-reposting frame callback with ReactChoreographer that keeps invoking driveAnimationBackend every frame for the lifetime of the choreographer. FabricUIManagerBinding.unregister() tore down the native binding via uninstallFabricUIManager() but left that callback running, so a frame that fired after teardown drove a JNI call through the binding's freed native state — a use-after-teardown that can surface as a native crash during React instance reload/teardown while a Fabric (C++ Native Animated) animation is in flight.

Pause the choreographer and clear its frame callback in unregister() before uninstalling the native binding. A fresh AnimationBackendChoreographer is created on every register() (it is never reused across instances), and pause/resume are driven by the native animation backend on the next animation, so pausing the now-orphaned choreographer at teardown is safe and does not affect a subsequent re-register. Pausing flips a memory-visible AtomicBoolean, so the UI-thread frame callback reliably no-ops even though unregister() may run off the UI thread.

Changelog:
[Android][Fixed] - Stop the Fabric animation frame callback from driving the native binding after teardown, fixing a use-after-teardown native crash

Differential Revision: D110150994

Summary:
WARNING: Generated by Autopilot (alpha) - review carefully, verify the underlying claim before accepting.
Agent: React Native Agent | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/d5b9a66a-cdcf-42e7-abc9-823520d1bef6/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/18014401277724259/

---

`AnimationBackendChoreographer` registers a self-reposting frame callback with `ReactChoreographer` that keeps invoking `driveAnimationBackend` every frame for the lifetime of the choreographer. `FabricUIManagerBinding.unregister()` tore down the native binding via `uninstallFabricUIManager()` but left that callback running, so a frame that fired after teardown drove a JNI call through the binding's freed native state — a use-after-teardown that can surface as a native crash during React instance reload/teardown while a Fabric (C++ Native Animated) animation is in flight.

Pause the choreographer and clear its frame callback in `unregister()` before uninstalling the native binding. A fresh `AnimationBackendChoreographer` is created on every `register()` (it is never reused across instances), and pause/resume are driven by the native animation backend on the next animation, so pausing the now-orphaned choreographer at teardown is safe and does not affect a subsequent re-register. Pausing flips a memory-visible `AtomicBoolean`, so the UI-thread frame callback reliably no-ops even though `unregister()` may run off the UI thread.

Changelog:
[Android][Fixed] - Stop the Fabric animation frame callback from driving the native binding after teardown, fixing a use-after-teardown native crash

Differential Revision: D110150994
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2026
@meta-codesync

meta-codesync Bot commented Jun 30, 2026

Copy link
Copy Markdown

@rozele has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110150994.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant