fix(builder): prevent undo from reverting multiple edits at once - #40
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Fast successive graph mutations saved the same pre-change workflow into the undo stack because handlers captured stale SWR data. One undo then reverted multiple server-side edits at once. Use lastPersistedRef for history snapshots, refresh it after each mutation via SWR mutate, and skip duplicate consecutive snapshots. Co-authored-by: esadrianno <esadrianno@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully 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.
Bug and impact
When users made two or more graph edits in quick succession (before SWR revalidated), both mutations saved the same stale workflow snapshot to the undo stack. A single undo then PATCHed the server back two or more steps, causing unexpected data loss.
Root cause
Graph mutation handlers captured
previous = workflowfrom SWR at callback start. While the server applied each edit sequentially, SWR often still held the pre-edit graph when the second mutation completed, pushing duplicate snapshots ontoHistoryManager.lastPersistedRefexisted for undo transitions but was not used when recording history.Fix
saveToHistory()now recordslastPersistedRef(last known persisted graph) instead of caller-supplied stale SWR data.mutateWorkflow()awaits SWR revalidation and refresheslastPersistedReffrom the server after each successful mutation.HistoryManager.saveStateskips duplicate consecutive snapshots as a safety net.Validation
npm run test:run— 236 tests passinghistory-manager.test.tsmutateWorkflowbehavior