Repository navigation
feat: start over from any step with reset overrides - #12
Merged
Merged
Conversation
bcheung
force-pushed
the
feat/reset-options
branch
from
November 6, 2026 03:57
7af84b1 to
e43ace1
Compare
bcheung
marked this pull request as ready for review
November 6, 2026 03:57
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.
Description
reset()always returns to the context and start step the flow mounted with. There's no way to start over with different data or at a different step: for example a review screen with a "Start fresh" button that should clear the answers and go back to the first question, without leaving the review screen in history.The workaround is to build state by hand with
createInitialStatefrom@useflow/coreand pass it torestore(). That pulls in the core package, and it skips the cleanupreset()does (clearing saved progress).resetnow takes optional overrides:contextreplaces the initial context;initialStepIdreplaces the start step (typed to the flow's step ids).reset().reset()with no arguments is unchanged, and later plain resets still use the mount values.RESETaction already accepted both values.Restoring progress that started at another step
Restores used to reject saved progress whose path didn't begin at
start(or the mountedinitialStepId). After a reset to another step, the next launch would discard the user's progress as incompatible. That check is removed: a path can begin at any existing step. Missing steps, a current step that doesn't match the path, and an inconsistent status are still rejected; structural changes remain the job ofversion+migrate.This removes the
allowedInitialStepIdsoption ofvalidatePersistedState(and theValidatePersistedStateOptionstype), which only existed to widen that check.Type of Change
Checklist
bun run test)bun run typecheck)bun run check)bun changeset)Testing
bun run test: 391 tests pass. New tests: a saved flow reset to another step resumes there after remounting (fails with the old check), and a test that resets with overrides from the last step and checks the new step, context, empty history (canGoBackfalse) and saved-state removal, then checks a plainreset()still returns to the mount values.validatePersistedStateaccepts a path starting at a non-startstep.reset({ initialStepId })only accepts known step ids.