Action Store: Preserve last error through running for stale-while-revalidate#1624
Action Store: Preserve last error through running for stale-while-revalidate#1624mcintyre94 wants to merge 1 commit into
error through running for stale-while-revalidate#1624Conversation
🦋 Changeset detectedLatest commit: 84cd1f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 47 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
BundleMonFiles updated (16)
Unchanged files (131)
Total files change +3.72KB +0.71% Final result: ✅ View report in BundleMon website ➡️ |
419b944 to
2f9688e
Compare
|
Documentation Preview: https://kit-docs-ja1r475c4-anza-tech.vercel.app |
trevor-cortex
left a comment
There was a problem hiding this comment.
LGTM (commenting rather than approving — no write access).
Clean, well-scoped extension of the existing SWR behavior to error. The change is symmetric with the prior data handling: previousError is now threaded through into the running snapshot the same way previousData already was, and success clears it (so a successful retry doesn't keep showing the old failure) while reset() clears both. The type, docs, README, changeset, and tests are all consistent with each other.
Things to watch out for:
- The
runningvariant'serrorwidens fromundefinedtounknown. Downstream consumers that narrowed onstatus === 'running'and relied onerrorbeingundefinedthere will need to adjust — the changeset'sminorbump is correct given pre-1.0 conventions whereminormay be treated as breaking. successclearserrorbut onlyreset()clearsdata— an intentional asymmetry that's now called out in both the package docstring and the README. Worth keeping in mind for anyone building on this.- The
setStateshort-circuit increateReactiveActionStorestill fires the listener on anerror → runningtransition becausestatusdiffers, so subscribers correctly observe the status flip even whendataanderrorare unchanged.
Notes for subsequent reviewers:
- Test coverage is solid: the new subscribable-layer tests cover both
error → running(preserves error) andsuccess → error → running(preserves both staledataand staleerror), and the React test confirmserrorclears on the subsequentsuccess. No need to ask for more. - The variant reordering in
ReactiveActionStateis cosmetic —runninganderrorare now structurally identical except for the discriminant, which is the whole point of this PR.
error through running for stale-while-revalidateerror through running for stale-while-revalidate
1c2b3e9 to
3471172
Compare
2f9688e to
3c31014
Compare
3471172 to
f22b562
Compare
3c31014 to
475b052
Compare
f22b562 to
674c112
Compare
475b052 to
a1625b6
Compare
674c112 to
f2bb5d1
Compare
a1625b6 to
a09827d
Compare
Errors from a `ReactiveActionStore` now persist through a subsequent `running` state, matching the existing behavior for `data`. A re-dispatch after a failure keeps the previous error in `state.error` until the new attempt resolves — `success` clears it, a new failure replaces it. This mirrors how SWR and TanStack Query handle revalidation: stale-while-revalidate applies symmetrically to data and errors, so consumers don't have to choose between flickering and losing context on retry. The `running` variant of `ReactiveActionState<T>` widens from `error: undefined` to `error: unknown`, which surfaces through `useAction` as a behavior change: the `error` field now persists across a new `send(...)` call until that call resolves, instead of clearing immediately. The README, JSDoc, and tests are updated to match. `useRequest` will pick this up via a follow-up commit on the next branch in the stack.
a09827d to
84cd1f2
Compare
f2bb5d1 to
4d72b50
Compare

Improving SWR for reactive-action-store: it now maintains the
erroras well asdataon a subsequent dispatch. This means that apps can display the previous error on a retrying state if they'd like to.Related to first note here: #1619 (comment) - this means we can track state correctly on a running -> error -> running retry scenario.