Skip to content

fix: replace RCTUISecureTextField #include hack with proper subclass#2895

Merged
Saadnajmi merged 1 commit intomicrosoft:mainfrom
Saadnajmi:fix-secure-textfield-include-hack
Apr 8, 2026
Merged

fix: replace RCTUISecureTextField #include hack with proper subclass#2895
Saadnajmi merged 1 commit intomicrosoft:mainfrom
Saadnajmi:fix-secure-textfield-include-hack

Conversation

@Saadnajmi
Copy link
Copy Markdown
Collaborator

Summary

  • 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 #included 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

@Saadnajmi Saadnajmi requested a review from a team as a code owner April 8, 2026 04:53
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 8, 2026

⚠️ No Changeset found

Latest commit: ef05e8e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Saadnajmi Saadnajmi changed the title fix: replace RCTUISecureTextField #include hack with proper OOP subclass fix: replace RCTUISecureTextField #include hack with proper subclass Apr 8, 2026
@Saadnajmi Saadnajmi force-pushed the fix-secure-textfield-include-hack branch from 5a10bd2 to 11a3d5d Compare April 8, 2026 05:42
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>
@Saadnajmi Saadnajmi force-pushed the fix-secure-textfield-include-hack branch from 11a3d5d to ef05e8e Compare April 8, 2026 17:11
@Saadnajmi Saadnajmi merged commit 26c68ad into microsoft:main Apr 8, 2026
17 of 18 checks passed
@Saadnajmi Saadnajmi deleted the fix-secure-textfield-include-hack branch April 8, 2026 18:15
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants