Skip to content

fix(slate-history): preserve unsaved edits inside inserted subtrees - #6370

Open
peterolkhov wants to merge 1 commit into
ianstormtaylor:mainfrom
peterolkhov:codex/preserve-unsaved-history-subtrees
Open

peterolkhov wants to merge 1 commit into
ianstormtaylor:mainfrom
peterolkhov:codex/preserve-unsaved-history-subtrees

Conversation

@peterolkhov

Copy link
Copy Markdown

Save an inserted paragraph, append text inside it with HistoryEditor.withoutSaving, then undo and redo: the paragraph comes back without the unsaved text. Unsaved child blocks inside a saved container can disappear the same way. Rebasing keeps a whole-node removal whose stored contents predate those edits.

Treat that removal as incompatible when it would swallow an unsaved update at or inside the subtree. This uses the existing conservative history fallback: the entire conflicting batch is dropped, so its container, original saved content and any unrelated operations in that batch remain applied. The next surviving batch stays undoable. This preserves unsaved data at the cost of that batch's undoability; it does not implement selective undo or general collaboration semantics. The existing dependent-redo truncation policy is unchanged.

The four-file change adds the guard, 22 regression cases, a short withoutSaving behavior note and a patch changeset. Fourteen regressions fail on the original source; all 22 pass with the fix. Independent review passes another 15 adversarial cases, including collateral operations in a discarded batch and neighboring history.

Validation: canonical build and lint pass; Mocha has 2,912 passing and 10 pending, Jest has 385 passing across 51 suites, and all five docs checks pass. The test commands ran separately, with Jest serialized. Browser/IME checks were not run for this history-only change. The coarse batch policy is the main compatibility choice to review.

If the TypeDoc migration in #6045 lands first, the new behavior note will need to move into the withoutSaving JSDoc.

@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0023576

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-history Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

side: Side
): Operation[] | null => {
if (
op.type === 'remove_node' &&

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.

  • transformOperations also calls transform with the unsaved op first (line 242), so this check runs both ways
  • an unsaved removal of a block now drops any saved batch that touched that block, including its edits in other blocks
  • tried it: set both blocks to h1 in one batch, remove block 1 without saving, undo
  • main turns block 0 back to p, on this branch there is nothing left to undo and block 0 stays h1
  • run the check only on the history op, e.g. if (removesUnsavedEdit(ops[0], by[0])) return null in the single op case of transformOperations, and add a test for this case

removed, or that can no longer be applied, such as a split whose halves are no
longer next to each other, is dropped.

A batch that would remove a whole node is also dropped if an unsaved change

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.

  • this drops the user's latest step in a common collaboration case
  • type "b", insert paragraph "x", a collaborator types "R" in "x" without saving
  • first undo on main removes "x", on this branch it skips "x" and removes "b"
  • same when the unsaved change is only a setNodes on "x", with no text at risk
  • for edits inside the node, could the stored node in the remove_node get the unsaved change applied instead of dropping the batch?

This branch has not been deployed

No deployments
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