| |
| |
| |
| |
| @@ -91,6 +91,17 @@ export function makeDynamicHangingPromise<T>( |
| ) |
| } |
| |
| +export function makeUntrackedHangingPromise<T>( |
| + signal: AbortSignal, |
| + route: string, |
| + expression: string |
| +): Promise<T> { |
| + return makeHangingPromiseWithError( |
| + signal, |
| + new HangingPromiseRejectionError(route, expression) |
| + ) |
| +} |
| + |
| /** |
| * Constructs a promise that never resolves, standing in for *runtime* data: |
| * data that hangs during a static prerender but is available during a runtime |
| |
| |
| |
| |
| @@ -42,6 +42,7 @@ import { |
| makeDynamicHangingPromise, |
| makeRuntimeHangingPromise, |
| makeStageHangingPromise, |
| + makeUntrackedHangingPromise, |
| RENDER_STAGES_BY_DATA_KIND, |
| } from '../dynamic-rendering-utils' |
| |
| @@ -1283,7 +1284,7 @@ async function generateCacheEntryImpl( |
| |
| switch (outerWorkUnitStore.type) { |
| case 'prerender-runtime': |
| - case 'prerender': |
| + case 'prerender': { |
| const timeoutAbortController = new AbortController() |
| const timer = setTimeout( |
| () => { |
| @@ -1299,7 +1300,6 @@ async function generateCacheEntryImpl( |
| const abortSignal = dynamicAccessAbortSignal |
| ? AbortSignal.any([ |
| dynamicAccessAbortSignal, |
| - outerWorkUnitStore.renderSignal, |
| timeoutAbortController.signal, |
| ]) |
| : timeoutAbortController.signal |
| @@ -1357,6 +1357,7 @@ async function generateCacheEntryImpl( |
| stream = prelude |
| } |
| break |
| + } |
| case 'request': |
| // TODO: We should just check if the render is abandonable. This is |
| // relevant in restart-on-cache-miss in general, so when we implement that |
| @@ -1640,6 +1641,51 @@ export async function cache( |
| ) |
| } |
| |
| + const workUnitStore = workUnitAsyncStorage.getStore() |
| + if (workUnitStore === undefined) { |
| + throw new InvariantError( |
| + '"use cache" cannot be used outside of App Router. Expected a WorkUnitStore.' |
| + ) |
| + } |
| + |
| + // In a prerender, tasky IO may result in cache reads that start |
| + // after the prerender has already been aborted: |
| + // |
| + // await setTimeout(100) // we can't abort this uncached IO... |
| + // await cachedData() // ...so we'll still get here even though the prerender aborted |
| + // |
| + // The prerender is over, so we should just return an erroring promise. |
| + // (NOTE: we also shouldn't fill this cache, because it's behind uncached IO, |
| + // so semantically it is not part of the prerender) |
| + switch (workUnitStore.type) { |
| + case 'prerender': |
| + case 'prerender-runtime': { |
| + if (workUnitStore.renderSignal.aborted) { |
| + // We don't know if the cache itself is dynamic or runtime data, |
| + // but the prerender is over, so it doesn't need to participate |
| + // in runtime data tracking at all. |
| + return makeUntrackedHangingPromise<never>( |
| + workUnitStore.renderSignal, |
| + workStore.route, |
| + '"use cache" called after prerender ended' |
| + ) |
| + } |
| + break |
| + } |
| + case 'prerender-ppr': |
| + case 'prerender-legacy': |
| + case 'prerender-client': |
| + case 'validation-client': |
| + case 'request': |
| + case 'cache': |
| + case 'private-cache': |
| + case 'unstable-cache': |
| + case 'generate-static-params': |
| + break |
| + default: |
| + workUnitStore satisfies never |
| + } |
| + |
| // Probe re-executions (the dev-server's hang-detection worker) short-circuit |
| // further down before any handler is consulted, so we skip handler selection |
| // entirely and the worker can boot without registering handlers at all. |
| @@ -1705,13 +1751,6 @@ export async function cache( |
| return error |
| } |
| |
| - const workUnitStore = workUnitAsyncStorage.getStore() |
| - if (workUnitStore === undefined) { |
| - throw new InvariantError( |
| - '"use cache" cannot be used outside of App Router. Expected a WorkUnitStore.' |
| - ) |
| - } |
| - |
| const outerOwnerStack = |
| process.env.NODE_ENV !== 'production' |
| ? captureOuterOwnerStack(workUnitStore) |
|
|