Skip to content

Avoid redundant work in View props diffing - #59681

Open
coado wants to merge 6 commits into
react:mainfrom
coado:export-D128623431
Open

coado wants to merge 6 commits into
react:mainfrom
coado:export-D128623431

Conversation

@coado

@coado coado commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary:
Small cleanups in HostPlatformViewProps::getDiffProps, which runs for every View update with props diffing and is also called by the Image, ScrollView, Paragraph and TextInput diffs:

  • The diff helpers (updateEventProp, updateBorderWidthPropValue, updateBorderRadiusPropValue, updateBorderColorPropValue, updateNativeDrawableProp) took the prop name as const std::string& but are always called with literals, so every call built a temporary std::string, also for unchanged values. Names longer than the small-string buffer (e.g. borderBottomRightRadius, onStartShouldSetResponderCapture) allocated on the heap. They now take const char*.
  • A transformOrigin-only change rebuilt and resent the whole transform array. BaseViewManager.setTransformOrigin already marks the transform invalid and onAfterUpdateTransaction re-applies the stored transform, so transform is now only sent when it changes. For a View that sets only transformOrigin, Java now keeps a null transform instead of receiving []; both reset the view to the identity transform.
  • Built folly::dynamic arrays/objects (accessibility actions, value, labelled-by, order, native drawables) were copied into the result instead of moved.

Changelog:
[Internal]

Differential Revision: D128623431

Dawid Małecki and others added 6 commits October 30, 2026 05:38
Summary:
Props diffing (`enablePropsUpdateReconciliationAndroid`) applies to every component whose props implement `getDiffProps`, which includes all codegen components. On view creation, props equal to their C++ default are not sent, so a native component whose default differs from the C++ default ends up with the wrong value. Third-party components have not been checked for this, which makes the existing flag unsafe to try in OSS.

This adds `enableCoreComponentsPropsUpdateReconciliationAndroid`, released in the experimental stage, which enables props diffing only for the core components with hand-written props (View, Paragraph, Text, RawText, TextEffect, Image, ScrollView). All other components keep receiving raw props.

TextInput is intentionally not included: on Android its component name is `AndroidTextInput` while its props report `TextInput` as the diffing target, so props diffing has never applied to it under either flag. Fixing that is left for a separate change.

The decision now lives in a single non-virtual function, `isPropsDiffingEnabled`, used by both `FabricMountingManager::getProps` and `ConcreteComponentDescriptor::cloneProps`, so the two decisions cannot diverge. Behavior with the new flag off is unchanged.

The Android ScrollViews (vertical, nested and horizontal) switch their native default `overflow` from `scroll` to `visible` under props diffing, because the C++ default `visible` is never sent. This switch only checked `enablePropsUpdateReconciliationAndroid`, so with only the new flag enabled ScrollViews clipped their content. The default is now resolved in one place, `ReactScrollViewHelper.getDefaultOverflow()`, which checks both flags.

Changelog:
[Android][Added] - Add experimental feature flag `enableCoreComponentsPropsUpdateReconciliationAndroid` to send prop updates based on props diffing for core components only

Differential Revision: D127587361
Summary:
`isPropsDiffingEnabled` only uses props diffing when a component's name matches the target returned by its props' `getDiffPropsImplementationTarget()`. On Android the TextInput component is named `AndroidTextInput`, but `AndroidTextInputProps` returned `TextInput`. The check always failed, so TextInput never used props diffing, even with `enablePropsUpdateReconciliationAndroid` on. It kept receiving raw props (or accumulated raw props) instead, and `AndroidTextInputProps::getDiffProps` was never called.

This makes `AndroidTextInputProps` return `AndroidTextInput` and adds it to the core components covered by `enableCoreComponentsPropsUpdateReconciliationAndroid`.

This changes behavior for anyone with `enablePropsUpdateReconciliationAndroid` enabled: TextInput now receives diffed props built by `AndroidTextInputProps::getDiffProps`, a code path that has not been exercised before. With both props diffing flags off, behavior is unchanged.

Changelog:
[Android][Fixed] - Fix props diffing never being applied to `TextInput` when props update reconciliation is enabled

Differential Revision: D128563541
Summary:
With props diffing, a prop whose value equals its C++ default is not sent when the view is created, so the C++ default has to match the state of a newly created native view. Several `AndroidTextInputProps` fields did not:

