Rxova
Skip to content

StorageTransport

Cross-tab delivery over the storage event, for browsers with no BroadcastChannel.

The mechanism is a quirk turned to advantage: writing to localStorage fires a storage event in every other same-origin tab and never in the writer — exactly BroadcastChannel’s no-self-echo semantics, for free.

Two differences from the real thing, both deliberate and both documented:

  1. Fidelity is JSON, not structured clone. localStorage holds strings. The default serializer therefore rejects every value JSON would quietly change — a Date, a Map, a function — rather than let a write appear to succeed while peers receive something else. Pass a Serializer (devalue, superjson) to carry those instead.
  2. The entry is removed immediately after writing. Peers have already been notified by then (the event carries the value), and leaving application state sitting in localStorage would be both a quota cost and a privacy one. The removal fires a second event with a null newValue, which receivers ignore.
new StorageTransport(
name,
storage?,
serializer?): StorageTransport;
ParameterTypeDefault value
namestringundefined
storageStorageglobalThis.localStorage
serializerSerializerjsonSerializer

StorageTransport

readonly kind: TransportKind = 'storage';

What this transport is. Optional so a custom transport need not declare one.

Transport.kind

close(): void;

void

Transport.close


post(data): void;
ParameterType
dataunknown

void

Transport.post


subscribe(listener): () => void;
ParameterType
listener(data) => void

() => void

Transport.subscribe