@@ -837,6 +837,15 @@ class LRUCache {
837837 if ( v !== oldVal ) {
838838 if ( this . #hasFetchMethod && this . #isBackgroundFetch( oldVal ) ) {
839839 oldVal . __abortController . abort ( new Error ( 'replaced' ) ) ;
840+ const { __staleWhileFetching : s } = oldVal ;
841+ if ( s !== undefined && ! noDisposeOnSet ) {
842+ if ( this . #hasDispose) {
843+ this . #dispose?. ( s , k , 'set' ) ;
844+ }
845+ if ( this . #hasDisposeAfter) {
846+ this . #disposed?. push ( [ s , k , 'set' ] ) ;
847+ }
848+ }
840849 }
841850 else if ( ! noDisposeOnSet ) {
842851 if ( this . #hasDispose) {
@@ -1090,15 +1099,15 @@ class LRUCache {
10901099 const pcall = ( res , rej ) => {
10911100 const fmp = this . #fetchMethod?. ( k , v , fetchOpts ) ;
10921101 if ( fmp && fmp instanceof Promise ) {
1093- fmp . then ( v => res ( v ) , rej ) ;
1102+ fmp . then ( v => res ( v === undefined ? undefined : v ) , rej ) ;
10941103 }
10951104 // ignored, we go until we finish, regardless.
10961105 // defer check until we are actually aborting,
10971106 // so fetchMethod can override.
10981107 ac . signal . addEventListener ( 'abort' , ( ) => {
10991108 if ( ! options . ignoreFetchAbort ||
11001109 options . allowStaleOnFetchAbort ) {
1101- res ( ) ;
1110+ res ( undefined ) ;
11021111 // when it eventually resolves, update the cache.
11031112 if ( options . allowStaleOnFetchAbort ) {
11041113 res = v => cb ( v , true ) ;
0 commit comments