@@ -187,34 +187,46 @@ export class ISRHandler {
187
187
return ;
188
188
}
189
189
190
- // Apply the callback if given
191
- let finalHtml = html ;
192
- if ( config ?. modifyCachedHtml ) {
193
- const timeStart = performance . now ( ) ;
194
- finalHtml = config . modifyCachedHtml ( req , html ) ;
195
- const totalTime = ( performance . now ( ) - timeStart ) . toFixed ( 2 ) ;
196
- finalHtml += `<!--\nℹ️ ISR: This cachedHtml has been modified with modifyCachedHtml()\n❗️
197
- This resulted into more ${ totalTime } ms of processing time.\n-->` ;
198
- }
199
-
200
190
// Cache exists. Send it.
201
191
this . logger . log ( `Page was retrieved from cache: ` , cacheKey ) ;
192
+ let finalHtml = html ;
202
193
203
194
// if the cache is expired, we will regenerate it
204
195
if ( cacheConfig . revalidate && cacheConfig . revalidate > 0 ) {
205
196
const lastCacheDateDiff = ( Date . now ( ) - createdAt ) / 1000 ; // in seconds
206
197
207
198
if ( lastCacheDateDiff > cacheConfig . revalidate ) {
208
199
// regenerate the page without awaiting, so the user gets the cached page immediately
209
- this . cacheGeneration . generateWithCacheKey (
210
- req ,
211
- res ,
212
- cacheKey ,
213
- config ?. providers ,
214
- 'regenerate' ,
215
- ) ;
200
+ if ( this . isrConfig . backgroundRevalidation ) {
201
+ this . cacheGeneration . generateWithCacheKey (
202
+ req ,
203
+ res ,
204
+ cacheKey ,
205
+ config ?. providers ,
206
+ 'regenerate' ,
207
+ ) ;
208
+ } else {
209
+ const result = await this . cacheGeneration . generateWithCacheKey (
210
+ req ,
211
+ res ,
212
+ cacheKey ,
213
+ config ?. providers ,
214
+ 'regenerate' ,
215
+ ) ;
216
+ if ( result ?. html ) {
217
+ finalHtml = result . html ;
218
+ }
219
+ }
216
220
}
217
221
}
222
+ // Apply the callback if given
223
+ if ( config ?. modifyCachedHtml ) {
224
+ const timeStart = performance . now ( ) ;
225
+ finalHtml = config . modifyCachedHtml ( req , finalHtml ) ;
226
+ const totalTime = ( performance . now ( ) - timeStart ) . toFixed ( 2 ) ;
227
+ finalHtml += `<!--\nℹ️ ISR: This cachedHtml has been modified with modifyCachedHtml()\n❗️
228
+ This resulted into more ${ totalTime } ms of processing time.\n-->` ;
229
+ }
218
230
return res . send ( finalHtml ) ;
219
231
} catch ( error ) {
220
232
// Cache does not exist. Serve user using SSR
0 commit comments