- `showSoftInputOnFocus` and `allowFontScaling` defaulted to `false` in C++ but are `true` natively, so setting them to `false` from JS had no effect.
- `autoCorrect` was a plain `bool` defaulting to `false`, while the native setter has three states (on, off, unset). `autoCorrect={false}` was never sent and removing the prop could not restore the platform default. It is now `std::optional<bool>` and is sent as `null` when unset.
- `numberOfLines`, `textBreakStrategy` and `includeFontPadding` were each emitted twice, once from the paragraph attributes and once from a duplicate flat field, with the later one overwriting the earlier. The flat `includeFontPadding` defaulted to `false` while the native default is `true`, so removing `includeFontPadding={true}` sent `false`. These keys are now only emitted from the paragraph attributes.

The flat fields are not used for layout, which reads the paragraph and text attributes, so only the props sent to the native view change.

Changelog:
[Android][Fixed] - Fix `TextInput` props `showSoftInputOnFocus`, `allowFontScaling`, `autoCorrect` and `includeFontPadding` being ignored or reset incorrectly when props diffing is enabled

Differential Revision: D128594780
Summary:
`HostPlatformViewProps::getDiffProps` sends a `scroll` key with the same value as `overflow` whenever clipping changes. No Android view manager has a `scroll` prop and nothing reads that key directly; every component reads `overflow`. `ViewProps.SCROLL` is the overflow value `"scroll"`, not a prop name. The key only adds a JNI string and a failed setter lookup per update, so remove it.

Changelog:
[Internal]

Differential Revision: D128598698
Summary:
`executeMount` queues an `UpdateProps` mount item whenever the props pointer of a view changes, but with props diffing the diff was only computed later, while writing the instruction buffer. A new props object does not mean there is anything to update: layout-only changes (`width`, `flex`, `margin`, ...) create new props, but layout props are applied through `UpdateLayout`/`UpdatePadding` and are not part of the diff. Those items still created an empty `ReadableNativeMap` over JNI, used a buffer slot, and on the Java side allocated a `ReactStylesDiffMap` and ran `updateProperties` plus `onAfterUpdateTransaction` (accessibility update, `ReactImageView.maybeUpdateView`, `ReactTextView.updateView`, ...) without applying anything.

The buffer size and item counts are fixed before the buffer is written, so the diff is now computed when the mount item is created and the item is dropped when the diff is empty. The computed diff is kept in the item (`CppMountItem::diffProps`, a `unique_ptr` so items cannot be copied by accident) and moved into the Java map when the buffer is written, so every diff is still computed exactly once, under the same lock as before.

This applies to every `UpdateProps` item created in `executeMount` (update, and the insert paths for preallocated views). Skipping an empty map applies the same setters as sending it (none); the differences are that `onAfterUpdateTransaction` no longer runs and `ViewState.currentProps` keeps the previous props map instead of an empty one. Components without props diffing (and builds with props diffing off) are unchanged. Create items are unchanged.

Changelog:
[Internal]

Differential Revision: D128610033
Summary:
Small cleanups in `HostPlatformViewProps::getDiffProps`, which runs for every View update with props diffing and is also called by the Image, ScrollView, Paragraph and TextInput diffs:

- The diff helpers (`updateEventProp`, `updateBorderWidthPropValue`, `updateBorderRadiusPropValue`, `updateBorderColorPropValue`, `updateNativeDrawableProp`) took the prop name as `const std::string&` but are always called with literals, so every call built a temporary `std::string`, also for unchanged values. Names longer than the small-string buffer (e.g. `borderBottomRightRadius`, `onStartShouldSetResponderCapture`) allocated on the heap. They now take `const char*`.
- A `transformOrigin`-only change rebuilt and resent the whole `transform` array. `BaseViewManager.setTransformOrigin` already marks the transform invalid and `onAfterUpdateTransaction` re-applies the stored transform, so `transform` is now only sent when it changes. For a View that sets only `transformOrigin`, Java now keeps a `null` transform instead of receiving `[]`; both reset the view to the identity transform.
- Built `folly::dynamic` arrays/objects (accessibility actions, value, labelled-by, order, native drawables) were copied into the result instead of moved.

Changelog:
[Internal]

Differential Revision: D128623431
@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 Oct 30, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner p: Facebook Partner: Facebook labels Oct 30, 2026
@meta-codesync

meta-codesync Bot commented Oct 30, 2026

Copy link
Copy Markdown

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

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-exported p: Facebook Partner: Facebook p: Software Mansion Partner: Software Mansion Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant