Skip to content

Add unstable_flushSync export to react-native - #60491

Merged
rubennorte merged 1 commit into
react:mainfrom
rubennorte:rn-unstable-flushsync
Dec 3, 2026
Merged

rubennorte merged 1 commit into
react:mainfrom
rubennorte:rn-unstable-flushsync

Conversation

@rubennorte

@rubennorte rubennorte commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary:

Exports unstable_flushSync from react-native, with the same semantics as flushSync from react-dom. 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 #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.

Changelog:

[INTERNAL] [ADDED] - Add unstable_flushSync export to react-native behind the enableFlushSync feature flag (disabled by default)

Test Plan:

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
# Tests: 9 skipped (flag dimension), 203 passed, 212 total
yarn build-types && yarn test-generated-typescript   # pass, no ReactNativeApi.d.ts change
yarn flow                                            # no new errors
yarn eslint <changed files>                          # clean

@rubennorte
rubennorte force-pushed the rn-unstable-flushsync branch from 5ccdcce to 8d97d5e Compare December 2, 2026 17:40
@rubennorte rubennorte changed the title Add canary unstable_flushSync export to react-native Add unstable_flushSync export to react-native Dec 2, 2026
@rubennorte
rubennorte force-pushed the rn-unstable-flushsync branch from 8d97d5e to 4b18459 Compare December 2, 2026 18:42
@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 2, 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
rubennorte force-pushed the rn-unstable-flushsync branch from 4b18459 to 9020595 Compare December 3, 2026 14:24
@rubennorte
rubennorte merged commit 6ff2bcd into react:main Dec 3, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants