[]previous and next page

SuspenseTracker

Counter protocol between asynchronous sources and the nearest <Suspense> boundary.

Counter protocol between asynchronous sources and the nearest <Suspense> boundary. A source calls increment() when it starts blocking its readers and decrement() exactly once when it settles.

Import#

ts
import type { SuspenseTracker } from "@shadow-js/core";

Signature#

ts
interface SuspenseTracker {
  /**
   * Records one more pending source. The boundary shows its fallback while the count is above
   * zero; call it once per source, the first time a reader sees that source pending.
   */
  increment(): void;
  /**
   * Records that one pending source settled (with a value or an error). Call it exactly once per
   * `increment()`; when the count returns to zero the boundary shows its content again.
   */
  decrement(): void;
  /**
   * Called when a transition reads pending data in this boundary. Returns true when the boundary keeps
   * its content meanwhile: the reader then throws the suspension and keeps its previous value until
   * the boundary releases it. Returns false (or is absent) to show the fallback as usual.
   * @default undefined (the boundary never holds its content: the fallback shows as usual)
   */
  hold?(): boolean;
}

Members#

Name Type Description
increment increment(): void Records one more pending source. The boundary shows its fallback while the count is above zero; call it once per source, the first time a reader sees that source pending.
decrement decrement(): void Records that one pending source settled (with a value or an error). Call it exactly once per increment(); when the count returns to zero the boundary shows its content again.
hold? hold?(): boolean Called when a transition reads pending data in this boundary. Returns true when the boundary keeps its content meanwhile: the reader then throws the suspension and keeps its previous value until the boundary releases it. Returns false (or is absent) to show the fallback as usual.