From ff094d248f00342824219ccd6534ad9bb5575103 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 05:30:47 +0000 Subject: [PATCH] fix(studio): Save waits for the CEL verdict's renders before it reads the hold The top bar's Save read the buffers' held state a fixed 50 ms past the lint debounce, but an action predicate's verdict climbs to the Data pillar's Save entry through four effect-driven renders. On a busy main thread the Save read the pre-edit verdict and sent the unparsable text (DataPillar.panelHold-27629, 4 of 7 runs red under a CPU stressor). Save now also awaits a transition-priority render of its own, which React commits only after every default-priority render, the verdict's last hop included. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbXCSJnUMMhWxyBmuqA --- .../36619-studio-save-waits-verdicts.md | 10 ++++ .../src/views/studio-design/studioSaveBar.tsx | 55 ++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .changeset/36619-studio-save-waits-verdicts.md diff --git a/.changeset/36619-studio-save-waits-verdicts.md b/.changeset/36619-studio-save-waits-verdicts.md new file mode 100644 index 00000000000..463c887eb25 --- /dev/null +++ b/.changeset/36619-studio-save-waits-verdicts.md @@ -0,0 +1,10 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(studio): Save waits for an expression's check to reach the page before it sends, so a predicate that does not parse is held, not saved, on a busy machine too + +Clause-②: no +Metadata-protocol: none + +Studio's top-bar Save reads whether an edit is held (a formula, rule guard or action predicate that does not parse) once the expression checks of the last keystroke have run. It waited a fixed 50 ms past the check's delay, but an action predicate's verdict reaches the object's Save through several renders (the expression field, the condition builder, the action inspector, the actions panel, then the Data pillar), and on a busy main thread those renders came after the 50 ms: Save read the verdict from before the edit and sent the unparsable predicate. Save now also waits until every render already queued has run, so it reads the verdict of the text it is about to send. A Save pressed after the check has reported is not slower; one pressed while renders are pending waits for them. diff --git a/ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx b/ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx index 8628df7a46b..1410e07368a 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx +++ b/ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx @@ -20,8 +20,17 @@ * - A buffer that holds an edit it cannot send yet (`held`) refuses the whole * Save before anything is written, naming what it needs. The held state is * read once the expression checks of the last keystroke have run (they run - * {@link LINT_DEBOUNCE_MS} after it): a Save pressed at once never sends a - * formula its check has not judged yet (objectui#4306). + * {@link LINT_DEBOUNCE_MS} after it) AND their verdicts have reached the + * buffers: a Save pressed at once never sends a formula its check has not + * judged yet (objectui#4306). + * - A verdict climbs to its buffer through effects, one render per hop (an + * action predicate's: the CEL field, the condition builder, the action + * inspector, the actions panel, then the Data pillar's `held`). Those + * renders run at default priority, so Save waits for a render of its own + * at transition priority ({@link useRendersSettled}): React commits it only + * once no default-priority render is left, the last hop included. A fixed + * margin past the debounce lost that race on a busy main thread and sent + * the unparsable text (objectstack#36619). * - Cancel drops every dirty buffer's edits: each goes back to what the * server holds. */ @@ -116,12 +125,50 @@ export interface StudioSaveCoordinator { cancel: () => void; } +/** + * objectstack#36619 — an answer that resolves once React has no render more + * urgent than a transition left: the caller's component renders at transition + * priority, and React reaches that render only after every default-priority + * one, including those scheduled by the effects of the renders before it. So + * an effect chain already under way (a CEL verdict climbing to the buffer that + * holds it) has run to its end when the answer resolves. Unmounted first, it + * resolves at once: nothing is left to wait for. + */ +function useRendersSettled(): () => Promise { + const [tick, setTick] = React.useState(0); + const seq = React.useRef(0); + const waiters = React.useRef void }>>([]); + React.useEffect(() => { + const due = waiters.current.filter((w) => w.tick <= tick); + if (due.length === 0) return; + waiters.current = waiters.current.filter((w) => w.tick > tick); + for (const w of due) w.resolve(); + }, [tick]); + React.useEffect( + () => () => { + for (const w of waiters.current) w.resolve(); + waiters.current = []; + }, + [], + ); + return React.useCallback( + () => + new Promise((resolve) => { + const next = ++seq.current; + waiters.current.push({ tick: next, resolve }); + React.startTransition(() => setTick(next)); + }), + [], + ); +} + /** The surface's side: the registered buffers, and the Save and Cancel over them. */ export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator { const entriesRef = React.useRef(new Map>()); const [dirty, setDirty] = React.useState(false); const [saving, setSaving] = React.useState(false); const savingRef = React.useRef(false); + const rendersSettled = useRendersSettled(); const readDirty = React.useCallback(() => { for (const ref of entriesRef.current.values()) if (ref.current?.dirty) return true; return false; @@ -152,6 +199,8 @@ export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator savingRef.current = true; setSaving(true); await new Promise((settled) => setTimeout(settled, VERDICT_SETTLE_MS)); + // The checks have run; their verdicts may still be climbing to the buffers. + await rendersSettled(); const entries = dirtyEntries(); const held = entries.find((e) => e.held !== null); if (held || entries.length === 0) { @@ -189,7 +238,7 @@ export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator } else if (saved.length > 0) { toast.success(tFormat('engine.studio.save.done', locale, { items: names(saved) }), { id: STUDIO_SAVE_TOAST_ID }); } - }, [dirtyEntries, locale, readDirty]); + }, [dirtyEntries, locale, readDirty, rendersSettled]); const cancel = React.useCallback(() => { if (savingRef.current) return; for (const entry of dirtyEntries()) entry.cancel();