@@ -13,11 +13,8 @@ import {
13
13
NEXT_CACHE_TAG_MAX_LENGTH ,
14
14
} from '../../lib/constants'
15
15
import * as Log from '../../build/output/log'
16
- import { trackDynamicFetch } from '../app-render/dynamic-rendering'
17
16
import type { FetchMetric } from '../base-http'
18
17
19
- const isEdgeRuntime = process . env . NEXT_RUNTIME === 'edge'
20
-
21
18
type Fetcher = typeof fetch
22
19
23
20
type PatchedFetcher = Fetcher & {
@@ -215,10 +212,7 @@ interface PatchableModule {
215
212
216
213
function createPatchedFetcher (
217
214
originFetch : Fetcher ,
218
- {
219
- serverHooks : { DynamicServerError } ,
220
- staticGenerationAsyncStorage,
221
- } : PatchableModule
215
+ { staticGenerationAsyncStorage } : PatchableModule
222
216
) : PatchedFetcher {
223
217
// Create the patched fetch function. We don't set the type here, as it's
224
218
// verified as the return value of this function.
@@ -354,35 +348,11 @@ function createPatchedFetcher(
354
348
curRevalidate = 0
355
349
}
356
350
357
- if ( _cache === 'no-cache' || _cache === 'no-store' ) {
358
- cacheReason = `cache: ${ _cache } `
359
- }
360
-
361
351
revalidate = validateRevalidate (
362
352
curRevalidate ,
363
353
staticGenerationStore . urlPathname
364
354
)
365
355
366
- const _headers = getRequestMeta ( 'headers' )
367
- const initHeaders : Headers =
368
- typeof _headers ?. get === 'function'
369
- ? _headers
370
- : new Headers ( _headers || { } )
371
-
372
- const hasUnCacheableHeader =
373
- initHeaders . get ( 'authorization' ) || initHeaders . get ( 'cookie' )
374
-
375
- const isUnCacheableMethod = ! [ 'get' , 'head' ] . includes (
376
- getRequestMeta ( 'method' ) ?. toLowerCase ( ) || 'get'
377
- )
378
-
379
- // if there are authorized headers or a POST method and
380
- // dynamic data usage was present above the tree we bail
381
- // e.g. if cookies() is used before an authed/POST fetch
382
- const autoNoCache =
383
- ( hasUnCacheableHeader || isUnCacheableMethod ) &&
384
- staticGenerationStore . revalidate === 0
385
-
386
356
switch ( fetchCacheMode ) {
387
357
case 'force-no-store' : {
388
358
cacheReason = 'fetchCache = force-no-store'
@@ -424,55 +394,20 @@ function createPatchedFetcher(
424
394
}
425
395
426
396
if ( typeof revalidate === 'undefined' ) {
427
- if ( fetchCacheMode === 'default-cache' ) {
428
- revalidate = false
429
- cacheReason = 'fetchCache = default-cache'
430
- } else if ( autoNoCache ) {
431
- revalidate = 0
432
- cacheReason = 'auto no cache'
433
- } else if ( fetchCacheMode === 'default-no-store' ) {
397
+ if ( fetchCacheMode === 'default-no-store' ) {
434
398
revalidate = 0
435
399
cacheReason = 'fetchCache = default-no-store'
436
400
} else if ( isUsingNoStore ) {
437
401
revalidate = 0
438
402
cacheReason = 'noStore call'
439
403
} else {
440
- cacheReason = 'auto cache'
441
- revalidate =
442
- typeof staticGenerationStore . revalidate === 'boolean' ||
443
- typeof staticGenerationStore . revalidate === 'undefined'
444
- ? false
445
- : staticGenerationStore . revalidate
404
+ revalidate = 0
405
+ cacheReason = 'default no cache'
446
406
}
447
407
} else if ( ! cacheReason ) {
448
408
cacheReason = `revalidate: ${ revalidate } `
449
409
}
450
410
451
- if (
452
- // when force static is configured we don't bail from
453
- // `revalidate: 0` values
454
- ! ( staticGenerationStore . forceStatic && revalidate === 0 ) &&
455
- // we don't consider autoNoCache to switch to dynamic during
456
- // revalidate although if it occurs during build we do
457
- ! autoNoCache &&
458
- // If the revalidate value isn't currently set or the value is less
459
- // than the current revalidate value, we should update the revalidate
460
- // value.
461
- ( typeof staticGenerationStore . revalidate === 'undefined' ||
462
- ( typeof revalidate === 'number' &&
463
- ( staticGenerationStore . revalidate === false ||
464
- ( typeof staticGenerationStore . revalidate === 'number' &&
465
- revalidate < staticGenerationStore . revalidate ) ) ) )
466
- ) {
467
- // If we were setting the revalidate value to 0, we should try to
468
- // postpone instead first.
469
- if ( revalidate === 0 ) {
470
- trackDynamicFetch ( staticGenerationStore , 'revalidate: 0' )
471
- }
472
-
473
- staticGenerationStore . revalidate = revalidate
474
- }
475
-
476
411
const isCacheableRevalidate =
477
412
( typeof revalidate === 'number' && revalidate > 0 ) ||
478
413
revalidate === false
@@ -673,80 +608,6 @@ function createPatchedFetcher(
673
608
}
674
609
}
675
610
676
- if (
677
- staticGenerationStore . isStaticGeneration &&
678
- init &&
679
- typeof init === 'object'
680
- ) {
681
- const { cache } = init
682
-
683
- // Delete `cache` property as Cloudflare Workers will throw an error
684
- if ( isEdgeRuntime ) delete init . cache
685
-
686
- if ( ! staticGenerationStore . forceStatic && cache === 'no-store' ) {
687
- const dynamicUsageReason = `no-store fetch ${ input } ${
688
- staticGenerationStore . urlPathname
689
- ? ` ${ staticGenerationStore . urlPathname } `
690
- : ''
691
- } `
692
-
693
- // If enabled, we should bail out of static generation.
694
- trackDynamicFetch ( staticGenerationStore , dynamicUsageReason )
695
-
696
- // If partial prerendering is not enabled, then we should throw an
697
- // error to indicate that this fetch is dynamic.
698
- if ( ! staticGenerationStore . prerenderState ) {
699
- // PPR is not enabled, or React postpone is not available, we
700
- // should set the revalidate to 0.
701
- staticGenerationStore . revalidate = 0
702
-
703
- const err = new DynamicServerError ( dynamicUsageReason )
704
- staticGenerationStore . dynamicUsageErr = err
705
- staticGenerationStore . dynamicUsageDescription = dynamicUsageReason
706
- throw err
707
- }
708
- }
709
-
710
- const hasNextConfig = 'next' in init
711
- const { next = { } } = init
712
- if (
713
- typeof next . revalidate === 'number' &&
714
- ( typeof staticGenerationStore . revalidate === 'undefined' ||
715
- ( typeof staticGenerationStore . revalidate === 'number' &&
716
- next . revalidate < staticGenerationStore . revalidate ) )
717
- ) {
718
- if (
719
- ! staticGenerationStore . forceDynamic &&
720
- ! staticGenerationStore . forceStatic &&
721
- next . revalidate === 0
722
- ) {
723
- const dynamicUsageReason = `revalidate: 0 fetch ${ input } ${
724
- staticGenerationStore . urlPathname
725
- ? ` ${ staticGenerationStore . urlPathname } `
726
- : ''
727
- } `
728
-
729
- // If enabled, we should bail out of static generation.
730
- trackDynamicFetch ( staticGenerationStore , dynamicUsageReason )
731
-
732
- // If partial prerendering is not enabled, then we should throw an
733
- // error to indicate that this fetch is dynamic.
734
- if ( ! staticGenerationStore . prerenderState ) {
735
- const err = new DynamicServerError ( dynamicUsageReason )
736
- staticGenerationStore . dynamicUsageErr = err
737
- staticGenerationStore . dynamicUsageDescription =
738
- dynamicUsageReason
739
- throw err
740
- }
741
- }
742
-
743
- if ( ! staticGenerationStore . forceStatic || next . revalidate !== 0 ) {
744
- staticGenerationStore . revalidate = next . revalidate
745
- }
746
- }
747
- if ( hasNextConfig ) delete init . next
748
- }
749
-
750
611
// if we are revalidating the whole page via time or on-demand and
751
612
// the fetch cache entry is stale we should still de-dupe the
752
613
// origin hit if it's a cache-able entry
0 commit comments