@solidnative-dev/networking

Bounded incremental HTTP(S) text transport, JSON documents, and Server-Sent Events (SSE) for Solid Native. Drives React Native's Networking TurboModule directly without evaluating fetch, XMLHttpRequest, or RCTNetworking.

Installation#

sh
pnpm add @solidnative-dev/networking

No extra native dependency is required—uses React Native's built-in Networking TurboModule.

Entrypoints#

ImportKey exports
@solidnative-dev/networkingcreateNetworkService, NetworkService, NetworkTextRequest, NetworkTextResult
@solidnative-dev/networking/react-nativecreateReactNativeNetworkService
@solidnative-dev/networking/solidcreateNetworkController
@solidnative-dev/networking/jsonrequestJSON, NetworkJSONProtocolError
@solidnative-dev/networking/solid-jsoncreateJSONResource
@solidnative-dev/networking/server-eventsopenServerEventStream
@solidnative-dev/networking/solid-server-eventscreateServerEventStream

Usage#

ts
import { createReactNativeNetworkService } from "@solidnative-dev/networking/react-native";
import { createNetworkController } from "@solidnative-dev/networking/solid";

const network = createNetworkController(createReactNativeNetworkService());
const request = network.requestText(
  {
    url: "https://api.example/assistant",
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ prompt: "Show the account summary" }),
  },
  {
    onResponse(response) {
      console.log(response.status);
    },
    onChunk(chunk) {
      appendIncrementalPayload(chunk.text);
    },
  },
);

const result = await request.result;

For a finite JSON response, the optional document layer owns buffering and validation instead of leaving each application to rebuild it:

ts
import { requestJSON } from "@solidnative-dev/networking/json";

const document = requestJSON(
  network,
  {
    url: "https://api.example/assistant/profile",
    headers: { Accept: "application/json" },
  },
  {
    onResult(result) {
      setProfile(result.value);
    },
  },
);

const { response, value } = await document.result;

For screen state, createJSONResource removes the imperative request-handle bookkeeping while retaining the bounded native transport:

ts
import { createJSONResource } from "@solidnative-dev/networking/solid-json";
import { createSignal } from "solid-js";

const [accountId, setAccountId] = createSignal("42");
const account = createJSONResource(
  network,
  () => ({
    url: `https://api.example/accounts/${accountId()}`,
    headers: { Accept: "application/json" },
  }),
  {
    decode(value) {
      if (
        value === null ||
        typeof value !== "object" ||
        Array.isArray(value) ||
        typeof value.name !== "string"
      ) {
        throw new TypeError("Account name is required.");
      }
      return { name: value.name };
    },
  },
);

// Reactive reads: account(), account.state, account.loading, account.error.

Changing accountId() cancels obsolete native work before starting its replacement. The last good value remains readable during refresh and after a failure; account.latest, account.response, and account.result expose the same state explicitly. account.refetch() retries the current request, account.cancel() restores the last stable state, a false/null/undefined source disables loading, and owner disposal cancels the final request. The optional decoder must be synchronous so validation and publication remain in the exact native completion cause.

