A navigator.onLine signal.
| Stage | Category | Version | Last Updated | Demo |
|---|---|---|---|---|
| 3 | Network | 1.0.0-next.2 (next) | Aug 12, 2026 | Demo → |
npm i @solid-primitives/connectivity@nextReactive primitives for network connectivity and connection quality. Wraps navigator.onLine for basic online/offline detection and the Network Information API (navigator.connection) for adaptive loading strategies.
- Docs (Storybook)
makeConnectivityListener— low-level callback when online status changescreateConnectivitySignal— signal fornavigator.onLineuseConnectivitySignal— singleton variant ofcreateConnectivitySignalmakeNetworkInformation— low-level callback for all network state changescreateNetworkInformation— signals for online status + connection quality metricsuseNetworkInformation— singleton variant ofcreateNetworkInformation
makeConnectivityListener
Attaches event listeners and fires callback whenever window.onLine changes.
import { makeConnectivityListener } from "@solid-primitives/connectivity";
const clear = makeConnectivityListener(isOnline => { console.log(isOnline); // T: boolean});// remove event listeners (happens also on cleanup)clear();Definition
function makeConnectivityListener(callback: (isOnline: boolean) => void): VoidFunction;createConnectivitySignal
A signal representing the browser's interpretation of whether it is on- or offline.
import { createConnectivitySignal } from "@solid-primitives/connectivity";
const isOnline = createConnectivitySignal();isOnline(); // T: booleanDefinition
function createConnectivitySignal(): Accessor<boolean>;useConnectivitySignal
This primitive provides a singleton root variant that will reuse event listeners and signals across dependents.
import { useConnectivitySignal } from "@solid-primitives/connectivity";
const isOnline = useConnectivitySignal();isOnline(); // T: booleanmakeNetworkInformation
Low-level primitive that fires a callback with a full NetworkState snapshot whenever online status or connection quality changes. Listens to both window online/offline events and navigator.connection change events.
import { makeNetworkInformation } from "@solid-primitives/connectivity";
const clear = makeNetworkInformation(state => { console.log(state.online, state.effectiveType, state.downlink);});clear();Definition
function makeNetworkInformation(callback: (state: NetworkState) => void): VoidFunction;createNetworkInformation
Returns independent reactive signals for online status and all Network Information API properties. Useful for adaptive loading strategies — adjusting image quality, prefetch behavior, or feature availability based on actual connection conditions.
Network Information API properties (downlink, effectiveType, etc.) are undefined in browsers that don't support the API (Firefox, Safari). Always guard on the value before branching on it.
import { createNetworkInformation } from "@solid-primitives/connectivity";
const { online, effectiveType, downlink, rtt, saveData, type } = createNetworkInformation();
// adapt asset quality to connectionconst imageQuality = () => { if (!online() || saveData()) return "low"; if (effectiveType() === "4g") return "high"; return "medium";};// show a warning banner when on a slow connection<Show when={effectiveType() === "2g" || effectiveType() === "slow-2g"}> <Banner>Slow connection detected — some features may be limited.</Banner></Show>Definition
function createNetworkInformation(): NetworkInformationReturn;
type NetworkInformationReturn = { online: Accessor<boolean>; downlink: Accessor<number | undefined>; // bandwidth estimate in Mbit/s downlinkMax: Accessor<number | undefined>; // max downlink speed (non-standard) effectiveType: Accessor<EffectiveConnectionType | undefined>; // "slow-2g" | "2g" | "3g" | "4g" rtt: Accessor<number | undefined>; // estimated round-trip time in ms saveData: Accessor<boolean | undefined>; // user has requested reduced data usage type: Accessor<ConnectionType | undefined>; // underlying connection technology};
type EffectiveConnectionType = "slow-2g" | "2g" | "3g" | "4g";type ConnectionType = | "bluetooth" | "cellular" | "ethernet" | "none" | "wifi" | "wimax" | "other" | "unknown";useNetworkInformation
Singleton root variant of createNetworkInformation. Shares a single set of event listeners across all callers in the same application.
import { useNetworkInformation } from "@solid-primitives/connectivity";
const { online, effectiveType } = useNetworkInformation();NetworkState
Plain data snapshot type returned by makeNetworkInformation callbacks.
type NetworkState = { online: boolean; downlink: number | undefined; downlinkMax: number | undefined; effectiveType: EffectiveConnectionType | undefined; rtt: number | undefined; saveData: boolean | undefined; type: ConnectionType | undefined;};Browser Support
| Primitive | Chrome | Firefox | Safari |
|---|---|---|---|
makeConnectivityListener / createConnectivitySignal | ✅ | ✅ | ✅ |
Network Information API fields (effectiveType, downlink, etc.) | ✅ | ❌ | ❌ |
The Network Information API fields return undefined where unsupported — no errors are thrown.
Changelog
See CHANGELOG.md