fix(editor): persist page-setup changes on save (data-loss bug) - #168
Merged
Merged
Conversation
…tive save) A page-setup change (size/orientation/margins) writes to the model-level finalSectionProperties, but it's not a ProseMirror transaction — so the change tracker never sees it, changedParaIds is empty, and the selective save path (the default) never re-emits the body sectPr. Result: the change was silently lost on reopen. Only a full repack serializes finalSectionProperties. Fix: usePageSetupControls flips a sectionPropsDirtyRef when page setup is applied; useFileIO ORs it into structuralChange, forcing attemptSelectiveSave to bail to a full repack (mirrors the existing hasInjectedReplies force), then resets the flag after a successful save. Regression test in selectiveSave.test.ts documents the bug (selective drops the sectPr change) and confirms the fix's mechanism (forcing structuralChange → repack persists it). Interim fix per SCRATCHPAD; the proper fix (PM-native section properties) remains.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
… save race) Review of #168 found the flag was reset AFTER the awaited toBuffer: a page-setup change applied during an in-flight autosave would have its dirty flag clobbered by the late reset and get dropped on the next save. Consume + reset the flag synchronously before the await (a set flag already forces this save to repack), and restore it if the save fails. Mirrors the mutateChart no-await-between rule. Also add a usePageSetupControls test guarding the producer side of the wiring (applying page setup dirties the flag; a read-only apply does not) — the earlier core test only covered the selective-save mechanism, not the React wiring.
This branch was previously deployed
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.
Fixes the high-priority data-loss bug from SCRATCHPAD: margin/orientation/size changes were silently dropped on save.
Root cause
Page setup writes to the model-level
finalSectionProperties, but it isn't a ProseMirror transaction — so the change tracker never sees it,changedParaIdsis empty, and the default selective save (useFileIO→toBuffer({ selective })→attemptSelectiveSave) only patches changed paragraphs and never re-emits the bodysectPr. Only a full repack serializes it. Confirmed by inspection + user report.Fix
usePageSetupControlsflips asectionPropsDirtyRefwhen page setup is applied (the single apply path).useFileIOORs it intostructuralChange, forcingattemptSelectiveSaveto bail → full repack (mirrors the existinghasInjectedRepliesforce), then resets the flag after a successful save (stays set if the save failed).Test
New regression test in
selectiveSave.test.tsthat documents the bug (selective save with a changedpageWidth+ emptychangedParaIdsreopens with the original width) and confirms the fix's mechanism (forcingstructuralChange→repackDocxreopens with the new width). It passes — i.e. it reproduced the drop and verified the repack path persists.Verification
pnpm checkgreen ·bun test1740 pass (+1).Interim fix per SCRATCHPAD; the proper fix (PM-native section properties, which also makes it Ctrl+Z-undoable) remains logged.