Skip to content

fix(ios): use findNodeHandle to register PasteInput on Fabric#55

Open
manan19 wants to merge 1 commit into
mattermost:masterfrom
manan19:fix/find-node-handle-fabric
Open

fix(ios): use findNodeHandle to register PasteInput on Fabric#55
manan19 wants to merge 1 commit into
mattermost:masterfrom
manan19:fix/find-node-handle-fabric

Conversation

@manan19
Copy link
Copy Markdown

@manan19 manan19 commented May 11, 2026

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. onPaste never fires; 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 the library does nothing.

Filed as #54 with full repro details.

Root cause

PasteInputIOSComponent reads the RN tag via the __nativeTag property (double underscore):

const nativeTag = textInputRef.current?.__nativeTag;

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.6 Libraries/Renderer/implementations/ReactNativeRenderer-prod.js ~line 1372:

var tag = inst._nativeTag;

So textInputRef.current?.__nativeTag is undefined, the useEffect bails before calling NativePasteInputModule.registerTextInput, and the native module never attaches its paste: swizzle.

Fix

Use findNodeHandle from react-native. It's the public API and resolves to the correct internal tag on both legacy and Fabric renderers.

import { findNodeHandle } from 'react-native';
// ...
const nativeTag = textInputRef.current
    ? findNodeHandle(textInputRef.current)
    : null;

Repro

  • RN 0.83.6 + Expo 55.0.16, RCT_NEW_ARCH_ENABLED=1
  • <PasteInput onPaste={...} /> focused
  • Copy a PNG to the clipboard (host macOS → iOS Simulator works; pasteboard carries public.png)
  • Tap system Paste affordance → no onPaste event before this change; works as expected after.

In __DEV__, the dev-only warning [PasteInput] Could not get native tag from ref fires once at mount before the fix and is silent after.

Notes

  • Behavior on the legacy renderer is unchanged: findNodeHandle still resolves to the same numeric tag.
  • Only touches src/PasteInput.tsx. tsc --noEmit passes.
  • The Android PasteInputAndroidComponent path is unaffected (it uses the custom PasteTextInput ComponentView and doesn't read the tag from JS).

Fixes #54

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
Copilot AI review requested due to automatic review settings May 11, 2026 21:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 findNodeHandle from react-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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35bacecc-5985-48ab-8c32-2ad74d46ab3f

📥 Commits

Reviewing files that changed from the base of the PR and between 671378e and 8fdcd0a.

📒 Files selected for processing (1)
  • src/PasteInput.tsx

📝 Walkthrough

Walkthrough

Updated src/PasteInput.tsx to use the public findNodeHandle API instead of the internal __nativeTag property when obtaining the native tag for iOS TextInput registration. This resolves silent failure of paste interception on React Native 0.76+ with Fabric enabled.

Changes

Fabric Compatibility Update

Layer / File(s) Summary
Import Resolution
src/PasteInput.tsx
Added findNodeHandle import from react-native alongside existing platform and module imports.
Native Tag Extraction
src/PasteInput.tsx
iOS paste-interception registration now calls findNodeHandle(textInputRef.current) to obtain the native tag instead of reading the internal __nativeTag property, enabling compatibility with both legacy and Fabric renderers.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: replacing __nativeTag with findNodeHandle for iOS Fabric compatibility.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the problem, root cause, fix, and reproduction steps.
Linked Issues check ✅ Passed The PR fully addresses issue #54 by replacing __nativeTag with findNodeHandle to restore paste interception on iOS Fabric renderer.
Out of Scope Changes check ✅ Passed All changes are scoped to src/PasteInput.tsx and directly address the linked issue; no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

v2 paste interception silently bails on RN 0.76+ Fabric (uses __nativeTag which is undefined)

2 participants