Skip to content

feat(host): export subscribeConnectionStatus - #295

Open
Imod7 wants to merge 2 commits into
mainfrom
domi-host-conn-status
Open

feat(host): export subscribeConnectionStatus#295
Imod7 wants to merge 2 commits into
mainfrom
domi-host-conn-status

Conversation

@Imod7

@Imod7 Imod7 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds a function to @parity/product-sdk-host that reports whether the app's channel to the host
container is up. You pass a callback, it runs immediately with the current status and again on every
change, and it returns a function to stop listening. The status is "connecting", "connected" or
"disconnected".

The signal already existed in @parity/truapi, reachable only by importing that lower level package
directly. This publishes it from the SDK.

import { subscribeConnectionStatus } from "@parity/product-sdk-host";

const unsubscribe = subscribeConnectionStatus((status) => setStatus(status));

Changes

packages/host/src/transport.ts adds subscribeConnectionStatus, the HostConnectionStatus type,
and emitConnectionStatus for tests. It also holds "disconnected" when the underlying signal
reports "connecting" after the channel has closed, and notifies subscribers when setTruApiClient
injects or clears a client.

packages/host/src/index.ts exports the function and the type.

packages/host/src/testing.ts re-exports emitConnectionStatus and adds it to FakeHost, so a
product can test its offline and reconnecting states. Breaking for anyone who writes their own object
of type FakeHost, because the member is required.

pending-changesets/host-subscribe-connection-status.md is the changeset, minor for
@parity/product-sdk-host and @parity/product-sdk.

Why these changes

coin-flip needs this to finish its migration and currently runs its own hook over
@novasamatech/host-api-wrapper. Landing it first means coin-flip never takes a direct dependency on
@parity/truapi, and the signature matches its existing hook, so the change there is one import.

The raw signal is wrong after a disconnect, so this corrects it rather than passing it through.
@parity/truapi 0.7.0 never clears its cached client when the pipe closes, so the next subscriber
reads "connecting" from a dead client and every existing subscriber receives that value with no way
back. A route change after the host went away showed a spinner that never ended instead of an offline
state. An upstream fix should follow, and this correction can be removed then.

Testing

Before: 92 tests pass in the host package, 5 of them in transport.ts.
After: 102 pass, 15 in transport.ts.

Run from product-sdk/:

pnpm check
pnpm --filter "@parity/product-sdk-host" test
pnpm --filter "@parity/product-sdk-host" build
pnpm --filter "@parity/product-sdk" build
pnpm typecheck

@github-actions

Copy link
Copy Markdown

📦 Bundle size impact

Comparing 2026-08-11T18:03:36.279Z2026-08-11T18:03:14.728Z

Package Entry Bundled before Bundled after Δ Ship gzip Δ Shake ratio
🟢 @parity/product-sdk ./host 84.4 KB 84.9 KB +473 B (+0.5%) 0 B 2% (was 2%)
🟢 @parity/product-sdk ./testing 58.2 KB 58.7 KB +433 B (+0.7%) 0 B 26% (was 26%)
🟢 @parity/product-sdk-host . 84.4 KB 84.9 KB +473 B (+0.5%) +5 B 2% (was 2%)
🟢 @parity/product-sdk-host ./testing 9.7 KB 10.1 KB +427 B (+4.3%) +17 B 67% (was 69%)
🟢 @parity/product-sdk-statement-store . 95.9 KB 96.4 KB +476 B (+0.5%) 0 B 10% (was 10%)

Thresholds — warn: ≥10% or ≥5.0 KB · fail: ≥20% or ≥15.0 KB (bundled). Percentage only applies once the baseline is ≥ 10 KB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant