fix: replace RCTUISecureTextField #include hack with proper subclass#2895
Merged
Saadnajmi merged 1 commit intomicrosoft:mainfrom Apr 8, 2026
Merged
Conversation
|
4 tasks
5a10bd2 to
11a3d5d
Compare
tido64
approved these changes
Apr 8, 2026
packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm
Outdated
Show resolved
Hide resolved
packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm
Outdated
Show resolved
Hide resolved
The old RCTUISecureTextField.m used `#include "../RCTUITextField.mm"` to re-compile the entire implementation with RCT_SUBCLASS_SECURETEXTFIELD defined. This caused duplicate symbol errors in SPM builds because both files were compiled as separate translation units. Replace with a proper OOP subclass: RCTUISecureTextField now inherits from RCTUITextField and overrides only what differs (NSSecureTextFieldCell). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
11a3d5d to
ef05e8e
Compare
tido64
approved these changes
Apr 8, 2026
Saadnajmi
added a commit
that referenced
this pull request
Apr 8, 2026
… subclass (#2894) ## Summary Backport of #2895 to `0.81-stable`. - Replaces the fragile preprocessor `#include .mm` trick in `RCTUISecureTextField` with proper OOP inheritance - `RCTUISecureTextField` now subclasses `RCTUITextField` directly and overrides `+cellClass` to return `RCTUISecureTextFieldCell : NSSecureTextFieldCell` - Removes all `RCT_SUBCLASS_SECURETEXTFIELD` preprocessor conditionals from `RCTUITextField.h/.mm` - Updates `isKindOfClass:[NSSecureTextField class]` checks to `[RCTUISecureTextField class]` in both Paper and Fabric code paths ## Motivation The old approach `#include`d the entire 734-line `RCTUITextField.mm` with a `#define` to swap class/superclass names — a preprocessor trick to work around a diamond inheritance problem. This caused duplicate-symbol linker errors on non-macOS SPM builds and was fragile and confusing. Since `NSSecureTextField`'s masking behavior lives entirely in `NSSecureTextFieldCell`, the proper fix is to subclass `RCTUITextField` and override just the cell class (~50 lines of duplicated cell code vs. 734 lines recompiled via include). ## Test plan - [ ] macOS build succeeds (RCTUISecureTextField inherits all behavior from RCTUITextField) - [ ] Secure text fields still mask input on macOS (masking comes from NSSecureTextFieldCell) - [ ] iOS/visionOS SPM builds pass without duplicate symbols or excludes - [ ] No regressions in text input behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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
#include .mmtrick inRCTUISecureTextFieldwith proper OOP inheritanceRCTUISecureTextFieldnow subclassesRCTUITextFielddirectly and overrides+cellClassto returnRCTUISecureTextFieldCell : NSSecureTextFieldCellRCT_SUBCLASS_SECURETEXTFIELDpreprocessor conditionals fromRCTUITextField.h/.mmisKindOfClass:[NSSecureTextField class]checks to[RCTUISecureTextField class]in both Paper and Fabric code pathsMotivation
The old approach
#included the entire 734-lineRCTUITextField.mmwith a#defineto swap class/superclass names — a preprocessor trick to work around a diamond inheritance problem. This caused duplicate-symbol linker errors on non-macOS SPM builds and was fragile and confusing.Since
NSSecureTextField's masking behavior lives entirely inNSSecureTextFieldCell, the proper fix is to subclassRCTUITextFieldand override just the cell class (~50 lines of duplicated cell code vs. 734 lines recompiled via include).Test plan
🤖 Generated with Claude Code