Skip to content

fix(studio): a sealed picker edit answered after another pick leaves the new pick's state alone - #8686

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/sealed-picker-state-owner
Nov 24, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/sealed-picker-state-owner

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A sealed picker edit that lands after the person has already picked another element now leaves the new pick's state alone. The edit still saves to the element it was made on.

Why

Follow-up to #8663 (review nits 2 and 3). In a sealed preview, setStyle, setDataAttr and setTextContent wait for the frame to draw before they update the picker state. The update was prev ? shown(prev) : null, so if another element was picked in the meantime, the old edit's style, attribute or text was written onto the new pick's state. The source save was already right: it uses the element captured when the edit was made.

Related work

Refs #8663.

How

  • In useElementPicker's writePickedElement, the state update applies only while the same element is still picked (samePick: same selector and id). Otherwise the state is left as it is. Unsealed, the update runs synchronously, so the pick cannot have changed and nothing changes there.
  • The hook's sealed wiring had no test (fix(studio): element picker style, data and text edits draw in a sealed preview #8663 tested only writePicked). useElementPicker.sealed.test.ts now tests it with writePicked held open until the test answers.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

packages/studio/src/hooks/useElementPicker.sealed.test.ts:

  • "a sealed edit answered after another pick saves to its own element and leaves the new pick alone": pick h1, set a color, pick p, then let the frame answer. The pick is still p, its styles have no color, and the saved file has style="color: red" on the h1.
  • "sealed edits answered in turn show on the picked element in the order they were made": a style edit and a data-attribute edit on h1 show on the pick only once answered, and both show.

Devbox: the named test passed 3 runs in a row (exit 0, 2 passed), the covering useElementPicker.test.ts passed, and studio tsc, Fallow and pre-push were clean.

fails without the fix: useElementPicker.sealed.test.ts "a sealed edit answered after another pick saves to its own element and leaves the new pick alone". With #8663's update restored (prev ? shown(prev) : null), it fails with expected 'red' to be undefined (exit 1, 1 failed, 1 passed). The ordering test stays green.

No visible change

No Studio or Desktop screen calls these setters (see #8663), and the change is in .ts files only.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 59 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)

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

Approving at 24a66766.

  • The fix holds. In writePickedElement, the sealed answer's state update now runs only when the current pick has the same selector and id as the pick the edit was made on. Otherwise the state is left alone. The source save still uses the picked captured at edit time, so the late edit still lands on its own element.
  • Red-first holds. With main's useElementPicker.ts put back, the named test "a sealed edit answered after another pick saves to its own element and leaves the new pick alone" fails with expected 'red' to be undefined (1 failed, 1 passed). At head, useElementPicker.sealed.test.ts and useElementPicker.test.ts pass (31/31).
  • I added probes with the same harness, each with writePicked held open:
    • A, then B, then A again, then A's answer: the color shows on the re-picked A, and the file gets style="color: red" on the h1. That's correct, because the frame drew the edit on that element. Keying on the element (selector and id) instead of on each pick is the right call here: a per-pick key would drop an update the frame really drew.
    • Same element picked again before the answer: the edit still shows.
    • Current pick's edit applies while an old pick's edit is still open: pick h1 and set red, pick p and set blue, answer p first and then h1. The pick stays p with blue, and the file ends with red on the h1 and blue on the p. Nothing legitimate is dropped.
    • A null answer (nothing drawn): the state is unchanged.

Nit, not from this PR:

  • Two edits on the same pick whose answers come back in reverse order leave the pick showing the older value. For example, set red, then blue, answer blue first and then red, and the final color is red. Main does the same, and the preview channel likely answers in order, so this probably can't happen in practice. I haven't verified that the channel guarantees the order.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit a8f6483 Nov 24, 2026
79 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-picker-state-owner branch November 24, 2026 10:54
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