Skip to content

fix(textinput): restore macOS Fabric trait conversion - #3173

Open
Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-textinput-traits
Open

Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-textinput-traits

Conversation

@JasonVMo

Copy link
Copy Markdown

Summary:

Restore macOS-only Fabric TextInput trait conversion:

  • Parse submitKeyEvents and clearTextOnSubmit. feat(fabric): Pick the rest of TextInput changes #2727 (90ce6058f5) added the traits, event converter, and consumer but omitted these assignments. Both props therefore remained at their defaults, including on current main after fix(macos): Fabric accessibility roles and state, and TextInput read-only and Tab-stop fixes #3136.
  • Replace pastedTypes' unconditional abort with an exception handled by the existing convertRawProp diagnostic/default boundary. Validate string types before casting, including array entries. Valid scalar and array forms remain supported; malformed input falls back to the declared empty-list default.
  • Add four regression tests in the existing React-RCTFabric/Tests suite covering modifier combinations, inheritance/replacement/removal, valid paste forms, and invalid string/non-string input.

The paste abort introduced by #2715 copied an older upstream conversion pattern. Upstream subsequently removed the adjacent TextInput aborts in react#50764; the macOS-specific converter was left behind. Paper already handles unknown paste type names without aborting. No overlapping fix was found in the PR/issue searches.

These are fork-only props, so an upstream change or JS wrapper would not repair the missing native conversion. All production changes are under TARGET_OS_OSX; iOS, Android, and Paper are unchanged.

The existing multiline consumer uses unmodified Enter for an empty/omitted key list and exact modifier matching for custom entries. This PR does not change event ordering, key handling, or single-line/secure inputs, which use the separate submitBehavior path.

Test Plan:

Parser regressions: red/green

Compiled the real changed TextInputProps.cpp and the new XCTest source against existing, read-only macOS Pods archives using Xcode 26.4.1. Baseline runs use the pristine conversion headers from 0b569f1497.

Commands from the repository root:

xcrun xctest -XCTest RCTTextInputPropsTests/testSubmitKeyModifiersAndClearText ../../../.copilot/session-state/33ea5c72-8bbd-448d-aa21-c9b99dd03c96/files/textinput-baseline.xctest

Expected baseline failure: exit 1, one test with two failed assertions: clearTextOnSubmit is false and submitKeyEvents.size() is 0.

xcrun xctest -XCTest RCTTextInputPropsTests/testInvalidPastedTypesUseDefault ../../../.copilot/session-state/33ea5c72-8bbd-448d-aa21-c9b99dd03c96/files/textinput-baseline.xctest

Expected baseline crash: exit 134/SIGABRT for an unknown JS paste type string.

xcrun xctest ../../../.copilot/session-state/33ea5c72-8bbd-448d-aa21-c9b99dd03c96/files/textinput-fixed.xctest

Passed: exit 0, four tests, zero failures. Invalid strings and numeric values log Error while converting prop 'pastedTypes' and select the default instead of terminating.

Exact direct XCTest compile/link command

The bundle is a local validation artifact, not new repository tooling. The test source is discovered by the existing React-RCTFabric test-spec glob.

artifacts=../../../.copilot/session-state/33ea5c72-8bbd-448d-aa21-c9b99dd03c96/files
native=../../react-native-macos/packages/rn-tester
component=packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput
headers=(
  -I packages/react-native/ReactCommon
  -I packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios
  -I packages/react-native/ReactCommon/react/renderer/components/view/platform/macos
  -I packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx
  -I packages/react-native/ReactCommon/react/renderer/graphics/platform/ios
  -I packages/react-native/ReactCommon/react/renderer/imagemanager/platform/ios
  -I packages/react-native/ReactCommon/jsi
  -I packages/react-native/ReactCommon/yoga
  -I "$native/Pods/boost"
  -I "$native/Pods/DoubleConversion"
  -I "$native/Pods/fast_float/include"
  -I "$native/Pods/fmt/include"
)
for dir in "$native"/Pods/Headers/Public/*; do headers+=(-I "$dir"); done
defines=(
  -DDEBUG=1
  -DFOLLY_NO_CONFIG
  -DFOLLY_MOBILE=1
  -DFOLLY_USE_LIBCPP=1
  -DFOLLY_CFG_NO_COROUTINES=1
  -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG
)
frameworks="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/Library/Frameworks"
libraries=("$native"/build/Products/Debug/*/*.a)
sources=(
  packages/react-native/React/Tests/Text/RCTTextInputPropsTests.mm
  "$component/TextInputProps.cpp"
  packages/react-native/ReactCommon/jsi/jsi/jsi.cpp
)
bundle="$artifacts/textinput-fixed.xctest"
mkdir -p "$bundle/Contents/MacOS"
xcrun clang++ -isysroot "$(xcrun --sdk macosx --show-sdk-path)" \
  -std=c++20 -bundle -fobjc-arc "${defines[@]}" \
  -F "$frameworks" -framework XCTest -framework Foundation -framework AppKit \
  -framework Security -framework QuartzCore -framework CoreText -framework ImageIO \
  -framework JavaScriptCore -framework SystemConfiguration -licucore \
  -Wl,-rpath,"$frameworks" "${headers[@]}" "${sources[@]}" "${libraries[@]}" \
  -o "$bundle/Contents/MacOS/TextInputPropsTests"

Passed: exit 0. No existing Pods/build output was modified.

iOS guard compilation

Exact iOS simulator translation-unit check
headers=(-I packages/react-native/ReactCommon -I packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios -I packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx -I packages/react-native/ReactCommon/react/renderer/graphics/platform/ios -I packages/react-native/ReactCommon/react/renderer/imagemanager/platform/ios -I packages/react-native/ReactCommon/jsi -I packages/react-native/ReactCommon/yoga -I ../../react-native-macos/packages/rn-tester/Pods/boost -I ../../react-native-macos/packages/rn-tester/Pods/DoubleConversion -I ../../react-native-macos/packages/rn-tester/Pods/fast_float/include -I ../../react-native-macos/packages/rn-tester/Pods/fmt/include)
for dir in ../../react-native-macos/packages/rn-tester/Pods/Headers/Public/*; do headers+=(-I "$dir"); done
xcrun --sdk iphonesimulator clang++ -isysroot "$(xcrun --sdk iphonesimulator --show-sdk-path)" -target arm64-apple-ios15.1-simulator -std=c++20 -fsyntax-only -UTARGET_OS_OSX -DTARGET_OS_OSX=0 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_CFG_NO_COROUTINES=1 "${headers[@]}" packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputProps.cpp

Passed: exit 0, no diagnostics.

Formatting

xcrun clang-format --dry-run --Werror --lines=14:17 --lines=220:222 --lines=236:236 packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/conversions.h
xcrun clang-format --dry-run --Werror --lines=17:23 --lines=87:98 packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/propsConversions.h
xcrun clang-format --dry-run --Werror packages/react-native/React/Tests/Text/RCTTextInputPropsTests.mm
git diff --check

All passed. The initial whole-header format check failed on formatting already present in both pristine headers; only changed lines were checked to avoid reformatting upstream code.

Tooling setup: yarn install --immutable passed with existing warnings after yarn exec clang-format --version reported missing install state. The npm formatter binary subsequently failed to execute on this host (spawn Unknown system error -86); the installed xcrun clang-format 21.0.0 was used instead.

Not run: full RNTester-macOS/iOS builds, Paper/Android builds, interactive UI/IME/secure-input testing, full native suite, Jest/Flow/JS lint (no JS changes). No screenshots: this is a parser-only fix; the existing RNTester “Clear text on submit - Multiline Textfield” example is the manual UI follow-up.

Parse submit key events and clear-on-submit traits, and route invalid paste types through the existing recoverable prop conversion boundary. Add native parser regressions for modifiers, prop updates and paste input validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96
@JasonVMo

Copy link
Copy Markdown
Author

Additional validation: the six independent main fixes (#3170–#3175) were combined at e9667492e9 in an isolated worktree. After regenerating Pods from packages/rn-tester, RNTester-macOS and RNTester for arm64/x86_64 iOS simulators both built successfully. Exact commands, corrected codegen invocation, and limitations are recorded in #3175 (integration validation comment). This is build evidence, not live UI or sanitizer qualification; no PR was merged.

Comment on lines +8 to +15
// [macOS]

#import <TargetConditionals.h>

#if TARGET_OS_OSX
#import <XCTest/XCTest.h>

#include <react/renderer/components/iostextinput/TextInputProps.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path I think is more for paper tests, but also we really don't need to be adding tests I think. I don't really see native tests like these much in React Native much less its' forks. I'm not sure what any of theses tests would catch vs hwo brittle they are to upstream refactors.

Comment on lines +14 to +16
#if TARGET_OS_OSX // [macOS
#include <stdexcept>
#endif // macOS]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no other more standard way to throw errors in RN's C++ code?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants