Skip to content

feat: add store-level getUndoPath for handle-driven navigation-aware undo#47

Merged
TrystonPerry merged 2 commits into
masterfrom
tdawg/undo-getundopath-callback
Jul 14, 2026
Merged

feat: add store-level getUndoPath for handle-driven navigation-aware undo#47
TrystonPerry merged 2 commits into
masterfrom
tdawg/undo-getundopath-callback

Conversation

@TrystonPerry

@TrystonPerry TrystonPerry commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

Handle writes (update/add/remove) push undo actions through makeOnPushUndo, which never set UndoAction.path. So action.path was always undefined for handle-driven undo and onNavigate never fired — only a manual undoManager.push({ path }) could trigger navigation-aware undo, which defeats the point.

Fix

Add a store-level getUndoPath?: () => string | undefined callback on FirestateConfig and FirestateProviderProps; makeOnPushUndo now stamps path: store.getUndoPath() onto every handle-pushed action, so the app supplies the router path at write time and onNavigate works for ordinary writes. It uses the same runtime-replace plumbing (setGetUndoPath + useEffect) as onNavigate/onError, and existing group-merge semantics are untouched (merged groups keep the newest action's path). Covered by store-level unit tests and an end-to-end integration test through the real makeOnPushUndo path, plus README docs; full suite passes (258 tests) and typecheck/build are clean.

Note

Add getUndoPath callback to stamp router path onto handle-driven undo actions

  • Adds getUndoPath?: () => string | undefined to FirestateConfig, FirestateStore, and FirestateProvider, allowing callers to supply a function that returns the current router path.
  • When a handle write pushes an undo action in shared-subscription.ts, the path from store.getUndoPath() is stamped onto the action so that onNavigate is invoked on undo/redo.
  • FirestateStore exposes setGetUndoPath to replace the resolver at runtime without recreating the store; FirestateProvider calls this in an effect when the prop changes.
  • Merged undo groups retain the newest action's path.
📊 Macroscope summarized 2261e2a. 5 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

…undo

Handle writes (update/add/remove) push undo actions through makeOnPushUndo,
which never set UndoAction.path — so onNavigate was dead for every undo except
a manual undoManager.push({ path }). Add a store-level getUndoPath callback,
stamped onto every handle-pushed action, so the app supplies the router path
at write time and navigation-aware undo works for ordinary writes.

Exposed on FirestateConfig and FirestateProviderProps with the same
runtime-replace plumbing as onNavigate/onError.
@TrystonPerry TrystonPerry merged commit b0c98c9 into master Jul 14, 2026
2 checks passed
@TrystonPerry TrystonPerry deleted the tdawg/undo-getundopath-callback branch July 14, 2026 18:59
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.

1 participant