Repository navigation
fix(studio): a host can claim its writes under the key Studio's edit history uses - #5064
Merged
Merged
Conversation
miguel-heygen
marked this pull request as ready for review
October 5, 2026 10:26
Contributor
Edit accuracy: accurate 2040 (base branch 2040), smooth 1624 of thoseThe gate passes. Quarantined, measured but not gated (0) |
jrusso1020
approved these changes
Oct 5, 2026
jrusso1020
left a comment
Collaborator
There was a problem hiding this comment.
Approving at 519b5aa3.
What it does: claimKey(key) returns ${pageKeyScope}:${key}, the same string recordEdit now builds through it. A host that claims its own write under claimKey(key) and then calls recordEdit with key joins one held claim, so one undo takes back both.
Checked
- Tests:
usePersistentEditHistory.test.tspasses 24/24, three runs in a row. - Mutation checks:
- With
claimKeyreturning the bare key whilerecordEditkeeps the scoped one, the new test fails. - With both unscoped, "a key one page holds does not join another page's edit under the same key" fails. So the page scope from #4937 is still enforced through
claimKey.
- With
- Can a host's claim swallow a real outside edit and lose its undo? No. Joining a held claim (
heldForinprojectHistory.ts) requires the same key, nothing pending elsewhere, and no held file changed since. I probed both cases over the real engine:- An outside write to another file between the host's claim and Studio's save: the result is three entries (host claim, "Changed outside the app", Studio's save), and three undos take them back in order.
- The claimed
clip.mp4replaced outside the app before Studio's save: the first undo revertsindex.htmlonly, the second puts back the original clip ("media"), and the outside replacement stays its own step. - In both cases the join is refused rather than the outside change being misattributed. This PR changes only the key string, not the claim or join rules.
- Reachable by a host:
usePersistentEditHistoryis exported frompackages/studio/src/index.ts, and hosts compose it themselves (hostMount.test.tsx). - CI: 58 pass, 17 skipped, 0 failing at this head.
Reuse and simplification: this is the minimal shape. It returns the hook's own scope, so the key format stays in one place. Hosts that call recordEdit themselves already have created, so this only covers a backend that claims on its own.
— Rames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
usePersistentEditHistorynow also returnsclaimKey(key): the exact history key itsrecordEditclaims under for a givencoalesceKey.recordEditbuilds its own key through it, so the hook stays the one place that knows the format.Why
Since #4937 every coalescing key is scoped to the page (
<page id>:<key>), so a reload or a second tab never joins another page's step. A host that writes files itself (an import, a file replaced from disk) and claims them in the same project history, meaning to join the edit Studio saves next under the same key, had no way to learn the scoped key. Its claim stayed unscoped, so the host's write and Studio's save became two entries: one Cmd+Z took back the save and left the imported file behind.With
claimKey, the host claims underclaimKey(key)and passeskeytorecordEdit, and both land in one entry. A host that callsrecordEdititself can already list its new files increated;claimKeyis for a host whose backend writes and claims files without access to the hook.No visible change
A hook gains one returned function; nothing on screen changes. A host that adopts
claimKeygets one undo where it had two.How I tested it
usePersistentEditHistory.test.ts, over the real history routes and engine: a host claims a new file underclaimKey(key), Studio saves underkey, and one undo restores the composition and removes the file.claimKeydoes not exist).recordEditclaims under (I changedclaimKeyto return the bare key whilerecordEditkept the scoped one): the file survives the undo.tsc --noEmitfor packages/studio, oxlint and oxfmt on both files.Small on purpose: one returned function and its test.