The JSON layer independently caps native chunk count, document characters, nesting depth, and value count, accepts application/json and registered application/*+json forms, and deeply freezes the parsed value without interpreting HTTP status. Content-type checks can be disabled only through an explicit option. onResult must be synchronous and runs inside the Solid controller's native completion event, so its reactive writes retain the exact completion-to-computation-to-commit relationship. The promise is still available for ordinary asynchronous control flow, but a later promise continuation is not implicitly treated as native input.

For Server-Sent Events, the optional protocol layer preserves those same native chunk and completion causes through event parsing:

ts
import { requestServerEvents } from "@solidnative-dev/networking/server-events";

const stream = requestServerEvents(
  network,
  {
    url: "https://api.example/assistant/events",
    headers: { Accept: "text/event-stream" },
  },
  {
    onEvent(event) {
      applyServerEvent(event.type, event.data);
    },
  },
);

const { eventCount, lastEventId, retryMilliseconds } = await stream.result;

Long-lived screens can project the same connection into reactive state:

ts
import { createServerEventStream } from "@solidnative-dev/networking/solid-server-events";

const assistant = createServerEventStream(
  network,
  () => ({
    url: `https://api.example/assistant/${conversationId()}`,
    headers: { Accept: "text/event-stream" },
  }),
  {
    onEvent(event) {
      applyAssistantEvent(event.type, event.data);
    },
  },
);

// Reactive reads: assistant(), assistant.state, assistant.active,
// assistant.eventCount, assistant.lastEventId, assistant.error.

Changing the request cancels the obsolete native stream and resets its logical-stream state. assistant.restart() explicitly repeats the current request, assistant.restart(request) starts a supplied request, assistant.cancel() closes it, and owner disposal cancels it. Event publication and the optional synchronous onResponse and onEvent callbacks retain each native input's causal relationship to Solid computations and Fabric commits.

The decoder accepts arbitrary CR, LF, and CRLF chunk boundaries, comments, multiline data, event names, IDs, and bounded retry hints. It independently bounds line length, data size, data-line count, and total event count. A stream must return HTTP 200 and text/event-stream unless the caller explicitly opts out of the media-type check. Completion flushes a final event whose data was not followed by a blank line, which is useful when a server cleanly closes a finite AI response.

requestServerEvents always makes one connection. createServerEventStream also makes one connection by default. To resume an interrupted stream, opt into a bounded policy:

ts
const assistant = createServerEventStream(network, request, {
  onEvent(event) {
    applyAssistantEvent(event.type, event.data);
  },
  reconnect: {
    maxAttempts: 3, // At most three reconnects after the initial connection.
    defaultRetryMilliseconds: 3_000,
    minimumRetryMilliseconds: 250,
    maximumRetryMilliseconds: 30_000,
  },
});

The default policy retries native transport failures, timeouts, and clean EOF. Set reconnectOnCleanClose: false for a finite response that should finish at EOF. Protocol, validation, and application callback failures are terminal by default; shouldReconnect(error) can synchronously select other failures, but application callback failures are never retried. Reaching the attempt bound closes a successful connection or reports its terminal error once through onError. The attempt count does not reset when a connection succeeds.

Server retry: hints are clamped to the configured delay range. While waiting, state is "waiting", active remains true, and pendingRetryMilliseconds exposes the owned delay. Automatic reconnects carry the latest nonempty ID in Last-Event-ID, replace any case-insensitive original ID header, and retain the decoder's ID and retry state, including ID-only blocks. An empty ID removes the header. IDs are limited to 16,384 characters; each connection retains the configured transport and decoder bounds. The stream retains only the latest event, not an accumulated history.

eventCount counts events across the logical stream; connectionEventCount and event sequence are connection-local. connectionCount and reconnectCount count attempts actually started. restart() starts a fresh logical stream from the original request and configured initial decoder state, not the last automatic resume position. Its promise settles when that logical stream ends and returns the final connection's result. Cancellation, source replacement, restart, and owner disposal cancel pending timers and native work and reject the obsolete series with NetworkRequestCancelledError. Late callbacks cannot publish into a replacement stream, including when a callback itself cancels or restarts it. These framing and retry APIs do not define Solid's server-function or server-component wire protocol.

The adapter normalizes two incompatible native ABIs. Android requires a caller-generated signed 32-bit request identifier, tuple headers, and positional arguments. iOS accepts an object request and returns its native identifier via a callback, including after the application has already cancelled. React Native's iOS request counter starts at zero, so the adapter accepts non-negative safe integers rather than imposing Android's positive signed 32-bit range. Invalid callback IDs settle as a canonical non-timeout transport failure instead of creating a malformed completion. Both platforms use native incremental text delivery and native abort rather than buffering the entire response through the React Native fetch polyfill. React Native's completion event can omit its timeout element for success and ordinary transport failure. The bridgeless iOS event path can expose the false NSNumber slot as null or undefined, while other native paths can surface booleans as 0 or 1. The pinned adapter canonicalizes only those bounded two- or three-element representations to false or true; it reports malformed lengths and value kinds without including native error values, and the service contract remains strictly boolean.

Request URLs, methods, credentials, headers, body size, timeout, per-chunk size, aggregate response size, response metadata, byte progress, native errors, and event ordering are validated. The service never accumulates response text; the application decides what to retain. Immediate cancellation avoids native work, active cancellation aborts the platform request, and Solid owner disposal cancels every pending request. Response and chunk observers are synchronous by design so the native input, reactive write, and resulting commit retain one exact causal relationship; start separate owned work explicitly when a chunk needs asynchronous processing.

The Solid controller gives response metadata, every chunk, completion, and failure a separate causal platform event. This is the transport-level path for tracing a server or AI stream into the Solid computations, Fabric commits, and frames it causes. Causal telemetry records none of the URL, headers, request body, response headers, streamed text, or parsed JSON. JSON documents and SSE are separate, stable framing layers; server functions and Solid server components remain future protocol layers and are deliberately not inferred here.

React Native's application bootstrap still installs its standard fetch/XHR globals before the entrypoint. The Release source policy fingerprints that unavoidable, platform-specific setup-env baseline while requiring the Solid Native transport itself to contain only its direct registry, adapter, service, and ownership seam. Removing the broader React Native environment bootstrap is a separate backend concern, not something this package disguises.

The dedicated Release proofs can be run on attached, securely unlocked physical devices with:

sh
pnpm --filter @solidnative-dev/native-e2e android:networking:test

SOLID_NATIVE_IOS_DESTINATION=<xcode-device-id> \
SOLID_NATIVE_IOS_TEAM=<development-team-id> \
pnpm --filter @solidnative-dev/native-e2e ios:networking:test

The Android runner serves split SSE and JSON responses from a bounded local host server through an explicit adb reverse. The proof also requires exactly two resumed SSE connections, a server-observed Last-Event-ID, the requested retry delay, and retained decoder state. It forces a native transport failure, physically taps explicit and Solid-owner cancellation paths, and requires response/chunk/ completion-to-computation-to-Fabric-commit/mount/frame causality without the URL, headers, bodies, or streamed values entering telemetry. The runner rejects emulators and ambiguous devices, bounds the one transparent OkHttp retry seen for the idempotent forced-failure request, waits for JavaScript cancellation and surface-teardown acknowledgement, and verifies that the app process, disposable packages, and reverse tunnel are gone before success. Cleartext permission is limited to this checked-in local proof application; the package does not weaken an application's network-security policy.

The iOS runner uses the same bounded server and proof definition over a run-scoped 144-bit *.local launch capability. Its app rejects any non-local or malformed origin, keeps arbitrary ATS loads disabled, and declares local-network access only in the disposable proof bundle. The generic Release app, XCTest bundle, Hermes bytecode, and composed source map compile and pass the same seam policy without signing. The signed physical URLSession run remains the iOS promotion gate. On 2026-09-25 the Xcode 27 signed Release build, source-map checks, and scene-based cold launch passed on iOS 27. A .local request timed out; a retry using the Mac's explicit Wi-Fi IPv4 address revealed iOS's Local network prohibited error. The runner now reports that permission failure without copying request URLs or native payloads into its summary. Physical reconnect qualification remains open on both platforms pending iOS Local Network authorization and a connected Android rerun. On a dual-homed Mac, SOLID_NATIVE_IOS_NETWORKING_HOST can select a canonical private IPv4 address; it does not bypass the phone's permission check.