Skip to content

Commit 21bcd57

Browse files
fix(studio): let a failed DOM edit report that it failed (#3510)
* fix(studio): let a failed text or style commit report itself `runDomEditCommit` catches a persist failure, reverts, fires `onError` and then resolves. That contract is deliberate and its docstring says so: the human path learns the write failed from the toast `onError` puts on screen, so a rejection would be redundant. It also means a caller awaiting `handleDomTextCommit` or `handleDomStyleCommit` cannot tell a landed write from a reverted one, because both resolve with `undefined`. The runner already offers `onSettled` as the way out. Text and style were the two commits that never got it wired. Add `runReportedDomEditCommit`, which owns `onSettled` (forwarding to a caller-supplied one rather than dropping it) and returns whether the write landed. Both handlers now return a tagged outcome, so the three preconditions that previously returned early and silently are each distinguishable: no selection, a manual-geometry property the style path refuses, and a selection that cannot edit styles. Same for text: no selection versus not text-editable. Human-facing behaviour is unchanged and the tests assert that: the toast still fires and the optimistic DOM change is still reverted. The callback props that carry these handlers ignore the result, so their declared type widens from `Promise<void>` to `Promise<unknown>`. That type is hand-copied in fourteen places; consolidating it is worth its own change. `useDomEditTextCommits.ts` is now 593 lines against the 600-line cap. The next change to it needs a split. * fix(studio): stop a paused save queue reporting a position edit as saved Two more commits that could not tell a caller they had failed. `useDomEditPositionPatchCommit` swallowed `DomEditSaveQueueOpenError` and resolved. The intent was right, a paused save queue already puts a banner on screen and one toast per blocked edit is noise, but swallowing it also skipped the caller's revert: `useDomGeometryCommits` only restores the optimistic offset, size or rotation from its `.catch`. So once the breaker opened, a drag left the element where the user dropped it while nothing reached the file, and the next reload snapped it back. It now rejects without toasting. The banner still does the telling; the caller gets to revert. `handleDomEditElementsDelete` caught everything and only toasted, so an unpatchable target and a completed delete were indistinguishable to a caller. It now returns an outcome, with `no-project` and `no-selection` separated from a failed write rather than all three sharing an early `return`. Adds the first test for `useDomEditPositionPatchCommit`, covering the paused queue, an ordinary failure, and success. * fix(studio): honor DOM edit failure outcomes * fix(studio): classify stale delete previews * fix(studio): enforce DOM edit outcome types
1 parent 7170dc6 commit 21bcd57

28 files changed

Lines changed: 541 additions & 104 deletions

‎packages/studio/src/components/editor/DomEditCropHandles.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function makeEl(id: string, clip: string): HTMLElement {
3535

3636
function render(
3737
el: HTMLElement,
38-
onStyleCommit: (property: string, value: string) => Promise<void> | void = () => undefined,
38+
onStyleCommit: (property: string, value: string) => Promise<unknown> | void = () => undefined,
3939
): { root: Root; rerender: (next: HTMLElement) => void } {
4040
const host = document.createElement("div");
4141
document.body.append(host);

‎packages/studio/src/components/editor/DomEditCropHandles.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface CropGestureState {
2828
interface DomEditCropHandlesProps {
2929
selection: DomEditSelection;
3030
overlayRect: OverlayRect;
31-
onStyleCommit?: (property: string, value: string) => Promise<void> | void;
31+
onStyleCommit?: (property: string, value: string) => Promise<unknown> | void;
3232
}
3333

3434
// Hit-strip size (px) for an edge crop handle: THICKNESS extends outward from

‎packages/studio/src/components/editor/DomEditOverlay.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ interface DomEditOverlayProps {
8383
restore?: () => void,
8484
) => Promise<void> | void;
8585
onRotationCommit: (selection: DomEditSelection, next: { angle: number }) => Promise<void> | void;
86-
onStyleCommit?: (property: string, value: string) => Promise<void> | void;
86+
onStyleCommit?: (property: string, value: string) => Promise<unknown> | void;
8787
gridVisible?: boolean;
8888
gridSpacing?: number;
8989
recordingState?: GestureRecordingState;

‎packages/studio/src/components/editor/DomEditSelectionChrome.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ interface DomEditSelectionChromeProps {
123123
groupSelectionCount: number;
124124
blockedMoveRef: RefObject<BlockedMoveState | null>;
125125
gestures: GestureHandlers;
126-
onStyleCommit?: (property: string, value: string) => Promise<void> | void;
126+
onStyleCommit?: (property: string, value: string) => Promise<unknown> | void;
127127
onBoxMouseDown: (e: React.MouseEvent) => void;
128128
onBoxClick: (event: React.MouseEvent<HTMLDivElement>) => void;
129129
/** The canvas' text-editing session: what opens one, and whether one is open. */

‎packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @vitest-environment happy-dom
22

33
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { DomEditSaveQueueOpenError } from "../../utils/domEditSaveQueue";
45
import type { DomEditSelection } from "./domEditing";
56
import type { GestureState, UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
67

@@ -75,7 +76,9 @@ interface CommitCall {
7576
offset: { x: number; y: number } | undefined;
7677
}
7778

78-
function buildHarness() {
79+
function buildHarness(
80+
onBoxSizeCommit?: UseDomEditOverlayGesturesOptions["onBoxSizeCommitRef"]["current"],
81+
) {
7982
const element = document.createElement("div");
8083
document.body.append(element);
8184

@@ -136,9 +139,12 @@ function buildHarness() {
136139
onManualDragStartRef: ref(() => {}),
137140
onPathOffsetCommitRef: ref(() => {}),
138141
onGroupPathOffsetCommitRef: ref(() => {}),
139-
onBoxSizeCommitRef: ref((_s, size, offset) => {
140-
commits.push({ size, offset });
141-
}),
142+
onBoxSizeCommitRef: ref(
143+
onBoxSizeCommit ??
144+
((_s, size, offset) => {
145+
commits.push({ size, offset });
146+
}),
147+
),
142148
onRotationCommitRef: ref(() => {}),
143149
onCanvasPointerMoveRef: ref(() => Promise.resolve(null)),
144150
onCanvasMouseDown: () => {},
@@ -172,6 +178,15 @@ function evt(clientX: number, clientY: number) {
172178
} as unknown as React.PointerEvent<HTMLDivElement>;
173179
}
174180

181+
async function finishResize(handlers: ReturnType<typeof createDomEditOverlayGestureHandlers>) {
182+
handlers.startGesture("resize", evt(ORIGIN_CENTER.x + 100, ORIGIN_CENTER.y), {
183+
resizeHandle: "se",
184+
});
185+
handlers.onPointerMove(evt(ORIGIN_CENTER.x + 150, ORIGIN_CENTER.y));
186+
handlers.onPointerUp(evt(ORIGIN_CENTER.x + 150, ORIGIN_CENTER.y));
187+
await Promise.resolve();
188+
}
189+
175190
afterEach(() => {
176191
document.body.innerHTML = "";
177192
});
@@ -211,4 +226,23 @@ describe("anchored corner resize — the release commit feeds the center-pin off
211226
expect(offset.x).toBeCloseTo(-(size.width - ORIGIN.width) / 2, 0);
212227
expect(offset.y).toBeCloseTo(-(size.height - ORIGIN.height) / 2, 0);
213228
});
229+
230+
it("does not log a paused save queue as an ordinary resize failure", async () => {
231+
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
232+
const { handlers } = buildHarness(() => Promise.reject(new DomEditSaveQueueOpenError()));
233+
234+
await finishResize(handlers);
235+
236+
expect(consoleError).not.toHaveBeenCalled();
237+
});
238+
239+
it("still logs an ordinary resize failure", async () => {
240+
const failure = new Error("save failed");
241+
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
242+
const { handlers } = buildHarness(() => Promise.reject(failure));
243+
244+
await finishResize(handlers);
245+
246+
expect(consoleError).toHaveBeenCalledWith("resize commit failed", failure);
247+
});
214248
});

‎packages/studio/src/components/editor/propertyPanelCommitField.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function CommitField({
2121
liveCommit?: boolean;
2222
align?: "left" | "right";
2323
onPreview?: (nextValue: string) => void;
24-
onCommit: (nextValue: string) => void | Promise<void>;
24+
onCommit: (nextValue: string) => void | Promise<unknown>;
2525
}) {
2626
const [draft, setDraft] = useState(value);
2727
const valueRef = useRef(value);

‎packages/studio/src/components/editor/propertyPanelFlatLayoutSection.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export function LayoutZIndexRow({
181181
onSetStyle,
182182
}: {
183183
styles: Record<string, string>;
184-
onSetStyle: (prop: string, value: string) => void | Promise<void>;
184+
onSetStyle: (prop: string, value: string) => void | Promise<unknown>;
185185
}) {
186186
const zIndex = String(parseInt(styles["z-index"] || "auto", 10) || 0);
187187
return (
@@ -200,7 +200,7 @@ export function LayoutFlexBlock({
200200
disabled,
201201
}: {
202202
styles: Record<string, string>;
203-
onSetStyle: (prop: string, value: string) => void | Promise<void>;
203+
onSetStyle: (prop: string, value: string) => void | Promise<unknown>;
204204
disabled: boolean;
205205
}) {
206206
const isFlex = styles.display === "flex" || styles.display === "inline-flex";
@@ -337,7 +337,7 @@ interface FlatLayoutSectionProps
337337
> {
338338
element: DomEditSelection;
339339
styles: Record<string, string>;
340-
onSetStyle: (prop: string, value: string) => void | Promise<void>;
340+
onSetStyle: (prop: string, value: string) => void | Promise<unknown>;
341341
disabled: boolean;
342342
}
343343

‎packages/studio/src/components/editor/propertyPanelFlatMaskInsetRows.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function FlatMaskInsetRows({
2727
clipPathValue: string;
2828
radiusValue: number;
2929
disabled: boolean;
30-
onSetStyle: (prop: string, value: string) => void | Promise<void>;
30+
onSetStyle: (prop: string, value: string) => void | Promise<unknown>;
3131
}) {
3232
const clipPathPreset = inferClipPathPreset(clipPathValue);
3333
const parsedClipInsets = parseInsetClipPathSides(clipPathValue);

‎packages/studio/src/components/editor/propertyPanelFlatMediaSection.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function FlatMediaSection({
3838
projectDir: string | null;
3939
element: DomEditSelection;
4040
styles: Record<string, string>;
41-
onSetStyle: (prop: string, value: string) => void | Promise<void>;
41+
onSetStyle: (prop: string, value: string) => void | Promise<unknown>;
4242
onSetAttribute: (attr: string, value: string) => void | Promise<void>;
4343
onSetHtmlAttribute: (attr: string, value: string | null) => void | Promise<void>;
4444
/** A volume lane in the timeline drives the level; the slider cannot. */

‎packages/studio/src/components/editor/propertyPanelFlatPrimitives.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function FlatRow({
3535
/** Renders a trailing 10px caret-down, for select-backed rows. */
3636
dropdown?: boolean;
3737
onPreview?: (nextValue: string) => void;
38-
onCommit: (nextValue: string) => void | Promise<void>;
38+
onCommit: (nextValue: string) => void | Promise<unknown>;
3939
onReset?: () => void;
4040
}) {
4141
const track = useTrackDesignInput();

0 commit comments

Comments
 (0)