Skip to content

Commit 4c624e2

Browse files
committed
simplify delay logic in patch-fetch
1 parent 1d7ebe5 commit 4c624e2

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

packages/next/errors.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,5 @@
868868
"867": "The %s \"%s\" must export a %s or a \\`default\\` function",
869869
"868": "No reference found for param: %s in reference: %s",
870870
"869": "No reference found for segment: %s with reference: %s",
871-
"870": "`pipelineInSequentialTasks` should not be called in edge runtime.",
872-
"871": "dynamicInDevStagedRendering should only be used in development mode and when Cache Components is enabled."
871+
"870": "`pipelineInSequentialTasks` should not be called in edge runtime."
873872
}

packages/next/src/server/lib/patch-fetch.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type { FetchMetric } from '../base-http'
1717
import { createDedupeFetch } from './dedupe-fetch'
1818
import {
1919
getCacheSignal,
20-
type RequestStore,
2120
type RevalidateStore,
2221
type WorkUnitAsyncStorage,
2322
} from '../app-render/work-unit-async-storage.external'
@@ -30,7 +29,6 @@ import {
3029
} from '../response-cache'
3130
import { cloneResponse } from './clone-response'
3231
import type { IncrementalCache } from './incremental-cache'
33-
import { InvariantError } from '../../shared/lib/invariant-error'
3432

3533
const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'
3634

@@ -573,7 +571,7 @@ export function createPatchedFetcher(
573571
cacheSignal = null
574572
}
575573
// TODO(restart-on-cache-miss): block dynamic when filling caches
576-
await dynamicInDevStagedRendering(workUnitStore)
574+
await getTimeoutBoundary()
577575
}
578576
break
579577
case 'prerender-ppr':
@@ -698,7 +696,7 @@ export function createPatchedFetcher(
698696
cacheSignal = null
699697
}
700698
// TODO(restart-on-cache-miss): block dynamic when filling caches
701-
await dynamicInDevStagedRendering(workUnitStore)
699+
await getTimeoutBoundary()
702700
}
703701
break
704702
case 'prerender-ppr':
@@ -968,7 +966,7 @@ export function createPatchedFetcher(
968966
process.env.NODE_ENV === 'development' &&
969967
isStagedRenderingInDev
970968
) {
971-
await dynamicInDevStagedRendering(workUnitStore)
969+
await getTimeoutBoundary()
972970
}
973971
break
974972
case 'prerender-ppr':
@@ -1089,7 +1087,7 @@ export function createPatchedFetcher(
10891087
cacheSignal = null
10901088
}
10911089
// TODO(restart-on-cache-miss): block dynamic when filling caches
1092-
await dynamicInDevStagedRendering(workUnitStore)
1090+
await getTimeoutBoundary()
10931091
}
10941092
break
10951093
case 'prerender-ppr':
@@ -1134,7 +1132,7 @@ export function createPatchedFetcher(
11341132
isStagedRenderingInDev
11351133
) {
11361134
// TODO(restart-on-cache-miss): block dynamic when filling caches
1137-
await dynamicInDevStagedRendering(workUnitStore)
1135+
await getTimeoutBoundary()
11381136
}
11391137
break
11401138
case 'cache':
@@ -1286,29 +1284,3 @@ function getTimeoutBoundary() {
12861284
}
12871285
return currentTimeoutBoundary
12881286
}
1289-
1290-
async function dynamicInDevStagedRendering(requestStore: RequestStore) {
1291-
if (
1292-
process.env.NODE_ENV === 'development' &&
1293-
process.env.__NEXT_CACHE_COMPONENTS
1294-
) {
1295-
if (requestStore.cacheSignal) {
1296-
// TODO(restart-on-cache-miss): block dynamic more effectively.
1297-
// Ideally, we'd hang here -- if the render acts as a warmup, there's no need to execute dynamic requests.
1298-
// But we can *only* hang if the render ends up being a warmup and gets discarded --
1299-
// if it's used as is, we have to resolve the fetch eventually.
1300-
// This coordination mechanism will be implemented in a follow-up,
1301-
// for now it's enough to delay.
1302-
await getTimeoutBoundary()
1303-
await getTimeoutBoundary()
1304-
} else {
1305-
// We don't have a cacheSignal, so this is the final (restarted) render.
1306-
// Don't block, but delay to prevent this from resolving in the static stage.
1307-
await getTimeoutBoundary()
1308-
}
1309-
} else {
1310-
throw new InvariantError(
1311-
'dynamicInDevStagedRendering should only be used in development mode and when Cache Components is enabled.'
1312-
)
1313-
}
1314-
}

0 commit comments

Comments
 (0)