mattermost / mattermost/react-native-paste-input

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

Offen Anfängerfreundlich
#54 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Objective-C
Sterne
213
Forks
38
Ø Merge
12 Std. 25 Min.
Gemergte PRs (30 T.)
1

Beschreibung

Summary

On v2.0.0 / v2.0.1, the iOS paste interception silently fails to register on RN 0.76+ with the New Architecture (Fabric) enabled. The Edit Menu / QuickType "Paste" / long-press → Paste actions fall through to the default UITextView paste handler, which does nothing for image-only clipboard contents — making it look like nothing happens on paste.

Root cause

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

// src/PasteInput.tsx
const nativeTag = textInputRef.current?.__nativeTag;

if (!nativeTag) {
  if (__DEV__) {
    console.warn('[PasteInput] Could not get native tag from ref');
  }
  return;
}

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 component instance — see e.g. react-native@0.83.6 Libraries/Renderer/implementations/ReactNativeRenderer-prod.js line ~1372:

var tag = inst._nativeTag;

So on Fabric textInputRef.current?.__nativeTag is undefined, the useEffect bails before calling NativePasteInputModule.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 builds it's a silent no-op.

Repro

  • RN ≥ 0.76 with new arch on (RCT_NEW_ARCH_ENABLED=1)
  • v2.0.0 or v2.0.1 installed
  • Mount a <PasteInput onPaste={...} /> and focus it
  • Copy an image to the clipboard (host macOS → iOS Simulator works; public.png on the pasteboard)
  • Tap the system Paste affordance — no onPaste event fires; no JS callback; in DEV the warning prints once at mount

Confirmed on RN 0.83.6 + Expo 55.0.16 + new arch enabled.

Suggested fix

Use findNodeHandle from react-native, which is the public API and works across both legacy and Fabric (returns the underlying _nativeTag on Fabric):

import { findNodeHandle } from 'react-native';

const nativeTag = textInputRef.current
    ? findNodeHandle(textInputRef.current)
    : null;

findNodeHandle is a thin wrapper around the same renderer-internal tag lookup, just with the correct property name per renderer.

Happy to send a PR.

Workaround

For anyone hitting this before a fix lands, a patch-package / pnpm patch diff against lib/commonjs/PasteInput.js and lib/module/PasteInput.js swapping textInputRef.current?.__nativeTag for findNodeHandle(textInputRef.current) (with the import added in lib/module/PasteInput.js) restores paste interception.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in src/PasteInput.tsx bei etwa Zeile 83 und verfolge den useEffect-Pfad, der das native Tag ermittelt und NativePasteInputModule.registerTextInput aufruft. Reproduziere das Problem unter RN 0.76+ mit aktiviertem Fabric und einem Zwischenablageinhalt, der nur aus einem Bild besteht; abgeschlossen ist die Aufgabe, wenn die Paste-Abfanglogik registriert wird und onPaste ohne die Entwicklungswarnung ausgelöst wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
ios, react-native, typescript
Bereich
mobile
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
76/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.