reactwg / react-native-releases

React Native Releases Working Group
338 stars 6 forks source link

CodeGen behaving strangely on upgraded project #294

Open jaaywags opened 1 month ago

jaaywags commented 1 month ago

Old Version

0.71.10

New Version

0.74.1

Description

Hello,

I Just followed the steps over at the React Native Upgrade Helper for my specific verson..

It went pretty smoothly. I am encounter an error though. I am sure it is just some xcode setting or something.

I have the @react-native-clipboard/clipboard (version ^1.14.1) installed. And after the upgrade, when I ran the app, I was getting this error.

 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
 WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
Screenshot of yellow logbox from simulator

I did a few things to diagnose this further. First, I stood up a brand new RN CLI project with the same exact package.json, and I do not get this error. From this point on, I will refer to the existing upgraded project that gets the warning as the old project, and the new one I stood up that doesn't have the error as the new project.

The error is coming from this file, ./node_modules/@react-native-clipboard/clipboard/dist/NativeClipboardModule.js.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeAllListeners = exports.addListener = void 0;
var react_native_1 = require("react-native");
var ClipboardTurboModule = react_native_1.TurboModuleRegistry.getEnforcing('RNCClipboard');
exports.default = ClipboardTurboModule;
var EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
var eventEmitter = new react_native_1.NativeEventEmitter(ClipboardTurboModule);
var listenerCount = eventEmitter.listenerCount;
// listenerCount is only available from RN 0.64
// Older versions only have `listeners`
if (!listenerCount) {
    listenerCount = function (eventType) {
        // @ts-ignore
        return eventEmitter.listeners(eventType).length;
    };
}
else {
    listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
}
var addListener = function (callback) {
    if (listenerCount(EVENT_NAME) === 0) {
        ClipboardTurboModule.setListener();
    }
    var res = eventEmitter.addListener(EVENT_NAME, callback);
    // Path the remove call to also remove the native listener
    // if we no longer have listeners
    // @ts-ignore
    res._remove = res.remove;
    res.remove = function () {
        // @ts-ignore
        this._remove();
        if (listenerCount(EVENT_NAME) === 0) {
            ClipboardTurboModule.removeListener();
        }
    };
    return res;
};
exports.addListener = addListener;
var removeAllListeners = function () {
    eventEmitter.removeAllListeners(EVENT_NAME);
    ClipboardTurboModule.removeListener();
};
exports.removeAllListeners = removeAllListeners;

I added a console.log(ClipboardTurboModule) under line 5 and found on the new project, I get this

{"addListener": [Function nonPromiseMethodWrapper], "getConstants": [Function anonymous], "getImage": [Function promiseMethodWrapper], "getImageJPG": [Function promiseMethodWrapper], "getImagePNG": [Function promiseMethodWrapper], "getString": [Function promiseMethodWrapper], "getStrings": [Function promiseMethodWrapper], "hasImage": [Function promiseMethodWrapper], "hasNumber": [Function promiseMethodWrapper], "hasString": [Function promiseMethodWrapper], "hasURL": [Function promiseMethodWrapper], "hasWebURL": [Function promiseMethodWrapper], "removeListener": [Function nonPromiseMethodWrapper], "removeListeners": [Function nonPromiseMethodWrapper], "setImage": [Function promiseMethodWrapper], "setListener": [Function nonPromiseMethodWrapper], "setString": [Function nonPromiseMethodWrapper], "setStrings": [Function nonPromiseMethodWrapper]}

And the old one I get this.

{"getConstants": [Function anonymous], "getString": [Function promiseMethodWrapper], "hasString": [Function promiseMethodWrapper], "hasURL": [Function promiseMethodWrapper], "setString": [Function nonPromiseMethodWrapper]}

You can immediately see that the old project is missing addListener and removeListeners which are now required for NativeEventEmitter. So my next goal was to find where this ClipboardTurboModule object comes from and I think I found it. I believe it is from here, ./ios/Pods/Headers/Private/React-Codegen/rnclipboard/rnclipboard.h. The new project, this file exists but in the old one it doesn't. In fact, many of the codegen files here don't exist.

Folder structure of both old and new projects

IDK how to turn this on. The Podfile's for both are pretty much identical (differing for only some firebase stuff). I went through a ton of the build settings and build phases and they seem to be the same. Removing node modules, build, and pods folders and pnpm-lock.yaml and Podfile.lock files and re-running/installing/building everything doesn't help.

Also, this seems to be an iOS issue only.

Any ideas? TIA

Steps to reproduce

I cannot reproduce this on a new project.

Affected Platforms

Runtime - iOS

Output of npx react-native info

warn Package rn-fetch-blob contains invalid configuration: "dependency.hooks" is not allowed. Please verify it's properly linked using "npx react-native config" command and contact the package maintainers about this.
info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (14) arm64 Apple M3 Max
  Memory: 200.31 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.13.1
    path: ~/.volta/tools/image/node/20.13.1/bin/node
  Yarn: Not Found
  npm:
    version: 10.5.2
    path: ~/.volta/tools/image/node/20.13.1/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10227.8.2321.11479570
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.74.1
    wanted: ^0.74.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

Posted everything in the main description

Reproducer

https://github.com

Screenshots and Videos

No response

cipolleschi commented 1 month ago

Hi @jaaywags, sorry for the (very) late reply. Have you tried to update the react-native-clipboard to the new version?