Add undo and redo lifecycle callbacks#40
Merged
Conversation
| onUndo, | ||
| onRedo, | ||
| children, | ||
| }) => { |
There was a problem hiding this comment.
🟡 Medium react/provider.tsx:86
onUndo and onRedo are applied to the store in useEffect, which runs after descendant effects during the same commit. A descendant that calls undoManager.undo() or redo() in its effect observes the previous callback (or undefined) instead of the prop from the current render. Update these handlers synchronously during render (e.g. via refs) rather than deferring replacement to effects.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @src/react/provider.tsx around line 86:
`onUndo` and `onRedo` are applied to the store in `useEffect`, which runs after descendant effects during the same commit. A descendant that calls `undoManager.undo()` or `redo()` in its effect observes the previous callback (or `undefined`) instead of the prop from the current render. Update these handlers synchronously during render (e.g. via refs) rather than deferring replacement to effects.
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.
Adds successful undo/redo callbacks across the standalone manager, store, and React provider while routing action failures through the existing error channel. Grouped actions now retain their members, run in the correct order, and compensate already-applied members when a later member fails; provider callbacks can also be replaced without recreating the store. Updates public types, README examples, package version, and focused store/undo/provider coverage. Verified with
pnpm typecheck,pnpm test(252 passed, 3 skipped), andpnpm build.Note
Add onUndo and onRedo lifecycle callbacks to the undo manager and store
onUndoandonRedooptional callbacks toUndoManagerConfig,FirestateConfig, andFirestateProviderProps, invoked after successful undo/redo operations.setOnUndoandsetOnRedomethods toFirestateStorefor replacing handlers at runtime without recreating the store.onErrorchannel withErrorContext { type: 'undo', operation: 'undo' | 'redo' }instead of only logging to console.createUndoManager: consecutive actions sharing agroupIdare merged into a single atomic entry that undoes newest-first and redoes oldest-first, with compensation on partial failure.📊 Macroscope summarized 1585d0f. 5 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.