Repository navigation
Generate setProp for codegen Props so codegen components can use the iterator setter - #60492
Open
hryhoriiK97 wants to merge 1 commit into
Open
hryhoriiK97 wants to merge 1 commit into
hryhoriiK97 wants to merge 1 commit into
Conversation
…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>
This branch has not been deployed
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:
With
enableCppPropsIteratorSetteron,clonePropsbuilds props by copying the previous props and callingsetPropfor each changed prop, instead of running the constructor that looks up every prop (#57328). It only does this for Props classes that declare their ownsetProp. Codegen-generated Props never do, soActivityIndicator,Switch,Modal,RefreshControl,VirtualViewand library components with codegen Props get nothing from the flag.This change:
setPropfor each codegen Props class. Each prop gets exactly what the constructor'sconvertRawPropgives it: same type and default,nullrestores the default, and conversion errors fall back to the default.convertRawProp's handling of a present value intoconvertRawPropValueso both paths share it.setPropwith#ifdef RN_HAS_CONVERT_RAW_PROP_VALUE, so code generated by this codegen still compiles against an older React Native.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.jsandpropsConversions.h.Changelog:
[General] [Added] - Codegen generates
setPropfor component Props, so codegen components use the props iterator setter whenenableCppPropsIteratorSetteris 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.GeneratedPropsSetPropTest(incomponents/modal/tests, which already links the generated components; happy to move it):ModalHostViewProps,AndroidSwipeRefreshLayoutProps,ActivityIndicatorViewPropsandVirtualViewPropssatisfyHasIteratorSetterCtor(fails onmain);setPropgive the same props across updates, covering a shrinking enum mask, a shrinking array,nullresets and non-zero defaults;clonePropsresults with the flag off and on.mainand with this change, including generated code compiled againstmain's headers. The same 5 fail in both, for existing reasons unrelated tosetProp.Modal-itest.jsruns with the flag on and off, and the full suite passes. ReactCommon C++ tests: 1,633 passed.--validatepasses.clonePropstime, generated descriptors, flag on vsmain:ActivityIndicatorViewProps, new node (11 props)ActivityIndicatorViewProps, update (2 props)VirtualViewProps, new node (11 props)VirtualViewProps, update (2 props)Switchand 100ActivityIndicatorevery frame: JS render and commit time is 5% lower with the flag on. Mounting showed no change beyond noise.🤖 Generated with Claude Code