Repository navigation
Conversation
With allowStaleOnFetchAbort, an aborted fetch resolves to the stale value while the fetchMethod keeps running. A late resolution updates the cache, but a late rejection was ignored: the settled promise stayed in the cache, so every later fetch() joined it, returned the stale value, and never called the fetchMethod again. Replace the pending promise with the stale value (or delete the entry, following the noDeleteOnFetchRejection settings) on a late rejection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a fetch() refreshes an entry that has a stale value, and the fetchMethod has not settled within staleFetchTimeout ms, resolve the fetch() to the stale value. The fetchMethod keeps running and updates the cache when it resolves; fetch() calls joining it meanwhile get the stale value at once. Entries without a stale value wait as usual, and the fetchMethod's AbortSignal is not aborted. This covers "return stale on timeout while refreshing" without creating a signal for every fetch() call, and without resolving to undefined on a cold miss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #414.
Two commits:
allowStaleOnFetchAbort, afetchMethodthat rejects after the abort left its settled promise in the cache. Every laterfetch()joined it, returned the stale value, and never called thefetchMethodagain. Now a late rejection replaces the promise with the stale value, or deletes the entry, followingnoDeleteOnFetchRejection/allowStaleOnFetchRejectionas a normal rejection would.staleFetchTimeoutoption. Whenfetch()refreshes an entry that has a stale value and thefetchMethodhasn't settled within that many ms,fetch()resolves to the stale value and setsstatus.returnedStaleand the newstatus.fetchTimedOut. ThefetchMethodkeeps running and updates the cache when it resolves, andfetch()calls joining it meanwhile get the stale value at once. If it rejects, the nextfetch()calls thefetchMethodagain (this uses the fix from commit 1). Entries with no stale value wait as usual, and thefetchMethod's signal is not aborted. It can be set on the constructor, perfetch()call, or from thefetchMethod.Tests are in
test/fetch.ts, at the end of the file so that fewer snapshot timestamps shift. Thetracing.tssnapshots were regenerated; onlystart/nowtimestamps changed. Coverage stays at 100%, and lint and prettier are clean. I didn't touch the CHANGELOG or the version.🤖 Generated with Claude Code