Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: optimistic ui for checkboxes
Sidwebworks4efd1b03440c
diff --git a/packages/onboarding/src/ui/state/hubStore.ts b/packages/onboarding/src/ui/state/hubStore.tsindex b5c0547cbe..31c111ac83 100644--- a/packages/onboarding/src/ui/state/hubStore.ts+++ b/packages/onboarding/src/ui/state/hubStore.ts@@ -8,12 +8,16 @@// the cycle repeats. `setData` is the authoritative writer of business fields —// only the provider calls it, and it always rebuilds from the server snapshot.//-// One exception, for responsiveness: `dispatch` applies an OPTIMISTIC patch to-// `checkMap` for `setCheck` toggles (checkboxes/gates) before the round-trip, so-// a tick reflects instantly instead of after the full submit→revalidate cycle.-// This is self-reconciling — the next `setData` rebuilds `checkMap` from server-// truth, so a rejected or differing write reverts on its own. No other intent is-// patched locally; everything else waits for the loader.+// One exception, for responsiveness: `dispatch` records an OPTIMISTIC override+// for `setCheck` toggles (checkboxes/gates) in `optimisticChecks` before the+// round-trip, so a tick reflects instantly instead of after the full+// submit→revalidate cycle. `checkMap` is always the server state with these+// overrides layered on top. Each override is held until the loader actually+// reports the value we wrote, then released — so it survives stale/early+// revalidations (whose snapshot doesn't yet reflect the write, and which would+// otherwise flash the toggle back) and reconciles to server truth once the write+// lands. No other intent is patched locally; everything else waits for the+// loader.//// `checkMap` / `fieldMap` are cheap derived lookups rebuilt on hydration so view// components do O(1) reads instead of each rebuilding a Map per render.@@ -36,6 +40,18 @@ import type {} from "../../types";import type { HubMutation } from "./mutations";+// Server check state with the pending optimistic overrides layered on top.+// `checkMap` is always derived through here so an in-flight toggle wins until the+// loader catches up.+function mergeChecks(+ checkStates: CheckStateRow[],+ optimistic: Map<string, string>+): Map<string, string> {+ const map = stateMap(checkStates);+ for (const [key, value] of optimistic) map.set(key, value);+ return map;+}+// The per-company server data the hub renders from (all loader-sourced).export interface HubData {tier: Tier;@@ -64,7 +80,12 @@ export type ResolveScreenUrl = (appKey: string) => string | undefined;export interface HubState extends HubData, HubFlags {checkMap: Map<string, string>;fieldMap: Map<string, string>;- // Public write path: optimistic checkMap patch (setCheck only) + round-trip.+ // Pending optimistic check overrides (itemKey -> value), layered over the+ // server checkMap. Each is held until the loader reports the value we wrote,+ // so an in-flight toggle never flashes back when a stale/early revalidation+ // lands before the write does. Internal; views read checkMap.+ optimisticChecks: Map<string, string>;+ // Public write path: optimistic check override (setCheck only) + round-trip.dispatch: (m: HubMutation) => void;// The raw server round-trip the route injects; `dispatch` wraps it.serverDispatch: (m: HubMutation) => void;@@ -110,16 +131,21 @@ export function createHubStore(initial: Partial<HubData & HubFlags> = {}) {const seed = { ...HUB_INITIAL, ...initial };return createStore<HubState>()((set, get) => ({...seed,+ optimisticChecks: new Map(),checkMap: stateMap(seed.checkStates),fieldMap: fieldMap(seed.fieldValues),- // Stable wrapper, created once. Optimistically reflects a checkbox/gate toggle- // in checkMap so the UI updates instantly, then round-trips. The next setData- // rebuilds checkMap from server truth, reconciling (or reverting) the patch.+ // Stable wrapper, created once. Records an optimistic override for a+ // checkbox/gate toggle so the UI updates instantly, then round-trips. The+ // override is layered over the server checkMap and released by setData once+ // the loader confirms the written value (see below).dispatch: (m) => {if (m.intent === "setCheck") {- const checkMap = new Map(get().checkMap);- checkMap.set(m.itemKey, m.value);- set({ checkMap });+ const optimisticChecks = new Map(get().optimisticChecks);+ optimisticChecks.set(m.itemKey, m.value);+ set({+ optimisticChecks,+ checkMap: mergeChecks(get().checkStates, optimisticChecks)+ });}get().serverDispatch(m);},@@ -127,15 +153,35 @@ export function createHubStore(initial: Partial<HubData & HubFlags> = {}) {serverDispatch: () => undefined,resolveScreenUrl: () => undefined,resolveVideoUrl: () => undefined,- setData: (data, flags, serverDispatch, resolveScreenUrl, resolveVideoUrl) =>+ setData: (+ data,+ flags,+ serverDispatch,+ resolveScreenUrl,+ resolveVideoUrl+ ) => {+ // Reconcile per key: drop an override only once the loader actually reports+ // the value we wrote (row absence = effective "todo"). This holds the+ // override through any number of stale/early revalidations whose snapshot+ // doesn't yet reflect the write — so the toggle never flickers back — and+ // releases it the moment the server confirms. (upsertCheckState always+ // writes the value, including "todo", so a confirmed write always matches.)+ const serverMap = stateMap(data.checkStates);+ const optimisticChecks = new Map(get().optimisticChecks);+ for (const [key, value] of optimisticChecks) {+ if ((serverMap.get(key) ?? "todo") === value)+ optimisticChecks.delete(key);+ }set({...data,...flags,- checkMap: stateMap(data.checkStates),+ optimisticChecks,+ checkMap: mergeChecks(data.checkStates, optimisticChecks),fieldMap: fieldMap(data.fieldValues),serverDispatch,resolveScreenUrl,resolveVideoUrl- })+ });+ }}));}diff --git a/playbooks/onboarding-checklist-toggle.md b/playbooks/onboarding-checklist-toggle.mdnew file mode 100644index 0000000000..b3bdadc358--- /dev/null+++ b/playbooks/onboarding-checklist-toggle.md@@ -0,0 +1,63 @@+# Onboarding Checklist Toggle (optimistic, no flicker)++Last tested: 2026-06-27+Route: /x/get-started/plan (Plan & Board, "Plan" tab)++## Prerequisites+- Company must be ENROLLED in the implementation hub, else /x/get-started+ redirects to /x (loader throws redirect when getImplementationHub has no row).+ Enroll via the "Enroll" button on the /x dashboard (creates the hub row).++## Steps++### 1. Login+- /login skill ([email protected]). networkidle times out on this+ app — use `agent-browser snapshot -i` directly after open instead of waiting.++### 2. Enroll (one-time)+- /x dashboard → click "Enroll". Sidebar then shows "Get Started" with sub-links+ Start Here / Scope Summary / Plan & Board / Setup Map / Training Plan / Go-Live.++### 3. Open Plan & Board+- Click "Plan & Board" link. Ensure the "Plan" tab is [pressed] (not "Board").+- Task rows render as buttons with the task label, e.g.+ "Set up sites, users, and roles", "Configure-to-order options and pricing".++### 4. Toggle a task+- Click a task button. The leading <span> checkbox flips emerald (done) /+ bg-card (todo); the label gets line-through when done.++### 5. Verify (no flicker)+- The checkbox state must change exactly ONCE per click (todo->done or+ done->todo) and hold — no done->todo->done bounce.++## Selector Notes+- Task checkbox state: the button's first child <span>; done == className+ contains "bg-emerald-500" / "emerald".+- Refs (@eN) churn between snapshots and React replaces nodes on re-render, so:+ - Re-query by text each time: `[...document.querySelectorAll("button")].find(b => b.textContent.includes("<label>"))`.+ - Click via `btn.click()` in eval to avoid stale refs.++## How to catch a flicker (transient revert)+agent-browser eval contexts are torn down after each call, killing pending+rAF/setInterval — so sample WITHIN A SINGLE eval that returns a Promise:++```+agent-browser eval '+new Promise((resolve) => {+ const find=()=>[...document.querySelectorAll("button")].find(b=>b.textContent.includes("Set up sites, users, and roles"));+ const read=()=>{const b=find(),s=b&&b.querySelector("span");return s?(s.className.includes("emerald")?"done":"todo"):"gone";};+ const log=[];let last=read();log.push({t:0,s:last});const t0=performance.now();+ const id=setInterval(()=>{const s=read();if(s!==last){log.push({t:Math.round(performance.now()-t0),s});last=s;}+ if(performance.now()-t0>2500){clearInterval(id);resolve(JSON.stringify(log));}},8);+ setTimeout(()=>{const b=find();if(b)b.click();},300);+})'+```+PASS = log has exactly 2 entries (initial + one transition). FAIL (flicker) =+3+ entries showing a revert.++## Result (2026-06-27)+- Toggle on: [{t:0,todo},{t:357,done}] -> single transition, held. PASS+- Toggle off: [{t:0,done},{t:327,todo}] -> single transition, held. PASS+- Fix: optimistic overlay in packages/onboarding/src/ui/state/hubStore.ts+ (optimisticChecks held until loader confirms the written value).