[]previous and next page

Claims

The claiming half of hydration, as a hook.

The claiming half of hydration, as a hook. hydrate() installs the real implementation for the length of its pass; outside a pass the hooks are idle: nothing is claimed, and the renderer builds the same DOM it builds on a fresh page. Templates, regions, Dynamic, Portal and NoHydration call through claims, so only code that reaches hydrate() carries the claiming code (the registry, the server-block lifting and the portal scan). A custom renderer reads the same hook.

Import#

ts
import type { Claims } from "@shadow-js/web/extend";

Signature#

ts
interface Claims {
  /** Claims the server element for `key` (see `claimElement`). */
  claimElement(key: string | undefined): Element | null;
  /** Adopts the next server region of `parent` (see `takeRegion`). */
  takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined;
  /** The content of every region lifted out of a claimed element (see `liftedRegions`). */
  liftedRegions(): readonly (readonly Node[])[] | undefined;
  /** Adopts the server block of a portal (see `claimPortal`). */
  claimPortal(key: string | undefined): Node[] | undefined;
  /** True while a hydration pass claims server DOM (see `isClaiming`). */
  isClaiming(): boolean;
  /** Runs `fn` with claiming off (see `withoutClaiming`). */
  withoutClaiming<T>(fn: () => T): T;
}

Members#

Name Type Description
claimElement claimElement(key: string | undefined): Element | null Claims the server element for key (see claimElement).
takeRegion takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined Adopts the next server region of parent (see takeRegion).
liftedRegions liftedRegions(): readonly (readonly Node[])[] | undefined The content of every region lifted out of a claimed element (see liftedRegions).
claimPortal claimPortal(key: string | undefined): Node[] | undefined Adopts the server block of a portal (see claimPortal).
isClaiming isClaiming(): boolean True while a hydration pass claims server DOM (see isClaiming).
withoutClaiming withoutClaiming<T>(fn: () => T): T Runs fn with claiming off (see withoutClaiming).