Skip to content

Make setNativeProps from JS visible to later reads in the same task - #60435

Open
robhogan wants to merge 1 commit into
mainfrom
robhogan/js-set-native-props-refreshes-reads
Open

robhogan wants to merge 1 commit into
mainfrom
robhogan/js-set-native-props-refreshes-reads

Conversation

@robhogan

@robhogan robhogan commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary:

JS layout reads use the shadow tree revision captured for the task, so that a UI-thread commit partway through a task doesn't change what they see. completeSurface refreshes that revision after React commits, but setNativeProps doesn't, so a read, then setNativeProps, then a read in the same task returns the old layout. That includes JS-driven Animated, which applies its values with setNativeProps.

This adds an overload of setNativeProps_DEPRECATED for JS that refreshes the captured revision after a successful commit, as completeSurface does. It takes the runtime just to ensure it's on the JS thread, as EventTarget::release does, and both JS entry points (NativeDOM and nativeFabricUIManager) use it. Native callers keep the existing overload, so a commit from another thread still can't change what JS sees mid-task.

With ResizeObserver enabled, a resize that a callback makes with setNativeProps is now delivered for deeper targets in the same update, rather than at the surface's next commit. A callback that resizes its own target (or anything no deeper than the targets just delivered) now gets the spec's loop error in the console.

With commit branching and a React revision pending, reads still see React's revision, which doesn't include the call. Neither does the tree the merge mounts, until the node is next cloned.

Changelog:

[GENERAL] [FIXED] - Layout reads see earlier setNativeProps calls in the same task, including JS-driven Animated updates

Test Plan:

New Fantom tests for read → setNativeProps → read through both entry points, for a deeper ResizeObserver target resized from a callback in the same update, and for the loop error. All three fail without this change, with commit branching on and off.

The refresh costs ~45ns per call. In an AI-driven Fantom benchmark of 100 setNativeProps calls per task (optimised tester build, 10 interleaved runs), it's within noise of main.

`setNativeProps` commits synchronously, but JS layout reads use the revision captured for the task, and only React's commits refresh it. So a read, then `setNativeProps`, then a read in the same task returns the old layout. JS-driven Animated on Fabric applies its values with `setNativeProps`, so it's affected the same way. `ResizeObserver` gathers against the same revision, so a resize that a callback makes with `setNativeProps` isn't delivered for a deeper target until the surface next commits.

This adds an overload of `setNativeProps_DEPRECATED` for JS, which refreshes the captured revision after a successful commit, as `completeSurface` does. It takes the runtime only to ensure it runs on the JS thread, as `EventTarget::release` does. Both JS entry points, `NativeDOM` and `nativeFabricUIManager`, use it. The existing overload, which nothing else in this repo calls, keeps its behavior for native callers, so a call from another thread still can't change what JS sees partway through a task. It now returns the commit status, so that a cancelled commit doesn't refresh anything.

A `ResizeObserver` callback that resizes an observed target no deeper than the shallowest one delivered in that round, such as its own target, now gets the spec's loop error, logged with `console.error`. When that target is delivered doesn't change: it still waits for the surface's next commit.

With commit branching and a React revision pending, later reads and `ResizeObserver` see React's revision, which doesn't include the call. Neither does the tree that the merge mounts, until the node is next cloned and its stored props are applied again.

Changelog: [General][Fixed] - Layout reads see earlier `setNativeProps` calls in the same task, including JS-driven Animated updates
@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 Dec 1, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 1, 2026
@robhogan

robhogan commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

FYI - This is part of an effort to make #60355 a cleaner architectural fit - it's one of a few smaller foundational changes, each one a self-contained fix, and should be easier to validate.

@robhogan
robhogan marked this pull request as ready for review December 1, 2026 16:38
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 1, 2026

This branch has not been deployed

No deployments
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 Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant