Skip to content

Nitro Modules v1: research breaking changes and React Native support #1100

Done

Description

@boorad

Part of the Nitro Modules v1 + RN-free RNQC milestone (context: #1099).

Find out what moving RNQC from Nitro Modules 0.35 to Nitro Modules v1 (margelo/nitro branch v1, currently 1.0.0-alpha.nightly.*) breaks: nitro.json keys, spec syntax, how hybrid objects are created (constructors replace createHybridObject), C++ headers and base classes, Promise/callback/ArrayBuffer types, generated output layout, autolinking, SwiftPM vs CocoaPods, and how React Native is supported.

Done when: there is a written list of breaking changes, each marked mechanical or needs design, and the decisions below are settled.

Decisions to settle: package names, the core/React Native boundary, whether #1099 seeds the core package or is closed, whether RNQC's React Native integration moves to Nitro Modules v1 or stays on Nitro Modules 0.x until v1 is stable, and how next is released.

Activity

  1. added this to the Nitro v1 + core split milestone on Nov 28, 2026
  2. added
    enhancement
    on Nov 28, 2026
  3. boorad commented on Nov 28, 2026

    @boorad
    CollaboratorAuthor

    Nitro Modules v1 research findings

    Versions used below: Nitro Modules (react-native-nitro-modules, nitro-core, nitrogen) is currently 0.35 in RNQC, and the new major is Nitro Modules v1. RNQC (react-native-quick-crypto) is currently 1.1.10, and moving it to Nitro Modules v1 would make RNQC 2.0. React Native (RN) versions are given as RN 0.81, RN 0.88.

    Source: margelo/nitro branch v1 at 43e09c1, the same build as the Nitro Modules npm 1.0.0-alpha.nightly.138.

    Requirements and compatibility

    • Nitro Modules v1 needs RN 0.88 or newer, New Architecture only (peer dependency react-native >=0.88.0). RNQC's example app is on RN 0.81.1.
    • Apple: iOS 16+, Swift 6.4 and Swift Package Manager only. CocoaPods projects are told to run npx react-native spm add --deintegrate; feat: support CocoaPods alongside SwiftPM nitro#2054, which adds CocoaPods back, is open and was last updated Nov 9.
    • No interop between Nitro Modules 0.x and v1 in either direction. createHybridObject is gone and registration now goes through getHybridClass and HybridClassRegistry. An app has to be on Nitro Modules v1 to use an RNQC built on it, so that RNQC release is a semver major (RNQC 2.0).
    • Stability: Nitro Modules v1 is published only as alpha-nightly, with no changelog or timeline.

    Nitro Modules 0.35 → v1 breaking changes for RNQC

    Area Change Effort
    nitro.json ios.iosModuleName becomes apple.moduleName; android.androidNamespace and android.androidCxxLibName become namespace and cxxLibName; environment is new; the autolinking block is now an error. Mechanical
    Specs (28) interface X extends HybridObject<…> becomes @Apple/@Android decorators on export declare class X extends HybridObject, plus export * from '#nitro/X' and a package.json imports map. Overloads, rest parameters and generics are unsupported. Mechanical
    Object creation (65 call sites) createHybridObject is replaced by constructors and statics. Upstream AGENTS.md says stateless APIs should be statics. Needs design
    C++ base class HybridObject(TAG) becomes HybridObject() (37 sites); registration moves to HybridClass. Mechanical
    Raw JSI methods The three loadHybridMethods() overrides (HybridUtils.hpp, HybridRsaCipher.hpp, HybridKeyObjectHandle.hpp) have to be re-expressed through registerRawHybridMethod on a HybridClass. Small design
    Types ArrayBuffer becomes a value type (const ArrayBuffer& in, ArrayBuffer out), about 440 sites. Promise<T> is returned by value, about 50 sites. Callbacks become Callback<void(T)>. optional, variant and hybrid references are unchanged. Mechanical, large
    Generated layout Headers are module-prefixed (<QuickCrypto/HybridXSpec.hpp>), generated JS is shared/javascript/*.cjs, and ios/ becomes apple/. Mechanical
    Apple build Moves to Package.swift with addNitrogenTargets; the podspec becomes metadata only. The OpenSSL download moves to a .binaryTarget, as in #1099. libsodium's ./configure build has no Swift package equivalent, so it needs a prebuilt xcframework or has to go. Rewrite
    Android build registerAllNatives() and <Lib>OnLoad.initializeNative() replace initialize(vm). CMakeLists.txt stays ours, so the opensslstatic prefab and --exclude-libs carry over. Mechanical

    Because the ArrayBuffer and Promise types differ, the C++ can't be shared between an RNQC build on Nitro Modules 0.x and one on Nitro Modules v1 without a compatibility layer.

    Do we need two packages?

    Nitro Modules v1 does not require it. The "Inside a nitro module library" section of the Nitro Modules v1 react-native-nitro-modules README says a library should declare nitro-core and react-native-nitro-modules as optional peer dependencies, so one package can serve both a React Native app and a non-React Native host.

    Resolved by test (results): generate once with "environment": "bare" and add a thin React Native layer. The two environments' nitrogen output differs only in the generated JS and the Android CMake; the Apple output is identical. The same package ran in an RN 0.88 app on iOS and Android and in a bare Hermes host on iOS. #1101 is now "make the single package work without React Native" rather than a split.

    Only src/utils/conversion.ts imports react-native today.

    Decisions

    Final outcomes: see the decisions comment. The table below is the original proposal.

    # Decision Recommendation
    1 Move RNQC's React Native integration to Nitro Modules v1, or keep it on Nitro Modules 0.x Everything moves to Nitro Modules v1 on next (RNQC 2.0); main stays on Nitro Modules 0.x (RNQC 1.x), with crypto fixes backported by hand until the merge.
    2 One package or a split Settled by test: one package (results). Split only for a product reason Nitro Modules doesn't impose, such as a different release cadence.
    3 Name RNQC 2.0 is a major, so this is the cheapest moment to rename. Bare quick-crypto and nitro-crypto are taken on npm; @margelo/quick-crypto is free, once Margelo control of the @margelo npm scope is confirmed. If we rename, keep react-native-quick-crypto publishing as a deprecated re-export for one or two majors. If apps without React Native aren't a real goal, keep the current name.
    4 Internal API Statics for stateless modules (Random, Utils, Pbkdf2, …) and constructors for stateful ones (new Hash(algo)). The public crypto.* and subtle.* API doesn't change.
    5 libsodium on Apple A prebuilt xcframework release asset, like OpenSSL, or audit what still uses libsodium and drop it.
    6 #1099 Close it once RNQC 2.0 (on Nitro Modules v1) lands. Reuse its separate Android shared library with hidden symbols and its Swift package OpenSSL binary target in #1103, with credit.
    7 Release Publish 2.0.0-next.N under the npm next tag, pinned to an exact Nitro Modules v1 nightly. Merge to main once Nitro Modules v1 is stable and either CocoaPods support lands or we decide to require Swift packages.

    Not verified

    • Whether a bare-generated .cjs runs unchanged under React Native. It does, provided react-native-nitro-modules is imported first (results).
    • Whether Swift package cxxSources can point outside the package root in an npm install. No longer needed with one package.

    Example app upgrade to RN 0.88: #1106

  4. changed the title [-]Nitro v1: research breaking changes and RN support[/-] [+]Nitro Modules v1: research breaking changes and React Native support[/+] on Nov 28, 2026
  5. boorad commented on Nov 28, 2026

    @boorad
    CollaboratorAuthor

    @hannojg decision 2 & 3 above 🙏

  6. boorad commented on Nov 28, 2026

    @boorad
    CollaboratorAuthor

    Test result: one package can serve both hosts

    Yes, with changes. A package generated with "environment": "bare" in nitro.json, plus a thin React Native layer, runs in both an RN 0.88 app and a bare Hermes host with no React Native. A separate core package isn't needed for Nitro Modules v1's sake. Whether to have one anyway is a product decision.

    Setup: Nitro Modules v1 at margelo/nitro@43e09c1 (npm 1.0.0-alpha.nightly.138), with the #1099 quick-crypto-nitro package as the test subject. Check: createHash('sha256').update('abc').digest('hex'), expected ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad.

    Host iOS (iPhone 18 Pro sim, iOS 27.2) Android (Pixel 8 Pro AVD, arm64)
    RN 0.88 (Nitro Modules v1 example app) ✅ correct digest, with the changes below ✅ correct digest, with the changes below
    Bare Hermes (Nitro Modules v1 standalone test runner) ✅ quick-crypto.test.ts passed; 26/26 Swift tests not run (the #1099 author reports it works)

    Why bare and not react-native

    Nitrogen's output differs between the two environments in only two files: shared/javascript/Hash.cjs (it imports nitro-core or react-native-nitro-modules) and android/QuickCryptoNitro+autolinking.cmake. The Apple output is identical. The react-native output does not work in the bare host: the bundle pulls in react-native/index.js, and the CMake needs ReactAndroid. So we generate once as bare and add a React Native layer.

    What the React Native layer needs

    1. JS entry point: exports["."]["react-native"] points to an RN entry that imports react-native-nitro-modules first, then re-exports the shared entry. Without that order you get Nitro Modules must be installed before importing nitro-core. Both nitro-core and react-native-nitro-modules become optional peer dependencies.
    2. Android library: android/ becomes a real RN library: manifest, namespace, a cpp-adapter.cpp that calls registerAllNatives() from JNI_OnLoad, and a Kotlin package class. A dependencies-only build.gradle breaks react-native config for the whole app.
    3. Android CMake shim: a small nitro-core-config.cmake defines nitro-core::NitroModules on top of react-native-nitro-modules::NitroModules, ReactAndroid::jsi, ReactAndroid::reactnative and the Folly defines, and CMakeLists.txt sets nitro-core_DIR to it. CMAKE_PREFIX_PATH doesn't work, because the Android toolchain re-roots it.
    4. iOS autolinking: a stub *.podspec, react-native.config.js and swiftpmConfig in package.json. Drop "type": "module", which made react-native.config.js unreadable.
    5. Package.swift:
      • Compile the generated QuickCryptoNitroAutolinking.mm. Without it you get HybridClass "quickcrypto.Hash" is not registered.
      • Pick the Nitro Modules package at build time: ../NitroModules under RN, ../nitro-core for bare. Add the DEBUG/NDEBUG defines.

    Not tested

    • Bare Android.
    • The bare branch of the new Package.swift. In the test, bare iOS was built through the Nitro repo's root Package.swift.
    • Whether compiling the autolinking .mm and also calling registerHybridClasses() by hand in a bare host registers twice.
    • Release builds, Android ABIs other than arm64-v8a, and Expo.

    Effect on the plan

  7. boorad commented on Nov 28, 2026

    @boorad
    CollaboratorAuthor

    Decisions (final)

    Decided by @boorad as maintainer.

    # Decision Outcome Tracked in
    1 Nitro Modules v1 timing Everything moves to Nitro Modules v1 on next as RNQC 2.0. main stays on Nitro Modules 0.x (RNQC 1.x), and crypto fixes are backported to next by hand until the merge. #1105
    2 One package or a split One package: generated as bare, plus a thin React Native layer (test results). #1101
    3 Name No rename. The package stays react-native-quick-crypto. —
    4 Internal API Statics for stateless modules and constructors for stateful ones, replacing createHybridObject. The public crypto.* and subtle.* API doesn't change. #1102
    5 libsodium on Apple Audit what still uses libsodium. If it's still needed, ship a prebuilt xcframework release asset with a pinned checksum, like OpenSSL; otherwise drop it. #1103
    6 #1099 Close it now. Its separate Android shared library with hidden symbols, its Swift package OpenSSL binary target and its shared HashContext.hpp are reused in #1101 and #1103. #1101, #1103
    7 Release 2.0.0-next.N under the npm next tag, pinned to an exact Nitro Modules v1 nightly. Merge to main once Nitro Modules v1 is stable and either CocoaPods support lands (margelo/nitro#2054) or we decide to require Swift packages. #1105

    The research and the decisions are complete, so this issue is closing. Follow-up work is in the milestone; #1106 (example app on RN 0.88) is next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions