Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to replace NativeModules.SourceCode under Fabric architecture? #44418

Closed
sailor1861 opened this issue May 6, 2024 · 4 comments
Closed

How to replace NativeModules.SourceCode under Fabric architecture? #44418

sailor1861 opened this issue May 6, 2024 · 4 comments
Labels
Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@sailor1861
Copy link

Description

Hello,

I'm currently transitioning to the new React Native Fabric architecture and I'm looking for a way to replace the functionality provided by NativeModules.SourceCode. In the legacy architecture, we used NativeModules.SourceCode to obtain information about the running JS bundle, such as its URL.

Could you please provide guidance or point me towards the recommended approach for accessing this kind of information within the context of the Fabric architecture? Is there a new API or an alternative method that we should use now?

Thank you for your assistance.

Best regards,

Steps to reproduce

console.log("NativeModules.SourceCode:" + NativeModules.SourceCode + "; scriptURL" + NativeModules.SourceCode.scriptURL);

React Native Version

0.72.5

Affected Platforms

Runtime - Android

Areas

TurboModule - The New Native Module System

Output of npx react-native info

nfo Fetching system and libraries information...
System:
  OS: macOS 12.5
  CPU: (8) arm64 Apple M1 Pro
  Memory: 106.81 MB / 16.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 16.20.1
    path: ~/node/node-16.20.1/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.8.0
    path: ~/node/node-16.20.1/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 21.4
      - iOS 15.5
      - macOS 12.3
      - tvOS 15.4
      - watchOS 8.5
  Android SDK:

Stacktrace or Logs

ERROR  TypeError: null is not an object (evaluating '_reactNative.NativeModules.SourceCode.scriptURL')

Reproducer

https://git.corp.com/GP_APPMAIN_RN/react-native-auto.git

Screenshots and Videos

No response

@sailor1861 sailor1861 added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels May 6, 2024
Copy link

github-actions bot commented May 6, 2024

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.72.14. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels May 6, 2024
Copy link

github-actions bot commented May 6, 2024

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@tarunrajput
Copy link
Contributor

try using TurboModuleRegistry.getEnforcing('SourceCode').getConstants().scriptURL or SourceCode.getConstants().scriptURL

@sailor1861
Copy link
Author

TurboModuleRegistry.getEnforcing('SourceCode').getConstants().scriptUR is OK;thanks @arunrajput

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels May 7, 2024
@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

3 participants