/// import { NAME, pattern, UI, Writable } from "commontools"; /** * Reproduction case for ct-select not displaying initial values from backend. * * Bug: When a ct-select is bound to a cell via $value, the dropdown would show * the placeholder "-" instead of the actual cell value on initial page load. * The value was present in the cell, but the component's onChange callback * wasn't being called when the subscription received backend updates. * * Root cause: CellController._setupCellSubscription() only called * host.requestUpdate() when cell values changed, but didn't call the onChange * callback. Components like ct-select rely on onChange to sync their DOM state. * * Fix: In cell-controller.ts, the subscription callback now calls onChange * when the cell value changes from the backend. * * To test: * 1. Deploy this pattern with `piece new` * 2. Use CLI to set values: echo '"video"' | ct piece set --piece ID type ... * 3. Refresh the page - the dropdown should show "🎬 Video", not "-" * 4. The "Current value" text should also display "video" */ interface Output { [NAME]: string; type: string; status: string; } export default pattern, Output>(() => { const type = Writable.of("article"); const status = Writable.of("want"); return { [NAME]: "Select Initial Value Repro", [UI]: ( Type Select

Current value: {type}

Status Select

Current value: {status}

If either dropdown shows "-" instead of its value on page load, the bug is present. Both dropdowns should show their selected values immediately.

), type, status, }; });