Repository navigation
cherry-pick(4.5-stable): Prevent animated views from reverting to stale values after app pause or re-animation - #9987
Merged
Conversation
…pause or re-animation (#9527) ## Summary This PR fixes the following issues: * #9478 * #9574 * #9635 * #9614 (likely — no reproduction available, but same symptom class) * #9965 The `FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS` mechanism periodically syncs settled animated values back to React state (`settledProps`) so that the corresponding entries can be evicted from the C++ registry, keeping React commits cheap. This PR fixes two defects in that mechanism. ## Fixed scenarios **Settled values evicted before ever reaching React.** Eviction was time-based: entries older than 2 seconds were removed at the start of every sync, before collection. The catch is that the timestamps come from a monotonic clock that keeps running while the app is paused, but the garbage collector only ticks when the JS thread does. If an animation settled and the app was paused before the next sync — browser intent (#9574), Google Play billing sheet or permission dialog (#9635), camera intent or notification tap (report under #9574), or simply a heavy render blocking the JS thread (#9478) — the first tick after resume evicted the entry without syncing it. The next React commit then reverted the view to a stale or initial value: modals coming back collapsed, views invisible, composers stranded at a stale transform. Re-running the same animation didn't repair the view, because the shared value already held the target value, so no new update was produced. This is fixed by evicting entries based on their sync status instead of elapsed time — an entry can only be removed after React has received its value. **Stale `settledProps` on re-animation.** `settledProps` was write-only: once a value was synced, JS never re-checked it. When an already-synced view animated again, React kept the old snapshot until the new value settled and got synced (up to ~1.5 s); any React commit landing in that window applied the stale value — the bottom-sheet collapse from #9478. This is fixed by tracking which tags React has a snapshot for and invalidating them as soon as a fresh worklet update arrives; the refreshed value reaches React on the next tick (≤500 ms). ## What changed * `AnimatedPropsRegistry` gains two tag sets: `syncedTags_` (values React already has) and `invalidatedTags_` (synced tags that received a fresh update since). `update()` moves a tag from the first set to the second, which schedules a refresh. `removeTag()` clears both on unmount, so nothing outlives its view. * `getUpdatesOlderThanTimestamp` is renamed to `collectSettledUpdates` (it evicts and returns invalidated entries, so the old name no longer described it) and now does a single pass: evict synced entries, collect settled or invalidated ones. * The second timestamp threshold (eviction at 2 s) is removed. It was a wall-clock proxy for "React already has this value", and time passing doesn't guarantee that — that's exactly the first bug. `syncedTags_` tracks the real condition directly, which is safe because the sync `setState` is always committed before the next tick runs (both happen on the JS thread). Entries are now evicted one tick after syncing instead of lingering for 2 s, and the settle threshold (1 s) is the mechanism's only remaining time constant. * Each settled value is synced exactly once. Previously an entry was returned on every tick of its settled window, triggering 2–3 redundant `setState` calls and React commits per animation. * Fixed a view-counter drift in `PropsRegistryGarbageCollector`: nested animated components share a viewTag and unregistered twice while registering once, which could leave the sync interval running forever or prevent it from restarting. * `FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS` and `USE_ANIMATION_BACKEND` are now declared conflicting and validated at build time (Gradle and `pod install`). The animation backend bypasses the registry, so the settled-props mechanism would be dead weight and `timestampMap_` entries would never be evicted. Runtime guards additionally disable the mechanism when the backend is enabled, and the feature flags documentation explains the conflict. ## Approaches considered * Not evicting registry entries at all (pre-4.2 behavior) — reverts the performance win the flag exists for (#7480). * Syncing the full registry on every tick — a `setState` per animating component every 500 ms. * Reordering `settledProps` in the style array — doesn't help when the prop only exists in the animated style, which is filtered out of the React render. * Tracking sync status per tag and invalidating on fresh updates (chosen) — minimal new state, no work added outside the flag's code path. ## Compatibility No JSI bindings are added, removed or changed — `getSettledUpdates` keeps its name, signature and return shape. This makes the PR safe for OTA updates in both directions (new JS bundle on old native and vice versa) and suitable for a patch release. Note that the fixes live on the native side, so an OTA update alone does not deliver them. ## Test plan * Reproduced and verified against two scenarios in `EmptyExample` on an Android emulator: a pause/resume repro (animate, background the app before the sync, wait, resume, trigger a re-render) and a verbatim port of the #9574 repro (modal scale animation, press-driven `Linking.openURL`, return from browser). Both reproduce on `main` and are fixed on this branch. * Verified single sync per settled value and eviction on the following tick via debug logging. * Exercised the new build-time validation on both platforms (Gradle build fails with both flags enabled; the Ruby assertion verified standalone). * Still pending: confirmation from the #9478 reporters on their `@gorhom/bottom-sheet` setups. ## Known limitations (accepted, deferred) A tag is marked as synced when its value is returned to JS, not when React commits it. If the delivery is a no-op (component missing from `viewsMap`, e.g. unmounting mid-tick), the entry is evicted one tick later without React having the value. This hole existed before this PR (with a wider accidental grace window) and only affects views that are going away. The airtight fix is a commit-time acknowledgment; it was prototyped and set aside as not worth the extra JSI surface until a real-world report shows a mounted view losing a delivered value. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Oleksii Bulenok <63914185+abulenok@users.noreply.github.com>
bartlomiejbloniarz
approved these changes
Jul 17, 2026
Merged
6 tasks
5 of 9 tasks
nrb-dev
added a commit
to nightly-labs/openbot
that referenced
this pull request
Oct 19, 2026
* Keep home list agents visible after leaving a chat Reanimated 4.5.1 deletes a settled animated value from its native registry 2 s after the value arrives, also when the JS sync has not copied it into React yet. A JS stall or an app pause skips the sync. A GestureDetector around an Animated.View also counts its view twice on unmount, so leaving a chat can stop the sync timer. The next React commit then puts the view back to its first-render style. On the home list that style hides rows: the reveal wrapper starts at opacity 0, and a row body has no React height while its content is absolute. Agents disappeared after a chat until a section collapse wrote new values. Reanimated 4.5.3 evicts an entry only after React has it and fixes the view count (software-mansion/react-native-reanimated#9987). Use 4.5.5, the last 4.5 release, and keep the Android patch, which applies as is. * Give the current Reanimated version and patch in the mobile README
priyamrmore
pushed a commit
to mieweb/pulse
that referenced
this pull request
Oct 28, 2026
…can't go blank 4.5.1 deletes animated values older than 2 s before handing values older than 1 s back to React. When the JS thread is busy for over a second (opening the editor probes files and reads waveforms) the clips area's "shown" opacity was dropped before React got it, and the next render put back the opacity of its first render: hidden when the editor opened on a tapped clip. Both views went blank and stayed blank. Fixed upstream in 4.5.3 (software-mansion/react-native-reanimated#9987, for issue #9965): values are kept until React has them. Native change: rebuild. Expo SDK 57 lists 4.5.1; 4.5.5 has the same peer ranges.
mikhail-create
pushed a commit
to RonasIT/open-webui-react-native
that referenced
this pull request
Oct 29, 2026
…elds Bump react-native-reanimated to 4.5.5, which fixes stale settled animation props (software-mansion/react-native-reanimated#9987) that could reset the floated label to the centre. Requires a native rebuild. Mask the change password fields with isPassword. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 10 tasks
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.
Summary
Cherry-pick of #9527 to
4.5-stable.Fixes the
FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONSmechanism so animated views no longer revert to stale values after app pause or re-animation:settledPropssnapshots are invalidated as soon as a fresh worklet update arrives for an already-synced tag, so a React commit during a re-animation no longer applies a stale value.setStatecalls per animation).PropsRegistryGarbageCollectorfor nested animated components.FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONSandUSE_ANIMATION_BACKENDare declared conflicting and validated at build time; runtime guards disable the mechanism when the backend is enabled.Fixes #9478, #9574, #9635, #9965 (and likely #9614) on the 4.5 line. No JSI bindings are added, removed or changed, so this is safe for OTA updates in both directions and suitable for a patch release. See #9527 for the full analysis, approaches considered, and known limitations.
The squashed commit applied cleanly with no conflicts; the resulting diff is identical to the one merged to
main.Test plan
Same as #9527 — both repro scenarios (pause/resume and the #9574 modal +
Linking.openURLport) were verified fixed on the original branch, which this backport reproduces byte-for-byte.🤖 Generated with Claude Code