AGENT SKILL

lit-persist

Gate Lit element UI on Persist hydration with HydrationController. Use when wiring HydrationSignal into a ReactiveControllerHost; not a hook.

License 许可
MIT
最近更新
2026-11-01
Stars
★ 5
Forks
0

01 前言 Front Matter

name
lit-persist
license
MIT
sources
[ "stainless-code/persist:src/adapters/frameworks/lit.ts" ]
metadata
{ "type": "framework", "library": "@stainless-code/persist", "framework": "lit", "library_version": "0.4.1" }
requires
[ "persist" ]
description
Gate Lit element UI on Persist hydration with HydrationController. Use when wiring HydrationSignal into a ReactiveControllerHost; not a hook.

03 SKILL.md 正文

Lit hydration gate

@stainless-code/persist/frameworks/lit exports HydrationController — a ReactiveController, not a hook. Constructor calls host.addController(this); subscribes on hostConnected, tears down on hostDisconnected.

Install

bun add @stainless-code/persist lit

Peer: lit >=3.0.0.

Minimal wiring

import { LitElement, html } from "lit";
import { HydrationController } from "@stainless-code/persist/frameworks/lit";

class PrefsEl extends LitElement {
  #hydration = new HydrationController(this, prefsHydration);

  render() {
    return this.#hydration.hydrated
      ? html`<prefs-panel></prefs-panel>`
      : html`<skeleton-el></skeleton-el>`;
  }
}

Common mistakes

  • Inventing useHydrated for Lit. Use the controller.
  • Caching hydrated outside render — the controller already requestUpdates on connect/change; read the getter in render().
  • Null signal ≠ loading → hydrated true, no subscribe.

API surface

  • new HydrationController(host, signal) — getter hydrated: boolean

04 同仓库更多 Skills