Skip to content

fix(studio): a sealed drag sends each step to the preview as the pointer moves - #8899

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/sealed-drag-step-before-paint
Nov 26, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/sealed-drag-step-before-paint

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

On a sealed preview, a dragged element now reaches the pointer's position in the same frame more often. On a 4x slowed CPU, the preview had the step when the frame was drawn in 166 of 400 drag frames, up from 2 of 400.

This does not close the lag: the other 234 frames still show the element one frame behind the pointer, where an unsealed preview never is.

Why

Chrome dispatches pointermove inside the task that draws the frame. A sealed drag sends each step to the preview over the preview's channel, and the preview can only take that message after the task ends, so every step reached it after the frame it belonged to had been drawn. An unsealed drag moves the element inside the pointermove handler, so it is drawn in that frame.

pointerrawupdate fires in its own task as the input arrives, before that drawing task. A step sent from it reaches the preview before the frame is drawn, unless the drawing task starts right behind it. In Studio at 4x it often does (0 to 2 ms later in the traces), which is why this is a partial fix.

Related work

None.

How

  • useDomEditOverlayGestures.ts: during a single drag on a sealed preview, a pointerrawupdate listener sends the drag's step to the preview. It is set up on the drag's first pointermove and removes itself on the first raw update after the drag ends. Everything else the drag draws (outline, readout, guides) stays on pointermove.
  • snappedDragDelta.ts: the drag's axis lock and edge snapping, moved out unchanged so pointermove and the raw update compute the same step.
  • previewDrafts.ts: a draw equal to the last one is not sent again, unless a save is waiting on it, so the pointermove that follows a raw update adds no message.
  • Where pointerrawupdate does not exist (it is feature-detected; WebKit has none, and it needs a secure context), pointermove sends the step as before.

Test plan

  • Unit tests added/updated
    • Fails without the fix: sealedRawDragStep.test.ts "draws each step after the first from the raw pointer update", and previewDrafts.test.ts "posts a step drawn twice once". Both fail on main and pass with the fix.
    • Also pinned: pointermove still draws when no raw update came first; an unsealed drag ignores raw updates; the listener stops after the drag ends.
    • src/components/editor/ 187 files, 2214 tests pass in 4 runs, the last on this head. Studio typecheck clean.
  • Manual testing performed
    • Edit accuracy seqnudge-none-px-r0-root-z100, sealed, CPU 4x, 10 rounds on main and 10 with the fix, interleaved, with a performance trace of each drag:

      main this branch
      frames where the preview had the step when drawn 2 / 400 166 / 400
      per-frame main-thread work, p95 25.9 ms 22.6 ms
      messages sent per drag, median 21 20.5
    • In the desktop app's Studio page, pointerrawupdate exists and fires once per pointer move (a loopback origin, which is a secure context).

  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

Before

Before: each frame of a sealed drag at 4x CPU, green when the preview had the step

After

After: each frame of a sealed drag at 4x CPU, green when the preview had the step

…ter moves

Chrome dispatches pointermove inside the task that paints the frame, so a step
a sealed drag sent from pointermove reached the preview after that paint. The
step now goes from pointerrawupdate, which fires in its own task before the
rendering. On a 4x slowed CPU this puts the step in the preview before its
frame is drawn in 166 of 400 frames instead of 2; the rest still arrive a frame
late, because the rendering task often starts right after the raw update.
pointermove still draws where that event is missing, and a step drawn twice is
sent once.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (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.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

Unstable (1)

  • seqab-none-pct-r0-root-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@vanceingalls vanceingalls 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.

Changes requested at 7193aff: the Comments check is red on this head and the failure is this PR's own lines. The code itself is clean.

Blocker (Comments / A package file's comment share may not rise, run 45772855162):

  • packages/studio/src/components/editor/previewDrafts.ts: comment share rose from 3.6% (8/225) to 3.8% (9/236). One comment line added; cut it or move it into a name (the doc line on drawsNothingNew is the new one).
  • packages/studio/src/components/editor/rawPointerSteps.ts: new file at 15.0% (3/20), over the package's 9.2%. Cut to one comment line.

Not main's red: both lines are added by this diff.

Code review, no findings:

  • Ordering: the raw path and pointermove compute the step through the same snappedDragDelta, and raw events come before the pointermove that carries the same or a newer position, so the preview only moves forward. A pointermove equal to the last drawn step is dropped by drawsNothingNew, never a different one.
  • Pointerup: the commit still uses lastSnappedDx/Dy from pointermove and draws it through applyManualOffsetDragCommit -> drawPreviewDraft. drawsNothingNew returns false once saving is armed, and a commit that differs from the last raw draw is sent, so the final preview equals the committed offset. gestureRef is nulled first, so a raw update after release draws nothing and removes its listener.
  • Cancel: clearPointerState restores through restoreStudioPathOffset -> endPreviewDraft("restore"), which deletes the drawn entry, so the next drag cannot be skipped as a repeat.
  • Hover raw updates are ignored (movesGesture needs the primary button), and a missing pointerrawupdate falls back to pointermove.
  • fails without the fix lines are in the body and both tests exist at the head.

Merge hold: the hold for the 70+30 board is Miguel's, not mine. Once Comments is green and Producer integration tests and CodeQL (pending now) finish, I would approve this as it is.

@vanceingalls vanceingalls 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.

Approved at 560e9f4.

The change since 7193aff is two files and only removes or shortens comments: one doc line cut in previewDrafts.ts, and the header comment in rawPointerSteps.ts cut to one line plus one doc line removed. No code changed. The ordering, pointerup and cancel code I found clean last time is untouched.

Every check is green at this head: Comments, Producer: integration tests, CodeQL (all Analyze jobs) and the rest. 59 passed, 22 skipped, none red or pending.

The merge hold for the 70+30 board is Miguel's.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit a3c190d Nov 26, 2026
81 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-drag-step-before-paint branch November 26, 2026 07:49
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