fix(ios): use findNodeHandle to register PasteInput on Fabric#55
fix(ios): use findNodeHandle to register PasteInput on Fabric#55manan19 wants to merge 1 commit into
Conversation
PasteInputIOSComponent reads `textInputRef.current?.__nativeTag` to
build the per-instance nativeID it passes to registerTextInput. That
property name is from the legacy renderer; under Fabric (RN 0.76+ with
new arch enabled) the renderer exposes the tag as `_nativeTag` (single
underscore) on the component instance.
On Fabric the lookup is undefined, the useEffect bails before calling
registerTextInput, and the native module never attaches its paste:
swizzle to the underlying UITextView. In __DEV__ this surfaces as the
"[PasteInput] Could not get native tag from ref" console warning; in
release it is a silent no-op. The Edit Menu / QuickType Paste / long-
press Paste all fall through to the default UITextView paste handler,
which does nothing for image-only clipboard contents — so to the user
it looks like onPaste never fires.
Switch to findNodeHandle from react-native, which is the public API
and works across both legacy and Fabric (it returns the renderer's
internal tag using the correct property name per arch).
Repro: RN 0.83.6 + Expo 55.0.16 + RCT_NEW_ARCH_ENABLED=1, mount a
<PasteInput onPaste={...} />, focus it, copy a PNG to the clipboard,
tap the system Paste suggestion — onPaste never fires before this
change.
Fixes mattermost#54
There was a problem hiding this comment.
Pull request overview
This PR fixes iOS paste interception registration on React Native’s New Architecture (Fabric) by switching from an internal __nativeTag lookup (legacy renderer-only) to the public findNodeHandle API so the native module can correctly register the underlying TextInput view.
Changes:
- Import
findNodeHandlefromreact-native. - Use
findNodeHandle(textInputRef.current)to derive the native tag for iOS registration (works on both legacy + Fabric). - Expand the inline comment to document the Fabric vs legacy tag behavior and link the fix to issue #54.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated ChangesFabric Compatibility Update
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
On v2.0.0 / v2.0.1, the iOS paste interception silently fails to register on RN ≥ 0.76 with the New Architecture enabled.
onPastenever fires; the Edit Menu / QuickType "Paste" / long-press Paste all fall through to the defaultUITextViewpaste handler, which does nothing for image-only clipboard contents — so to the user it looks like the library does nothing.Filed as #54 with full repro details.
Root cause
PasteInputIOSComponentreads the RN tag via the__nativeTagproperty (double underscore):That property name is from the legacy renderer. Under Fabric (RN 0.76+ with
RCT_NEW_ARCH_ENABLED=1), the renderer exposes the tag as_nativeTag(single underscore) on the Fabric instance — see e.g.react-native@0.83.6Libraries/Renderer/implementations/ReactNativeRenderer-prod.js~line 1372:So
textInputRef.current?.__nativeTagisundefined, theuseEffectbails before callingNativePasteInputModule.registerTextInput, and the native module never attaches itspaste:swizzle.Fix
Use
findNodeHandlefromreact-native. It's the public API and resolves to the correct internal tag on both legacy and Fabric renderers.Repro
RCT_NEW_ARCH_ENABLED=1<PasteInput onPaste={...} />focusedpublic.png)onPasteevent before this change; works as expected after.In
__DEV__, the dev-only warning[PasteInput] Could not get native tag from reffires once at mount before the fix and is silent after.Notes
findNodeHandlestill resolves to the same numeric tag.src/PasteInput.tsx.tsc --noEmitpasses.PasteInputAndroidComponentpath is unaffected (it uses the customPasteTextInputComponentView and doesn't read the tag from JS).Fixes #54