Commit fba4609b authored by Janka Uryga's avatar Janka Uryga

simplify delay logic in patch-fetch

parent 9da7a501
...@@ -868,6 +868,5 @@ ...@@ -868,6 +868,5 @@
"867": "The %s \"%s\" must export a %s or a \\`default\\` function", "867": "The %s \"%s\" must export a %s or a \\`default\\` function",
"868": "No reference found for param: %s in reference: %s", "868": "No reference found for param: %s in reference: %s",
"869": "No reference found for segment: %s with reference: %s", "869": "No reference found for segment: %s with reference: %s",
"870": "`pipelineInSequentialTasks` should not be called in edge runtime.", "870": "`pipelineInSequentialTasks` should not be called in edge runtime."
"871": "dynamicInDevStagedRendering should only be used in development mode and when Cache Components is enabled."
} }
...@@ -17,7 +17,6 @@ import type { FetchMetric } from '../base-http' ...@@ -17,7 +17,6 @@ import type { FetchMetric } from '../base-http'
import { createDedupeFetch } from './dedupe-fetch' import { createDedupeFetch } from './dedupe-fetch'
import { import {
getCacheSignal, getCacheSignal,
type RequestStore,
type RevalidateStore, type RevalidateStore,
type WorkUnitAsyncStorage, type WorkUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external' } from '../app-render/work-unit-async-storage.external'
...@@ -30,7 +29,6 @@ import { ...@@ -30,7 +29,6 @@ import {
} from '../response-cache' } from '../response-cache'
import { cloneResponse } from './clone-response' import { cloneResponse } from './clone-response'
import type { IncrementalCache } from './incremental-cache' import type { IncrementalCache } from './incremental-cache'
import { InvariantError } from '../../shared/lib/invariant-error'
const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge' const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'
...@@ -573,7 +571,7 @@ export function createPatchedFetcher( ...@@ -573,7 +571,7 @@ export function createPatchedFetcher(
cacheSignal = null cacheSignal = null
} }
// TODO(restart-on-cache-miss): block dynamic when filling caches // TODO(restart-on-cache-miss): block dynamic when filling caches
await dynamicInDevStagedRendering(workUnitStore) await getTimeoutBoundary()
} }
break break
case 'prerender-ppr': case 'prerender-ppr':
...@@ -698,7 +696,7 @@ export function createPatchedFetcher( ...@@ -698,7 +696,7 @@ export function createPatchedFetcher(
cacheSignal = null cacheSignal = null
} }
// TODO(restart-on-cache-miss): block dynamic when filling caches // TODO(restart-on-cache-miss): block dynamic when filling caches
await dynamicInDevStagedRendering(workUnitStore) await getTimeoutBoundary()
} }
break break
case 'prerender-ppr': case 'prerender-ppr':
...@@ -968,7 +966,7 @@ export function createPatchedFetcher( ...@@ -968,7 +966,7 @@ export function createPatchedFetcher(
process.env.NODE_ENV === 'development' && process.env.NODE_ENV === 'development' &&
isStagedRenderingInDev isStagedRenderingInDev
) { ) {
await dynamicInDevStagedRendering(workUnitStore) await getTimeoutBoundary()
} }
break break
case 'prerender-ppr': case 'prerender-ppr':
...@@ -1089,7 +1087,7 @@ export function createPatchedFetcher( ...@@ -1089,7 +1087,7 @@ export function createPatchedFetcher(
cacheSignal = null cacheSignal = null
} }
// TODO(restart-on-cache-miss): block dynamic when filling caches // TODO(restart-on-cache-miss): block dynamic when filling caches
await dynamicInDevStagedRendering(workUnitStore) await getTimeoutBoundary()
} }
break break
case 'prerender-ppr': case 'prerender-ppr':
...@@ -1134,7 +1132,7 @@ export function createPatchedFetcher( ...@@ -1134,7 +1132,7 @@ export function createPatchedFetcher(
isStagedRenderingInDev isStagedRenderingInDev
) { ) {
// TODO(restart-on-cache-miss): block dynamic when filling caches // TODO(restart-on-cache-miss): block dynamic when filling caches
await dynamicInDevStagedRendering(workUnitStore) await getTimeoutBoundary()
} }
break break
case 'cache': case 'cache':
...@@ -1286,29 +1284,3 @@ function getTimeoutBoundary() { ...@@ -1286,29 +1284,3 @@ function getTimeoutBoundary() {
} }
return currentTimeoutBoundary return currentTimeoutBoundary
} }
async function dynamicInDevStagedRendering(requestStore: RequestStore) {
if (
process.env.NODE_ENV === 'development' &&
process.env.__NEXT_CACHE_COMPONENTS
) {
if (requestStore.cacheSignal) {
// TODO(restart-on-cache-miss): block dynamic more effectively.
// Ideally, we'd hang here -- if the render acts as a warmup, there's no need to execute dynamic requests.
// But we can *only* hang if the render ends up being a warmup and gets discarded --
// if it's used as is, we have to resolve the fetch eventually.
// This coordination mechanism will be implemented in a follow-up,
// for now it's enough to delay.
await getTimeoutBoundary()
await getTimeoutBoundary()
} else {
// We don't have a cacheSignal, so this is the final (restarted) render.
// Don't block, but delay to prevent this from resolving in the static stage.
await getTimeoutBoundary()
}
} else {
throw new InvariantError(
'dynamicInDevStagedRendering should only be used in development mode and when Cache Components is enabled.'
)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment