Skip to content

fix(studio): a sealed resize follows the pointer instead of trailing it by about 6 px - #8537

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/sealed-draft-step-sends-once
Nov 22, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/sealed-draft-step-sends-once

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

On a sealed preview, a resize now grows the element under the pointer. Before, on each pointer step the element stepped back a few pixels for a frame and then jumped about 6 px to catch up, so a resize trailed the pointer by about 6 px.

Why

A resize step draws two parts on the frame's element: its offset (applyManualOffsetDragDraft) and its size (drawPreviewDraft({ size })), one call after the other in resizeDraft.ts. drawPreviewDraft sent straight away whenever no request was in flight. So the first call left on its own, carrying the step's new offset with the previous size, and the frame painted that half state. The size followed one round trip later. When a request was already in flight the two calls merged, which is why the trail came and went with load.

The edit-accuracy bench shows it in every sealed resize. In seqplainkeys-none-center-r0-root-z100 at 4x CPU, every resize trailed the pointer by 6.2-6.3 px, with a 6.4 px jump. Unsealed, the same case trails 0.0 px. The bench's per-frame trace shows the corner stepping back about 2.5 px, then jumping +6.4 px to the pointer, on each step. The drop and renderKey checks failed whenever their reading caught that drawn offset.

Related work

Refs #7846 (Studio's preview sealed by default): its edit-accuracy gate flags these cases. #8473 sends a save's draft end in the same message as the patch; this change keeps that working.

How

previewDrafts.ts alone changes:

  • Draws batch per task. drawPreviewDraft schedules its send for the end of the current task, once per frame's queue, instead of sending at once. Everything a gesture draws in one step leaves as one draft. Fields merge as before: a later draw of the same field wins, and a field no later draw names keeps its value.
  • Ends still send at once, and a draw waiting in the same task leaves with them, ahead of them in the same message.
  • A save flushes first. takePreviewDraftEnds, which a save calls right before it sends, now sends any waiting draw first. The draw goes out before the save that carries its end, and the end can still ride the save (fix(studio): a sealed move or resize ends its draft in the save's own frame message #8473).

Every draw site now batches this way:

  • the drag offset (manualOffsetDrag.ts);
  • the resize size (resizeDraft.ts);
  • the rotation (rotationDraft.ts);
  • an undo's revert (gestureUndoRevert.ts);
  • a keep-size end (previewDrafts.ts), where the offset clear and its end now share one message.

A plain (unsealed) preview doesn't change: its elements have no stand-in, so drawPreviewDraft returns before queueing anything.

No visible change

On a sealed preview, a resize follows the pointer without the small jump on each step. The interface itself doesn't change.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • packages/studio/src/components/editor/previewDrafts.test.ts:
    • "sends a resize step's offset and size in one message, so the frame never shows one without the other": against main, the step leaves as two messages, the first with no size;
    • "keeps what each draw in one task set: a later field wins, and a size drawn earlier stays".

"sends a draw waiting in this task before a save that carries its end" passes on main and fails if the save's flush is removed.

"sends one request at a time and draws only the latest of the moves that waited" still holds. It now makes its first draw in a task of its own, because draws in one task leave together.

  • Every test under packages/studio/src/components/editor, src/hooks and src/player (578 files, 6,714 tests) passes on Linux. Three earlier runs each had one failure, runtimeProtocol.test.ts. It also failed on main's code in that tree and passes once the core package is rebuilt, so it came from a stale build, not this change.
  • On the bench at 4x CPU, three runs per mode:
    • seqplainkeys-none-center-r0-root-z100, sealed: resizes trail 0.2-0.3 px, against 6.2-6.3 px before; unsealed is 0.0-0.1. Its drop and renderKey checks pass in all three runs. One run still misses a move step by 12.4 px and one misses its undo; both are separate work.
    • resize-none-px-r0-root-z100, sealed: passes every check, tracking 0.23 px. Before, tracking and teleport failed in 3 of 3 runs.
  • Pre-commit (format, lint, fallow, typecheck) passes.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 71 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at 60bd943d.

Need ✅ (sealed resize trailed the pointer by about 6 px) · Size ✅ (previewDrafts.ts only, plus tests) · Reuse ✅ (the existing per-frame queue and field merge) · Simpler ✅ · Structure ✅
Risk: low. Draws only, on sealed previews; an unsealed preview returns before queueing.

  • Draws now leave in one queueMicrotask send per frame, which always runs before the next pointer event. Both resize draws (the offset, then drawPreviewDraft({ size })) run in one handler, so the frame never gets an offset without its size.
  • Each end still sends at once, with any waiting draw ahead of it in the same message, and the frame applies drafts in order. That covers cancel and restore, commit ends, the keep-size end and restoreRotationDraft. The later scheduled send finds nothing left and does nothing.
  • takePreviewDraftEnds sends a waiting draw first. Draws and the save both go through previewAnswer → client.request in call order, so the draw goes out before the save that carries its end (#8473).
  • previewDraftLive still reads the drawn-state map synchronously. Queues stay keyed by iframe, so two frames don't interfere, and a draw that lands after a reload is skipped as before.

Checked locally:

  • At head: previewDrafts.test.ts passes 16/16. src/components/editor plus useDomEditPositionPatchCommit pass 2187 tests (182 files). The sealed-preview tests pass 259/259.
  • With main's previewDrafts.ts restored, the two tests named on the "fails without the fix:" line fail.
  • With the flush in takePreviewDraftEnds removed, "sends a draw waiting in this task before a save that carries its end" fails.
  • CI is green at this head.

Non-blocking:

  • The names and comments say "task end", but a microtask runs when the current call stack empties. Draws separated by an await, or made in two separate listener callbacks, would not merge. No draw site does that today.
  • If a draw is already in flight when a save starts, the end is left out of the save, as on main. The existing waiting check handles it.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 8521027 Nov 22, 2026
78 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-draft-step-sends-once branch November 22, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants