Skip to content

Generate setProp for codegen Props so codegen components can use the iterator setter - #60492

Open
hryhoriiK97 wants to merge 1 commit into
react:mainfrom
hryhoriiK97:codegen-props-setprop
Open

hryhoriiK97 wants to merge 1 commit into
react:mainfrom
hryhoriiK97:codegen-props-setprop

Conversation

@hryhoriiK97

@hryhoriiK97 hryhoriiK97 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

With enableCppPropsIteratorSetter on, cloneProps builds props by copying the previous props and calling setProp for each changed prop, instead of running the constructor that looks up every prop (#57328). It only does this for Props classes that declare their own setProp. Codegen-generated Props never do, so ActivityIndicator, Switch, Modal, RefreshControl, VirtualView and library components with codegen Props get nothing from the flag.

This change:

  • Generates a setProp for each codegen Props class. Each prop gets exactly what the constructor's convertRawProp gives it: same type and default, null restores the default, and conversion errors fall back to the default.
  • Moves convertRawProp's handling of a present value into convertRawPropValue so both paths share it.
  • Guards generated setProp with #ifdef RN_HAS_CONVERT_RAW_PROP_VALUE, so code generated by this codegen still compiles against an older React Native.
  • Value-initializes the generated enum mask wrapper, whose parser ORs into a mask that was uninitialized.

With the flag off, props are built as before, apart from the mask fix.

Most of the diff is codegen snapshots. The logic is in GeneratePropsCpp.js, GeneratePropsH.js and propsConversions.h.

Changelog:

[General] [Added] - Codegen generates setProp for component Props, so codegen components use the props iterator setter when enableCppPropsIteratorSetter is on
[General] [Fixed] - Codegen enum-array (mask) props no longer start from an uninitialized mask

Test Plan:

  • yarn test packages/react-native-codegen: 3,174 passed, with snapshots regenerated.
  • New GeneratedPropsSetPropTest (in components/modal/tests, which already links the generated components; happy to move it):
    • asserts that generated ModalHostViewProps, AndroidSwipeRefreshLayoutProps, ActivityIndicatorViewProps and VirtualViewProps satisfy HasIteratorSetterCtor (fails on main);
    • checks that the constructor and setProp give the same props across updates, covering a shrinking enum mask, a shrinking array, null resets and non-zero defaults;
    • compares cloneProps results with the flag off and on.
  • The 38 codegen fixtures compile the same on main and with this change, including generated code compiled against main's headers. The same 5 fail in both, for existing reasons unrelated to setProp.
  • Fantom: Modal-itest.js runs with the flag on and off, and the full suite passes. ReactCommon C++ tests: 1,633 passed.
  • C++ API snapshots regenerated with Doxygen 1.16.1; --validate passes.
  • cloneProps time, generated descriptors, flag on vs main:
Apple M-series Samsung Galaxy S10+
ActivityIndicatorViewProps, new node (11 props) 1.22 → 0.43 µs 12.2 → 5.6 µs
ActivityIndicatorViewProps, update (2 props) 0.84 → 0.13 µs 6.8 → 3.6 µs
VirtualViewProps, new node (11 props) 1.19 → 0.42 µs 11.9 → 5.5 µs
VirtualViewProps, update (2 props) 0.84 → 0.13 µs 6.9 → 3.6 µs
  • RNTester release build on the Galaxy S10+, updating 100 Switch and 100 ActivityIndicator every frame: JS render and commit time is 5% lower with the flag on. Mounting showed no change beyond noise.
  • Size: +5.8 KB of code for React Native's 15 generated components (arm64).

🤖 Generated with Claude Code

…iterator setter

`ConcreteComponentDescriptor::cloneProps` builds props through `setProp`
(`enableCppPropsIteratorSetter`) only for Props classes that declare their own
`setProp`. Props generated by codegen never did, so every component whose Props
are generated by codegen, in React Native and in libraries, kept building its
props through the constructor, which looks up every prop including all View
props, even with the flag on.

Codegen now generates a `setProp` for each Props class. It calls
`ViewProps::setProp` and sets each prop to exactly what the constructor's
`convertRawProp` gives it: the same type and default, `null` restoring the
default, values converted into a new object instead of merged into the previous
one, and conversion errors falling back to the default. To share that logic,
`convertRawProp`'s handling of a present value moves into
`convertRawPropValue`. Generated `setProp` is guarded by
`RN_HAS_CONVERT_RAW_PROP_VALUE`, so code generated by this codegen still
compiles against a React Native without it and uses the constructor there.

The generated wrapper for enum mask arrays now value-initializes its mask: its
parser ORs each value into the mask, and the constructor started from an
uninitialized one. Apart from that, props are built as before with the flag off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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

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

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.

1 participant