Repository navigation
Add unstable_flushSync export to react-native - #60491
Merged
Merged
Conversation
rubennorte
force-pushed
the
rn-unstable-flushsync
branch
from
December 2, 2026 17:40
5ccdcce to
8d97d5e
Compare
unstable_flushSync export to react-nativeunstable_flushSync export to react-native
rubennorte
force-pushed
the
rn-unstable-flushsync
branch
from
December 2, 2026 18:42
8d97d5e to
4b18459
Compare
javache
approved these changes
Dec 3, 2026
Exports `unstable_flushSync` from `react-native`, with the same semantics as [`flushSync` from `react-dom`](https://react.dev/reference/react-dom/flushSync). It's needed to read layout right after an update, or to apply updates from a `ResizeObserver` callback on the same frame as the size change. The renderer implementation landed in React (react/react#38475) and was synced in react#60470. This change: - Re-exports `ReactFabric.flushSync` from `RendererImplementation`/`RendererProxy` and the jest-preset `RendererProxy` mock. - Adds a lazy `unstable_flushSync` getter to `index.js`, gated by a new `enableFlushSync` feature flag. The flag is off by default and isn't enabled in any OSS release stage yet (`ossReleaseStage: 'none'`); that will be flipped separately. When the flag is off, the export is `undefined`, so it's typed `?typeof flushSync`. [INTERNAL] [ADDED] - Add `unstable_flushSync` export to `react-native` behind the `enableFlushSync` feature flag (disabled by default) New Fantom tests in `flushSync-itest.js`, run with the flag on and off: - flushes updates before returning (vs. deferred without it); - opts out of transitions; - returns the callback's value, or `undefined` with no callback; - propagates errors from the callback and still flushes; - flushes pending discrete work when called with no callback, using a real discrete native event; - warns in DEV and defers the update when called during commit; - isn't exported when the flag is off. New `ResizeObserver` Fantom tests show that updates flushed with `unstable_flushSync` in the observer callback are mounted in the same layout pass, while updates without it land in a later one. ``` yarn fantom packages/react-native/Libraries/ReactNative/__tests__/flushSync-itest.js \ packages/react-native/src/private/webapis/resizeobserver/__tests__/ResizeObserver-itest.js yarn build-types && yarn test-generated-typescript # pass, no ReactNativeApi.d.ts change yarn flow # no new errors yarn eslint <changed files> # clean ``` Signed-off-by: Rubén Norte <rubennorte@meta.com>
rubennorte
force-pushed
the
rn-unstable-flushsync
branch
from
December 3, 2026 14:24
4b18459 to
9020595
Compare
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:
Exports
unstable_flushSyncfromreact-native, with the same semantics asflushSyncfromreact-dom. It's needed to read layout right after an update, or to apply updates from aResizeObservercallback on the same frame as the size change.The renderer implementation landed in React (react/react#38475) and was synced in #60470. This change:
ReactFabric.flushSyncfromRendererImplementation/RendererProxyand the jest-presetRendererProxymock.unstable_flushSyncgetter toindex.js, gated by a newenableFlushSyncfeature flag. The flag is off by default and isn't enabled in any OSS release stage yet (ossReleaseStage: 'none'); that will be flipped separately. When the flag is off, the export isundefined, so it's typed?typeof flushSync.Changelog:
[INTERNAL] [ADDED] - Add
unstable_flushSyncexport toreact-nativebehind theenableFlushSyncfeature flag (disabled by default)Test Plan:
New Fantom tests in
flushSync-itest.js, run with the flag on and off:undefinedwith no callback;New
ResizeObserverFantom tests show that updates flushed withunstable_flushSyncin the observer callback are mounted in the same layout pass, while updates without it land in a later one.