Authoring Packages

Anyone can build and publish packages for Solid Native under their own npm scope—whether that is a pure Solid utility, a zero-React adapter around an existing React Native native library, or a custom Swift/Kotlin/C++ TurboModule or Nitro Module.

Three kinds of Solid Native packages#

Package typeNative build required?What to watch out for
Pure JS / Solid libraries (state, queries, schemas, headless auth clients)NoAvoid importing react or browser-only DOM APIs (window, document)
Adapters for existing RN / Nitro libraries (Keychain, VisionCamera, Maps, Biometrics)Consumer installs + autolinks the upstream native packageCall the native TurboModule, Fabric descriptor, or Nitro HybridObject directly—do not import the upstream package's React JS barrel
Custom native packages (new TurboModules, Fabric components, or Nitro Modules)Yes (autolinked via React Native autolinking & Codegen)Publish standard React Native Codegen specs (Native*.ts / *NativeComponent.ts) alongside your Solid TypeScript entrypoint

Solid Native's own platform packages (such as @solidnative-dev/secure-storage, @solidnative-dev/dialogs, and @solidnative-dev/camera) split into three small subpath exports:

text
my-solid-native-pkg/
├── package.json
└── src/
    ├── index.ts         # Framework-neutral contract & runtime validation (no RN/Solid imports)
    ├── react-native.ts  # Narrow native TurboModule / Fabric / Nitro adapter
    └── solid.ts         # Owner-scoped Solid controller (onCleanup disposal, reactive accessors)

In package.json:

json
{
  "name": "solid-native-example",
  "version": "0.1.0",
  "type": "module",
  "sideEffects": false,
  "exports": {
    ".": "./dist/index.js",
    "./react-native": "./dist/react-native.js",
    "./solid": "./dist/solid.js"
  },
  "peerDependencies": {
    "solid-js": "^2.0.0"
  }
}

Separating the contract, native adapter, and Solid controller makes your validation and ownership logic testable in plain Node with zero simulator overhead, while keeping React Native ABI changes isolated to one small file.

Wrapping an existing React Native TurboModule or Fabric view#

You do not need to fork a React Native library to use its native iOS and Android code from Solid Native:

  1. Generate typed, React-free bindings from the library's Codegen spec:
sh
   sn generate --platform all --solid-library <react-native-library>
  1. Scaffold an owner-safe adapter around the generated TurboModule:
sh
   sn adapter create <ModuleName> \
     --library <react-native-library> \
     --output adapters/<ModuleName>.ts
  1. For native Fabric views (including Nitro PreviewView components), declare a typed descriptor and expose a thin Solid component rather than importing the upstream library's React JSX wrapper. See @solidnative-dev/camera for a complete Nitro + Fabric example.

Solid 2 ownership rules for native packages#

Mobile native callbacks outlive screens if you do not tie them to Solid's owner tree. Follow four rules when writing ./solid controllers:

  • Require or bind to the current owner: Register native teardown (subscription.remove(), request abort, hardware release) with onCleanup(...).
  • Reject or ignore late settlements after disposal: Native promises that cannot be cancelled at the OS layer must reject with a clear *OwnerDisposedError (or drop callbacks) once the owner is disposed so retired state is never mutated.
  • Avoid writing signals synchronously during construction: Start async initial queries after component construction and expose a ready promise or status accessor so you do not write inside a Solid 2 owned computation.
  • Keep sensitive payloads out of logs and telemetry: Pass only semantic event names and bounded metadata into causal observability—never tokens, clipboard text, URLs, or dialog strings.

Composing auth & backend SDKs#

Auth and backend clients do not need to live inside Solid Native core. Libraries that already provide framework-agnostic or Solid clients compose directly with Solid Native's platform primitives:

  • Token & cookie persistence: Wire @solidnative-dev/secure-storage as the client's storage adapter (Keychain on iOS, Keystore on Android).
  • HTTP & streaming: Use @solidnative-dev/networking for bounded JSON requests and Server-Sent Events.
  • First-class Solid clients: Libraries like better-auth/solid or @supabase/supabase-js work directly once wired to native secure storage and deep-link redirects.

Testing and verifying zero React leaks#

Before publishing, verify both behavior and bundle cleanliness:

  1. Unit-test the portable contract (.) and Solid owner disposal (./solid) with @solidnative-dev/testing.
  2. In an example app, run sn compatibility check to confirm your native spec and autolinking declarations match.
  3. Run sn bundle sources on a production bundle to verify neither react nor an upstream library's React JS barrel leaked into the bundle.