@@ -2342,6 +2342,8 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
23422342 const cb = ( v : V | undefined , updateCache = false ) : V | undefined => {
23432343 const { aborted } = ac . signal
23442344 const ignoreAbort = options . ignoreFetchAbort && v !== undefined
2345+ const proceed = options . ignoreFetchAbort ||
2346+ ! ! ( options . allowStaleOnFetchAbort && v !== undefined )
23452347 if ( options . status ) {
23462348 if ( aborted && ! updateCache ) {
23472349 options . status . fetchAborted = true
@@ -2352,7 +2354,7 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
23522354 }
23532355 }
23542356 if ( aborted && ! ignoreAbort && ! updateCache ) {
2355- return fetchFail ( ac . signal . reason )
2357+ return fetchFail ( ac . signal . reason , proceed )
23562358 }
23572359 // either we didn't abort, and are still here, or we did, and ignored
23582360 const bf = p as BackgroundFetch < V >
@@ -2380,10 +2382,11 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
23802382 options . status . fetchRejected = true
23812383 options . status . fetchError = er
23822384 }
2383- return fetchFail ( er )
2385+ // do not pass go, do not collect $200
2386+ return fetchFail ( er , false )
23842387 }
23852388
2386- const fetchFail = ( er : any ) : V | undefined => {
2389+ const fetchFail = ( er : any , proceed : boolean ) : V | undefined => {
23872390 const { aborted } = ac . signal
23882391 const allowStaleAborted = aborted && options . allowStaleOnFetchAbort
23892392 const allowStale =
@@ -2393,7 +2396,8 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
23932396 if ( this . #valList[ index as Index ] === p ) {
23942397 // if we allow stale on fetch rejections, then we need to ensure that
23952398 // the stale value is not removed from the cache when the fetch fails.
2396- const del = ! noDelete || bf . __staleWhileFetching === undefined
2399+ const del = ! noDelete ||
2400+ ! proceed && bf . __staleWhileFetching === undefined
23972401 if ( del ) {
23982402 this . #delete( k , 'fetch' )
23992403 } else if ( ! allowStaleAborted ) {
0 commit comments