Skip to content

VariantRegistry

Defined in: variant.ts:115

new VariantRegistry(): VariantRegistry

VariantRegistry

get viewId(): string | null

Defined in: variant.ts:140

The explicit page view the registry is scoped to, or null for the implicit view (the one reset() starts).

string | null

enterView(viewId): boolean

Defined in: variant.ts:152

Scope the registry to page view viewId. A different id than the current one starts a new page view: pins, reservations and slot memories of the old view are dropped (as reset() does) before anything is pinned for the new one. The same id again changes nothing, so calling it on every render is safe. Returns true when it started a new view.

string

boolean


fallbackShown(key): boolean

Defined in: variant.ts:191

Has this slot’s fallback already been shown in this page view?

string

boolean


get(key): string | undefined

Defined in: variant.ts:200

The variant to request for this pin key — the campaign id, or the surface id for surface-only islands — if one is already pinned. Undefined means “let the server choose” — which it should, exactly once.

string

string | undefined


markFallbackShown(key): void

Defined in: variant.ts:186

Record that a slot’s fallback has been shown in this page view (the hold ran out, or a server reservation revealed it). It is final for the rest of the page view: a later mount of the same slot — a re-render, a suspended boundary resolving — shows it again instead of holding, and no later stream replaces it. key is the renderer’s slot identity.

string

void


onNewView(listener): () => void

Defined in: variant.ts:129

Run listener whenever a page view ends and a new one begins (a client navigation, enterView with a different view, or reset after use). Not for the page’s first view: state a server render left for it stays. Returns the unsubscribe.

() => void

() => void


pin(key, variantId): string

Defined in: variant.ts:213

Record a resolved variant. First writer wins.

Later calls are ignored rather than overwriting, because a second resolution arriving at all means one island raced ahead of the pin — and in that case the right repair is to keep the value already reported on the impression, not to adopt the newer one and disagree with our own analytics.

string

string

string


reserve(key, timeoutMs?): VariantReservation

Defined in: variant.ts:230

Claim, or wait for, this page view’s variant for a pin key (campaign id, or surface id for surface-only islands).

The first caller (per key, per page view) gets a LEADER reservation and must eventually call resolve or abort on it. Everyone else gets a FOLLOWER whose promise resolves with the leader’s variant, capped at timeoutMs. A key that is already pinned returns a follower whose promise is already resolved — awaiting it costs one microtask.

string

number = RESERVATION_TIMEOUT_MS

VariantReservation


reset(): void

Defined in: variant.ts:281

New page view. Call on client-side navigation, or scope the registry to explicit views with enterView (the provider does this for you when it is given a serverContext or a viewKey).

void


slot(key): SlotMemory

Defined in: variant.ts:163

The memory of one copy slot in this page view, created empty on first use. key is the renderer’s slot identity. Cleared with the view.

string

SlotMemory