Repository navigation
Fix runFlow error handling, useFlow lifecycle, and Next helpers - #1
Merged
Merged
Conversation
- runFlow: retry and roll back only the action; post-success failures
settle as errors without re-running the mutation. beforeRun and
optimistic.apply failures no longer reject. Hook errors are collected
in hookErrors. Add status and rolledBack to FlowRunResult. Remove the
abort listener from the caller signal.
- useFlow: clear pending in finally, abort in-flight runs on unmount and
reset, ignore stale results after reset, use result.status.
- tags/paths builders: not thenable, serialize to { kind, value }.
- createServerActionAdapter: call action(input) only; optional
forwardContext passes serializable { flowId, attempt }.
- testkit: check result.status; add regression tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs on pushes to main and on pull requests across Node 20, 22 and 24. The README badge already points at this workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks done
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.
Summary
Fixes runtime correctness bugs found during a repository review. Each one was reproduced before the fix and is covered by a regression test.
runFlow
invalidate,consistency,redirect,reconcile,onSuccess,afterSuccess) threw, the error was retried, so the server action ran again, and optimistic state was rolled back. Now only the action and its middleware are retried or rolled back. Post-success failures settle withstatus: "error"and keepdata.beforeRunoroptimistic.applyused to rejectrunFlowand skiponSettled. The run now settles as an error and the action is not called.onError,afterError,onSettledorrollbackare collected inhookErrorsand no longer skip the remaining hooks.throw undefinedwas reported as a success. Results now carrystatusandrolledBack.signalis removed when the run settles.useFlow
pendingis cleared infinally.reset(), and results from runs started before a reset are ignored.optimisticstage is now actually visible.cancel()without an argument targets the latest run.mutaflow/next
tags/pathsbuilders were thenable, soawait tags.todoshung. They also serialized incorrectly withJSON.stringify.createServerActionAdapterused to forward{ flowId, attempt, signal }to every Server Action. A live Next.js 15.5 check showed this does not throw, but theAbortSignalcannot be used on the server, so the argument was misleading. The adapter now callsaction(input). The newforwardContext: trueoption passes{ flowId, attempt }.Behavior changes
flow:errorstage isrolled_backonly when a rollback actually happened.expectRollbackandexpectReconciledcheckresult.status.Test plan
npm test: 39/39 pass (11 new regression tests)npm run typecheck🤖 Generated with Claude Code