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 type | Native build required? | What to watch out for |
|---|---|---|
| Pure JS / Solid libraries (state, queries, schemas, headless auth clients) | No | Avoid 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 package | Call 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 |
Recommended 3-layer package layout#
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:
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:
{
"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:
- Generate typed, React-free bindings from the library's Codegen spec:
sn generate --platform all --solid-library <react-native-library>- Scaffold an owner-safe adapter around the generated TurboModule:
sn adapter create <ModuleName> \
--library <react-native-library> \
--output adapters/<ModuleName>.ts- For native Fabric views (including Nitro
PreviewViewcomponents), declare a typed descriptor and expose a thin Solid component rather than importing the upstream library's React JSX wrapper. See@solidnative-dev/camerafor 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) withonCleanup(...). - 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
readypromise 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-storageas the client's storage adapter (Keychain on iOS, Keystore on Android). - HTTP & streaming: Use
@solidnative-dev/networkingfor bounded JSON requests and Server-Sent Events. - First-class Solid clients: Libraries like
better-auth/solidor@supabase/supabase-jswork 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:
- Unit-test the portable contract (
.) and Solid owner disposal (./solid) with@solidnative-dev/testing. - In an example app, run
sn compatibility checkto confirm your native spec and autolinking declarations match. - Run
sn bundle sourceson a production bundle to verify neitherreactnor an upstream library's React JS barrel leaked into the bundle.