Unverified Commit 30e6794b authored by Josh Story's avatar Josh Story Committed by GitHub

Refactor prerender workUnitStores (#70986)

This continues the refactor by adding an explicit type for PPR without
dynamicIO. It gets rid of `isDynamicIOPrerender` helper in favor or just
using a new discriminated type. It narrows the function arguments where
possible. dynamicIO prerenders encompass both PPR and non-PPR since
prerendering semnatics aren't different even when PPR is enabled. It
also sets up passing an AbortSignal into the dynamicIO prerender stores.
We don't use it yet but we will end up relying on it to clean up hanging
promises after the render is complete
parent a2d8421a
...@@ -923,7 +923,9 @@ async function renderToHTMLOrFlightImpl( ...@@ -923,7 +923,9 @@ async function renderToHTMLOrFlightImpl(
const staticGenStore = ComponentMod.workAsyncStorage.getStore() const staticGenStore = ComponentMod.workAsyncStorage.getStore()
const prerenderStore = workUnitAsyncStorage.getStore() const prerenderStore = workUnitAsyncStorage.getStore()
const isPPR = const isPPR =
prerenderStore && prerenderStore.type === 'prerender' prerenderStore &&
(prerenderStore.type === 'prerender' ||
prerenderStore.type === 'prerender-ppr')
? !!prerenderStore.dynamicTracking?.dynamicAccesses?.length ? !!prerenderStore.dynamicTracking?.dynamicAccesses?.length
: false : false
...@@ -1854,10 +1856,13 @@ async function prerenderToStream( ...@@ -1854,10 +1856,13 @@ async function prerenderToStream(
const PRERENDER_COMPLETE = 'NEXT_PRERENDER_COMPLETE' const PRERENDER_COMPLETE = 'NEXT_PRERENDER_COMPLETE'
const abortReason = new Error(PRERENDER_COMPLETE) const abortReason = new Error(PRERENDER_COMPLETE)
let flightController = new AbortController()
const cacheSignal = new CacheSignal() const cacheSignal = new CacheSignal()
const prospectiveRenderPrerenderStore: PrerenderStore = { const prospectiveRenderPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: flightController.signal,
cacheSignal, cacheSignal,
// During the prospective render we don't want to synchronously abort on dynamic access // During the prospective render we don't want to synchronously abort on dynamic access
// because it could prevent us from discovering all caches in siblings. So we omit the controller // because it could prevent us from discovering all caches in siblings. So we omit the controller
...@@ -1869,8 +1874,6 @@ async function prerenderToStream( ...@@ -1869,8 +1874,6 @@ async function prerenderToStream(
dynamicTracking: null, dynamicTracking: null,
} }
let flightController = new AbortController()
let reactServerIsDynamic = false let reactServerIsDynamic = false
function onError(err: unknown) { function onError(err: unknown) {
if (err === abortReason) { if (err === abortReason) {
...@@ -1950,6 +1953,7 @@ async function prerenderToStream( ...@@ -1950,6 +1953,7 @@ async function prerenderToStream(
const finalRenderPrerenderStore: PrerenderStore = { const finalRenderPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: flightController.signal,
// During the final prerender we don't need to track cache access so we omit the signal // During the final prerender we don't need to track cache access so we omit the signal
cacheSignal: null, cacheSignal: null,
// During the final render we do want to abort synchronously on dynamic access so we // During the final render we do want to abort synchronously on dynamic access so we
...@@ -2006,6 +2010,7 @@ async function prerenderToStream( ...@@ -2006,6 +2010,7 @@ async function prerenderToStream(
const ssrPrerenderStore: PrerenderStore = { const ssrPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: SSRController.signal,
// For HTML Generation we don't need to track cache reads (RSC only) // For HTML Generation we don't need to track cache reads (RSC only)
cacheSignal: null, cacheSignal: null,
// We expect the SSR render to complete in a single Task and need to be able to synchronously abort // We expect the SSR render to complete in a single Task and need to be able to synchronously abort
...@@ -2211,6 +2216,7 @@ async function prerenderToStream( ...@@ -2211,6 +2216,7 @@ async function prerenderToStream(
const prospectiveRenderPrerenderStore: PrerenderStore = { const prospectiveRenderPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: flightController.signal,
cacheSignal, cacheSignal,
// When PPR is off we can synchronously abort the prospective render because we will // When PPR is off we can synchronously abort the prospective render because we will
// always hit this path on the final render and thus we can skip the final render and just // always hit this path on the final render and thus we can skip the final render and just
...@@ -2290,6 +2296,7 @@ async function prerenderToStream( ...@@ -2290,6 +2296,7 @@ async function prerenderToStream(
const finalRenderPrerenderStore: PrerenderStore = { const finalRenderPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: flightController.signal,
// During the final prerender we don't need to track cache access so we omit the signal // During the final prerender we don't need to track cache access so we omit the signal
cacheSignal: null, cacheSignal: null,
controller: flightController, controller: flightController,
...@@ -2300,6 +2307,7 @@ async function prerenderToStream( ...@@ -2300,6 +2307,7 @@ async function prerenderToStream(
const ssrPrerenderStore: PrerenderStore = { const ssrPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
renderSignal: SSRController.signal,
// For HTML Generation we don't need to track cache reads (RSC only) // For HTML Generation we don't need to track cache reads (RSC only)
cacheSignal: null, cacheSignal: null,
// We expect the SSR render to complete in a single Task and need to be able to synchronously abort // We expect the SSR render to complete in a single Task and need to be able to synchronously abort
...@@ -2479,10 +2487,8 @@ async function prerenderToStream( ...@@ -2479,10 +2487,8 @@ async function prerenderToStream(
renderOpts.isDebugDynamicAccesses renderOpts.isDebugDynamicAccesses
) )
const reactServerPrerenderStore: PrerenderStore = { const reactServerPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender-ppr',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
cacheSignal: null,
controller: null,
dynamicTracking, dynamicTracking,
} }
const RSCPayload = await workUnitAsyncStorage.run( const RSCPayload = await workUnitAsyncStorage.run(
...@@ -2507,10 +2513,8 @@ async function prerenderToStream( ...@@ -2507,10 +2513,8 @@ async function prerenderToStream(
)) ))
const ssrPrerenderStore: PrerenderStore = { const ssrPrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender-ppr',
pathname: ctx.requestStore.url.pathname, pathname: ctx.requestStore.url.pathname,
cacheSignal: null,
controller: null,
dynamicTracking, dynamicTracking,
} }
...@@ -2693,7 +2697,9 @@ async function prerenderToStream( ...@@ -2693,7 +2697,9 @@ async function prerenderToStream(
const renderToReadableStream = require('react-dom/server.edge') const renderToReadableStream = require('react-dom/server.edge')
.renderToReadableStream as (typeof import('react-dom/server.edge'))['renderToReadableStream'] .renderToReadableStream as (typeof import('react-dom/server.edge'))['renderToReadableStream']
const htmlStream = await renderToReadableStream( const htmlStream = await workUnitAsyncStorage.run(
prerenderLegacyStore,
renderToReadableStream,
<App <App
reactServerStream={reactServerResult.asUnclosingStream()} reactServerStream={reactServerResult.asUnclosingStream()}
preinitScripts={preinitScripts} preinitScripts={preinitScripts}
...@@ -2813,9 +2819,21 @@ async function prerenderToStream( ...@@ -2813,9 +2819,21 @@ async function prerenderToStream(
'/_not-found/page' '/_not-found/page'
) )
const errorRSCPayload = await getErrorRSCPayload(tree, ctx, errorType) const prerenderLegacyStore: PrerenderStore = {
type: 'prerender-legacy',
pathname: ctx.requestStore.url.pathname,
}
const errorRSCPayload = await workUnitAsyncStorage.run(
prerenderLegacyStore,
getErrorRSCPayload,
tree,
ctx,
errorType
)
const errorServerStream = ComponentMod.renderToReadableStream( const errorServerStream = workUnitAsyncStorage.run(
prerenderLegacyStore,
ComponentMod.renderToReadableStream,
errorRSCPayload, errorRSCPayload,
clientReferenceManifest.clientModules, clientReferenceManifest.clientModules,
{ {
......
...@@ -29,8 +29,8 @@ import React from 'react' ...@@ -29,8 +29,8 @@ import React from 'react'
import { DynamicServerError } from '../../client/components/hooks-server-context' import { DynamicServerError } from '../../client/components/hooks-server-context'
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout' import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'
import { import {
isDynamicIOPrerender,
workUnitAsyncStorage, workUnitAsyncStorage,
type PrerenderStoreLegacy,
type PrerenderStoreModern, type PrerenderStoreModern,
} from './work-unit-async-storage.external' } from './work-unit-async-storage.external'
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { workAsyncStorage } from '../../client/components/work-async-storage.external'
...@@ -142,9 +142,8 @@ export function markCurrentScopeAsDynamic( ...@@ -142,9 +142,8 @@ export function markCurrentScopeAsDynamic(
) )
} }
const prerenderStore = workUnitAsyncStorage.getStore() if (workUnitStore) {
if (prerenderStore && prerenderStore.type === 'prerender') { if (workUnitStore.type === 'prerender') {
if (isDynamicIOPrerender(prerenderStore)) {
// We're prerendering the RSC stream with dynamicIO enabled and we need to abort the // We're prerendering the RSC stream with dynamicIO enabled and we need to abort the
// current render because something dynamic is being used. // current render because something dynamic is being used.
// This won't throw so we still need to fall through to determine if/how we handle // This won't throw so we still need to fall through to determine if/how we handle
...@@ -152,19 +151,17 @@ export function markCurrentScopeAsDynamic( ...@@ -152,19 +151,17 @@ export function markCurrentScopeAsDynamic(
abortAndThrowOnSynchronousDynamicDataAccess( abortAndThrowOnSynchronousDynamicDataAccess(
store.route, store.route,
expression, expression,
prerenderStore workUnitStore
) )
} else { } else if (workUnitStore.type === 'prerender-ppr') {
postponeWithTracking( postponeWithTracking(
store.route, store.route,
expression, expression,
prerenderStore.dynamicTracking workUnitStore.dynamicTracking
) )
} } else if (workUnitStore.type === 'prerender-legacy') {
} else { store.revalidate = 0
store.revalidate = 0
if (store.isStaticGeneration) {
// We aren't prerendering but we are generating a static page. We need to bail out of static generation // We aren't prerendering but we are generating a static page. We need to bail out of static generation
const err = new DynamicServerError( const err = new DynamicServerError(
`Route ${store.route} couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/messages/dynamic-server-error` `Route ${store.route} couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
...@@ -174,7 +171,9 @@ export function markCurrentScopeAsDynamic( ...@@ -174,7 +171,9 @@ export function markCurrentScopeAsDynamic(
throw err throw err
} }
// We fall through in all other cases to just tracking that something dynamic happened on the work store
} }
store.revalidate = 0
} }
/** /**
...@@ -190,7 +189,7 @@ export function trackFallbackParamAccessed( ...@@ -190,7 +189,7 @@ export function trackFallbackParamAccessed(
expression: string expression: string
): void { ): void {
const prerenderStore = workUnitAsyncStorage.getStore() const prerenderStore = workUnitAsyncStorage.getStore()
if (!prerenderStore || prerenderStore.type !== 'prerender') return if (!prerenderStore || prerenderStore.type !== 'prerender-ppr') return
postponeWithTracking(store.route, expression, prerenderStore.dynamicTracking) postponeWithTracking(store.route, expression, prerenderStore.dynamicTracking)
} }
...@@ -220,36 +219,32 @@ export function trackDynamicDataAccessed( ...@@ -220,36 +219,32 @@ export function trackDynamicDataAccessed(
) )
} }
} }
if (store.dynamicShouldError) { if (store.dynamicShouldError) {
throw new StaticGenBailoutError( throw new StaticGenBailoutError(
`Route ${store.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering` `Route ${store.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`
) )
} }
const prerenderStore = workUnitAsyncStorage.getStore() if (workUnitStore) {
if (prerenderStore && prerenderStore.type === 'prerender') { if (workUnitStore.type === 'prerender') {
if (isDynamicIOPrerender(prerenderStore)) { // dynamicIO Prerender
// We're prerendering the RSC stream with dynamicIO enabled and we need to abort the
// current render because something dynamic is being used.
// This won't throw so we still need to fall through to determine if/how we handle
// this specific dynamic request.
abortAndThrowOnSynchronousDynamicDataAccess( abortAndThrowOnSynchronousDynamicDataAccess(
store.route, store.route,
expression, expression,
prerenderStore workUnitStore
) )
} else { } else if (workUnitStore.type === 'prerender-ppr') {
// PPR Prerender
postponeWithTracking( postponeWithTracking(
store.route, store.route,
expression, expression,
prerenderStore.dynamicTracking workUnitStore.dynamicTracking
) )
} } else if (workUnitStore.type === 'prerender-legacy') {
} else { // legacy Prerender
store.revalidate = 0 store.revalidate = 0
if (store.isStaticGeneration) {
// We aren't prerendering but we are generating a static page. We need to bail out of static generation
const err = new DynamicServerError( const err = new DynamicServerError(
`Route ${store.route} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error` `Route ${store.route} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
) )
...@@ -258,6 +253,8 @@ export function trackDynamicDataAccessed( ...@@ -258,6 +253,8 @@ export function trackDynamicDataAccessed(
throw err throw err
} }
} else {
store.revalidate = 0
} }
} }
...@@ -270,25 +267,15 @@ export function trackDynamicDataAccessed( ...@@ -270,25 +267,15 @@ export function trackDynamicDataAccessed(
export function throwToInterruptStaticGeneration( export function throwToInterruptStaticGeneration(
expression: string, expression: string,
store: WorkStore, store: WorkStore,
workUnitStore: undefined | WorkUnitStore // We don't actually use this store but making it part of the function signature enforces
// that it is only called in contexts where we are in fact performing a legacy prerender
_prerenderStore: PrerenderStoreLegacy
): never { ): never {
// We aren't prerendering but we are generating a static page. We need to bail out of static generation // We aren't prerendering but we are generating a static page. We need to bail out of static generation
const err = new DynamicServerError( const err = new DynamicServerError(
`Route ${store.route} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error` `Route ${store.route} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
) )
if (workUnitStore) {
if (
workUnitStore.type === 'cache' ||
workUnitStore.type === 'unstable-cache'
) {
// inside cache scopes marking a scope as dynamic has no effect because the outer cache scope
// creates a cache boundary. This is subtly different from reading a dynamic data source which is
// forbidden inside a cache scope.
throw err
}
}
store.revalidate = 0 store.revalidate = 0
store.dynamicUsageDescription = expression store.dynamicUsageDescription = expression
...@@ -390,7 +377,7 @@ type PostponeProps = { ...@@ -390,7 +377,7 @@ type PostponeProps = {
export function Postpone({ reason, route }: PostponeProps): never { export function Postpone({ reason, route }: PostponeProps): never {
const prerenderStore = workUnitAsyncStorage.getStore() const prerenderStore = workUnitAsyncStorage.getStore()
const dynamicTracking = const dynamicTracking =
prerenderStore && prerenderStore.type === 'prerender' prerenderStore && prerenderStore.type === 'prerender-ppr'
? prerenderStore.dynamicTracking ? prerenderStore.dynamicTracking
: null : null
postponeWithTracking(route, reason, dynamicTracking) postponeWithTracking(route, reason, dynamicTracking)
...@@ -576,26 +563,24 @@ export function useDynamicRouteParams(expression: string) { ...@@ -576,26 +563,24 @@ export function useDynamicRouteParams(expression: string) {
) { ) {
// There are fallback route params, we should track these as dynamic // There are fallback route params, we should track these as dynamic
// accesses. // accesses.
const prerenderStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
if (prerenderStore && prerenderStore.type === 'prerender') { if (workUnitStore) {
// We're prerendering with dynamicIO or PPR or both // We're prerendering with dynamicIO or PPR or both
if (isDynamicIOPrerender(prerenderStore)) { if (workUnitStore.type === 'prerender') {
// We are in a prerender with dynamicIO semantics // We are in a prerender with dynamicIO semantics
// We are going to hang here and never resolve. This will cause the currently // We are going to hang here and never resolve. This will cause the currently
// rendering component to effectively be a dynamic hole // rendering component to effectively be a dynamic hole
React.use(makeHangingPromise()) React.use(makeHangingPromise())
} else { } else if (workUnitStore.type === 'prerender-ppr') {
// We're prerendering with PPR // We're prerendering with PPR
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking workUnitStore.dynamicTracking
) )
} else if (workUnitStore.type === 'prerender-legacy') {
throwToInterruptStaticGeneration(expression, workStore, workUnitStore)
} }
} else {
// We're prerendering in legacy mode
const workUnitStore = workUnitAsyncStorage.getStore()
throwToInterruptStaticGeneration(expression, workStore, workUnitStore)
} }
} }
} }
......
...@@ -63,25 +63,32 @@ export type PrerenderStoreModern = { ...@@ -63,25 +63,32 @@ export type PrerenderStoreModern = {
*/ */
readonly cacheSignal: null | CacheSignal readonly cacheSignal: null | CacheSignal
/**
* This signal is used to clean up the prerender once it is complete.
*/
readonly renderSignal: AbortSignal
/** /**
* During some prerenders we want to track dynamic access. * During some prerenders we want to track dynamic access.
*/ */
readonly dynamicTracking: null | DynamicTrackingState readonly dynamicTracking: null | DynamicTrackingState
} }
export type PrerenderStorePPR = {
type: 'prerender-ppr'
pathname: string | undefined
readonly dynamicTracking: null | DynamicTrackingState
}
export type PrerenderStoreLegacy = { export type PrerenderStoreLegacy = {
type: 'prerender-legacy' type: 'prerender-legacy'
pathname: string | undefined pathname: string | undefined
} }
export type PrerenderStore = PrerenderStoreLegacy | PrerenderStoreModern export type PrerenderStore =
| PrerenderStoreLegacy
export function isDynamicIOPrerender(workUnitStore: WorkUnitStore): boolean { | PrerenderStorePPR
return ( | PrerenderStoreModern
workUnitStore.type === 'prerender' &&
!!(workUnitStore.controller || workUnitStore.cacheSignal)
)
}
export type UseCacheStore = { export type UseCacheStore = {
type: 'cache' type: 'cache'
...@@ -114,6 +121,7 @@ export function getExpectedRequestStore( ...@@ -114,6 +121,7 @@ export function getExpectedRequestStore(
} }
if ( if (
workUnitStore.type === 'prerender' || workUnitStore.type === 'prerender' ||
workUnitStore.type === 'prerender-ppr' ||
workUnitStore.type === 'prerender-legacy' workUnitStore.type === 'prerender-legacy'
) { ) {
// This should not happen because we should have checked it already. // This should not happen because we should have checked it already.
......
...@@ -175,6 +175,7 @@ export function addImplicitTags( ...@@ -175,6 +175,7 @@ export function addImplicitTags(
? workUnitStore.type === 'request' ? workUnitStore.type === 'request'
? workUnitStore.url.pathname ? workUnitStore.url.pathname
: workUnitStore.type === 'prerender' || : workUnitStore.type === 'prerender' ||
workUnitStore.type === 'prerender-ppr' ||
workUnitStore.type === 'prerender-legacy' workUnitStore.type === 'prerender-legacy'
? workUnitStore.pathname ? workUnitStore.pathname
: undefined : undefined
...@@ -642,7 +643,7 @@ export function createPatchedFetcher( ...@@ -642,7 +643,7 @@ export function createPatchedFetcher(
(isCacheableRevalidate || requestStore?.serverComponentsHmrCache) (isCacheableRevalidate || requestStore?.serverComponentsHmrCache)
) { ) {
if (workUnitStore && workUnitStore.type === 'prerender') { if (workUnitStore && workUnitStore.type === 'prerender') {
// We are prerendering at build time or revalidate time so we need to // We are prerendering at build time or revalidate time with dynamicIO so we need to
// buffer the response so we can guarantee it can be read in a microtask // buffer the response so we can guarantee it can be read in a microtask
const bodyBuffer = await res.arrayBuffer() const bodyBuffer = await res.arrayBuffer()
......
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import { import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external'
isDynamicIOPrerender,
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import { abortOnSynchronousDynamicDataAccess } from '../app-render/dynamic-rendering' import { abortOnSynchronousDynamicDataAccess } from '../app-render/dynamic-rendering'
export function io(expression: string) { export function io(expression: string) {
const workUnitStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
if ( if (workUnitStore && workUnitStore.type === 'prerender') {
workUnitStore &&
workUnitStore.type === 'prerender' &&
isDynamicIOPrerender(workUnitStore)
) {
const workStore = workAsyncStorage.getStore() const workStore = workAsyncStorage.getStore()
const route = workStore ? workStore.route : '' const route = workStore ? workStore.route : ''
if (workStore) { if (workStore) {
......
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import { import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external'
isDynamicIOPrerender,
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import { import {
postponeWithTracking, postponeWithTracking,
throwToInterruptStaticGeneration, throwToInterruptStaticGeneration,
...@@ -44,31 +41,24 @@ export function connection(): Promise<void> { ...@@ -44,31 +41,24 @@ export function connection(): Promise<void> {
) )
} }
if (workUnitStore && workUnitStore.type === 'prerender') { if (workUnitStore) {
// We are in PPR and/or dynamicIO mode and prerendering if (workUnitStore.type === 'prerender') {
// dynamicIO Prerender
if (isDynamicIOPrerender(workUnitStore)) { // We return a promise that never resolves to allow the prender to stall at this point
// We use the controller and cacheSignal as an indication we are in dynamicIO mode.
// When resolving headers for a prerender with dynamic IO we return a forever promise
// along with property access tracked synchronous headers.
// We don't track dynamic access here because access will be tracked when you access
// one of the properties of the headers object.
return makeHangingPromise() return makeHangingPromise()
} else { } else if (workUnitStore.type === 'prerender-ppr') {
// We are prerendering with PPR. We need track dynamic access here eagerly // PPR Prerender (no dynamicIO)
// to keep continuity with how headers has worked in PPR without dynamicIO. // We use React's postpone API to interrupt rendering here to create a dynamic hole
// TODO consider switching the semantic to throw on property access intead
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
'connection', 'connection',
workUnitStore.dynamicTracking workUnitStore.dynamicTracking
) )
} else if (workUnitStore.type === 'prerender-legacy') {
// Legacy Prerender
// We throw an error here to interrupt prerendering to mark the route as dynamic
throwToInterruptStaticGeneration('connection', workStore, workUnitStore)
} }
} else if (workStore.isStaticGeneration) {
// We are in a legacy static generation mode while prerendering
// We treat this function call as a bailout of static generation
throwToInterruptStaticGeneration('connection', workStore, workUnitStore)
} }
// We fall through to the dynamic context below but we still track dynamic access // We fall through to the dynamic context below but we still track dynamic access
// because in dev we can still error for things like using headers inside a cache context // because in dev we can still error for things like using headers inside a cache context
......
...@@ -6,7 +6,6 @@ import { ...@@ -6,7 +6,6 @@ import {
import { RequestCookies } from '../../server/web/spec-extension/cookies' import { RequestCookies } from '../../server/web/spec-extension/cookies'
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import { import {
isDynamicIOPrerender,
workUnitAsyncStorage, workUnitAsyncStorage,
type PrerenderStoreModern, type PrerenderStoreModern,
} from '../app-render/work-unit-async-storage.external' } from '../app-render/work-unit-async-storage.external'
...@@ -81,31 +80,24 @@ export function cookies(): Promise<ReadonlyRequestCookies> { ...@@ -81,31 +80,24 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
if (workUnitStore) { if (workUnitStore) {
if (workUnitStore.type === 'prerender') { if (workUnitStore.type === 'prerender') {
// We are in PPR and/or dynamicIO mode and prerendering // dynamicIO Prerender
// We don't track dynamic access here because access will be tracked when you access
if (isDynamicIOPrerender(workUnitStore)) { // one of the properties of the cookies object.
// We use the controller and cacheSignal as an indication we are in dynamicIO mode. return makeDynamicallyTrackedExoticCookies(
// When resolving cookies for a prerender with dynamic IO we return a forever promise workStore.route,
// along with property access tracked synchronous cookies. workUnitStore
)
// We don't track dynamic access here because access will be tracked when you access } else if (workUnitStore.type === 'prerender-ppr') {
// one of the properties of the cookies object. // PPR Prerender (no dynamicIO)
return makeDynamicallyTrackedExoticCookies( // We are prerendering with PPR. We need track dynamic access here eagerly
workStore.route, // to keep continuity with how cookies has worked in PPR without dynamicIO.
workUnitStore postponeWithTracking(
) workStore.route,
} else { callingExpression,
// We are prerendering with PPR. We need track dynamic access here eagerly workUnitStore.dynamicTracking
// to keep continuity with how cookies has worked in PPR without dynamicIO. )
// TODO consider switching the semantic to throw on property access instead
postponeWithTracking(
workStore.route,
callingExpression,
workUnitStore.dynamicTracking
)
}
} else if (workUnitStore.type === 'prerender-legacy') { } else if (workUnitStore.type === 'prerender-legacy') {
// We are in a legacy static generation mode while prerendering // Legacy Prerender
// We track dynamic access here so we don't need to wrap the cookies in // We track dynamic access here so we don't need to wrap the cookies in
// individual property access tracking. // individual property access tracking.
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
......
...@@ -43,6 +43,7 @@ export function draftMode(): Promise<DraftMode> { ...@@ -43,6 +43,7 @@ export function draftMode(): Promise<DraftMode> {
(workUnitStore.type === 'cache' || (workUnitStore.type === 'cache' ||
workUnitStore.type === 'unstable-cache' || workUnitStore.type === 'unstable-cache' ||
workUnitStore.type === 'prerender' || workUnitStore.type === 'prerender' ||
workUnitStore.type === 'prerender-ppr' ||
workUnitStore.type === 'prerender-legacy') workUnitStore.type === 'prerender-legacy')
) { ) {
// Return empty draft mode // Return empty draft mode
......
...@@ -5,7 +5,6 @@ import { ...@@ -5,7 +5,6 @@ import {
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import { getExpectedRequestStore } from '../app-render/work-unit-async-storage.external' import { getExpectedRequestStore } from '../app-render/work-unit-async-storage.external'
import { import {
isDynamicIOPrerender,
workUnitAsyncStorage, workUnitAsyncStorage,
type PrerenderStoreModern, type PrerenderStoreModern,
} from '../app-render/work-unit-async-storage.external' } from '../app-render/work-unit-async-storage.external'
...@@ -86,30 +85,25 @@ export function headers(): Promise<ReadonlyHeaders> { ...@@ -86,30 +85,25 @@ export function headers(): Promise<ReadonlyHeaders> {
if (workUnitStore) { if (workUnitStore) {
if (workUnitStore.type === 'prerender') { if (workUnitStore.type === 'prerender') {
// We are in PPR and/or dynamicIO mode and prerendering // dynamicIO Prerender
// We don't track dynamic access here because access will be tracked when you access
if (isDynamicIOPrerender(workUnitStore)) { // one of the properties of the headers object.
// We use the controller and cacheSignal as an indication we are in dynamicIO mode. return makeDynamicallyTrackedExoticHeaders(
// When resolving headers for a prerender with dynamic IO we return a forever promise workStore.route,
// along with property access tracked synchronous headers. workUnitStore
)
// We don't track dynamic access here because access will be tracked when you access } else if (workUnitStore.type === 'prerender-ppr') {
// one of the properties of the headers object. // PPR Prerender (no dynamicIO)
return makeDynamicallyTrackedExoticHeaders( // We are prerendering with PPR. We need track dynamic access here eagerly
workStore.route, // to keep continuity with how headers has worked in PPR without dynamicIO.
workUnitStore // TODO consider switching the semantic to throw on property access instead
) postponeWithTracking(
} else { workStore.route,
// We are prerendering with PPR. We need track dynamic access here eagerly 'headers',
// to keep continuity with how headers has worked in PPR without dynamicIO. workUnitStore.dynamicTracking
// TODO consider switching the semantic to throw on property access instead )
postponeWithTracking(
workStore.route,
'headers',
workUnitStore.dynamicTracking
)
}
} else if (workUnitStore.type === 'prerender-legacy') { } else if (workUnitStore.type === 'prerender-legacy') {
// Legacy Prerender
// We are in a legacy static generation mode while prerendering // We are in a legacy static generation mode while prerendering
// We track dynamic access here so we don't need to wrap the headers in // We track dynamic access here so we don't need to wrap the headers in
// individual property access tracking. // individual property access tracking.
......
...@@ -9,9 +9,9 @@ import { ...@@ -9,9 +9,9 @@ import {
} from '../app-render/dynamic-rendering' } from '../app-render/dynamic-rendering'
import { import {
isDynamicIOPrerender,
workUnitAsyncStorage, workUnitAsyncStorage,
type WorkUnitStore, type PrerenderStorePPR,
type PrerenderStoreLegacy,
type PrerenderStoreModern, type PrerenderStoreModern,
} from '../app-render/work-unit-async-storage.external' } from '../app-render/work-unit-async-storage.external'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
...@@ -96,16 +96,14 @@ export function createPrerenderParamsForClientSegment( ...@@ -96,16 +96,14 @@ export function createPrerenderParamsForClientSegment(
): Promise<Params> { ): Promise<Params> {
const prerenderStore = workUnitAsyncStorage.getStore() const prerenderStore = workUnitAsyncStorage.getStore()
if (prerenderStore && prerenderStore.type === 'prerender') { if (prerenderStore && prerenderStore.type === 'prerender') {
if (isDynamicIOPrerender(prerenderStore)) { const fallbackParams = workStore.fallbackRouteParams
const fallbackParams = workStore.fallbackRouteParams if (fallbackParams) {
if (fallbackParams) { for (let key in underlyingParams) {
for (let key in underlyingParams) { if (fallbackParams.has(key)) {
if (fallbackParams.has(key)) { // This params object has one of more fallback params so we need to consider
// This params object has one of more fallback params so we need to consider // the awaiting of this params object "dynamic". Since we are in dynamicIO mode
// the awaiting of this params object "dynamic". Since we are in dynamicIO mode // we encode this as a promise that never resolves
// we encode this as a promise that never resolves return makeHangingPromise()
return makeHangingPromise()
}
} }
} }
} }
...@@ -132,25 +130,31 @@ function createPrerenderParams( ...@@ -132,25 +130,31 @@ function createPrerenderParams(
if (hasSomeFallbackParams) { if (hasSomeFallbackParams) {
// params need to be treated as dynamic because we have at least one fallback param // params need to be treated as dynamic because we have at least one fallback param
const prerenderStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
if (prerenderStore && prerenderStore.type === 'prerender') { if (workUnitStore) {
if (isDynamicIOPrerender(prerenderStore)) { if (workUnitStore.type === 'prerender') {
// We are in a dynamicIO (PPR or otherwise) prerender // We are in a dynamicIO (PPR or otherwise) prerender
return makeAbortingExoticParams( return makeAbortingExoticParams(
underlyingParams, underlyingParams,
workStore.route, workStore.route,
prerenderStore workUnitStore
)
} else if (
workUnitStore.type === 'prerender-legacy' ||
workUnitStore.type === 'prerender-ppr'
)
// We aren't in a dynamicIO prerender but we do have fallback params at this
// level so we need to make an erroring exotic params object which will postpone
// if you access the fallback params
return makeErroringExoticParams(
underlyingParams,
fallbackParams,
workStore,
workUnitStore
) )
}
} }
// We aren't in a dynamicIO prerender but we do have fallback params at this throw new InvariantError(
// level so we need to make an erroring exotic params object which will postpone 'createPrerenderParams called without a prerenderStore in scope. This is a bug in Next.js'
// if you access the fallback params
return makeErroringExoticParams(
underlyingParams,
fallbackParams,
workStore,
prerenderStore
) )
} }
} }
...@@ -249,7 +253,7 @@ function makeErroringExoticParams( ...@@ -249,7 +253,7 @@ function makeErroringExoticParams(
underlyingParams: Params, underlyingParams: Params,
fallbackParams: FallbackRouteParams, fallbackParams: FallbackRouteParams,
workStore: WorkStore, workStore: WorkStore,
prerenderStore: undefined | WorkUnitStore prerenderStore: PrerenderStorePPR | PrerenderStoreLegacy
): Promise<Params> { ): Promise<Params> {
const cachedParams = CachedParams.get(underlyingParams) const cachedParams = CachedParams.get(underlyingParams)
if (cachedParams) { if (cachedParams) {
...@@ -304,17 +308,19 @@ function makeErroringExoticParams( ...@@ -304,17 +308,19 @@ function makeErroringExoticParams(
// fallback shells // fallback shells
// TODO remove this comment when dynamicIO is the default since there // TODO remove this comment when dynamicIO is the default since there
// will be no `dynamic = "error"` // will be no `dynamic = "error"`
if (prerenderStore && prerenderStore.type === 'prerender') { if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
// Legacy Prerender
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
expression, expression,
workStore, workStore,
undefined prerenderStore
) )
} }
}, },
...@@ -329,17 +335,19 @@ function makeErroringExoticParams( ...@@ -329,17 +335,19 @@ function makeErroringExoticParams(
// fallback shells // fallback shells
// TODO remove this comment when dynamicIO is the default since there // TODO remove this comment when dynamicIO is the default since there
// will be no `dynamic = "error"` // will be no `dynamic = "error"`
if (prerenderStore && prerenderStore.type === 'prerender') { if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
// Legacy Prerender
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
expression, expression,
workStore, workStore,
undefined prerenderStore
) )
} }
}, },
......
...@@ -10,9 +10,9 @@ import { ...@@ -10,9 +10,9 @@ import {
} from '../app-render/dynamic-rendering' } from '../app-render/dynamic-rendering'
import { import {
isDynamicIOPrerender,
workUnitAsyncStorage, workUnitAsyncStorage,
type WorkUnitStore, type PrerenderStoreLegacy,
type PrerenderStorePPR,
type PrerenderStoreModern, type PrerenderStoreModern,
} from '../app-render/work-unit-async-storage.external' } from '../app-render/work-unit-async-storage.external'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
...@@ -90,12 +90,11 @@ export function createPrerenderSearchParamsForClientPage( ...@@ -90,12 +90,11 @@ export function createPrerenderSearchParamsForClientPage(
} }
const prerenderStore = workUnitAsyncStorage.getStore() const prerenderStore = workUnitAsyncStorage.getStore()
if (prerenderStore) { if (prerenderStore && prerenderStore.type === 'prerender') {
if (isDynamicIOPrerender(prerenderStore)) { // dynamicIO Prerender
// We're prerendering in a mode that aborts (dynamicIO) and should stall // We're prerendering in a mode that aborts (dynamicIO) and should stall
// the promise to ensure the RSC side is considered dynamic // the promise to ensure the RSC side is considered dynamic
return makeHangingPromise() return makeHangingPromise()
}
} }
// We're prerendering in a mode that does not aborts. We resolve the promise without // We're prerendering in a mode that does not aborts. We resolve the promise without
// any tracking because we're just transporting a value from server to client where the tracking // any tracking because we're just transporting a value from server to client where the tracking
...@@ -112,17 +111,23 @@ function createPrerenderSearchParams( ...@@ -112,17 +111,23 @@ function createPrerenderSearchParams(
return Promise.resolve({}) return Promise.resolve({})
} }
const prerenderStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
if (prerenderStore && prerenderStore.type === 'prerender') { if (workUnitStore) {
if (prerenderStore.controller || prerenderStore.cacheSignal) { if (workUnitStore.type === 'prerender') {
// We are in a dynamicIO (PPR or otherwise) prerender // We are in a dynamicIO (PPR or otherwise) prerender
return makeAbortingExoticSearchParams(workStore.route, prerenderStore) return makeAbortingExoticSearchParams(workStore.route, workUnitStore)
} else if (
workUnitStore.type === 'prerender-legacy' ||
workUnitStore.type === 'prerender-ppr'
) {
// We are in a legacy static generation and need to interrupt the prerender
// when search params are accessed.
return makeErroringExoticSearchParams(workStore, workUnitStore)
} }
} }
throw new InvariantError(
// We are in a legacy static generation and need to interrupt the prerender 'createPrerenderSearchParams called without a prerenderStore in scope. This is a bug in Next.js'
// when search params are accessed. )
return makeErroringExoticSearchParams(workStore, prerenderStore)
} }
function createRenderSearchParams( function createRenderSearchParams(
...@@ -258,7 +263,7 @@ function makeAbortingExoticSearchParams( ...@@ -258,7 +263,7 @@ function makeAbortingExoticSearchParams(
function makeErroringExoticSearchParams( function makeErroringExoticSearchParams(
workStore: WorkStore, workStore: WorkStore,
prerenderStore: undefined | WorkUnitStore prerenderStore: PrerenderStoreLegacy | PrerenderStorePPR
): Promise<SearchParams> { ): Promise<SearchParams> {
const cachedSearchParams = CachedSearchParams.get(workStore) const cachedSearchParams = CachedSearchParams.get(workStore)
if (cachedSearchParams) { if (cachedSearchParams) {
...@@ -311,18 +316,19 @@ function makeErroringExoticSearchParams( ...@@ -311,18 +316,19 @@ function makeErroringExoticSearchParams(
workStore.route, workStore.route,
expression expression
) )
} else if (prerenderStore && prerenderStore.type === 'prerender') { } else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
const workUnitStore = workUnitAsyncStorage.getStore() // Legacy Prerender
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
expression, expression,
workStore, workStore,
workUnitStore prerenderStore
) )
} }
return return
...@@ -335,18 +341,19 @@ function makeErroringExoticSearchParams( ...@@ -335,18 +341,19 @@ function makeErroringExoticSearchParams(
workStore.route, workStore.route,
expression expression
) )
} else if (prerenderStore && prerenderStore.type === 'prerender') { } else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
const workUnitStore = workUnitAsyncStorage.getStore() // Legacy Prerender
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
expression, expression,
workStore, workStore,
workUnitStore prerenderStore
) )
} }
return return
...@@ -362,18 +369,19 @@ function makeErroringExoticSearchParams( ...@@ -362,18 +369,19 @@ function makeErroringExoticSearchParams(
workStore.route, workStore.route,
expression expression
) )
} else if (prerenderStore && prerenderStore.type === 'prerender') { } else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
const workUnitStore = workUnitAsyncStorage.getStore() // Legacy Prerender
throwToInterruptStaticGeneration( throwToInterruptStaticGeneration(
expression, expression,
workStore, workStore,
workUnitStore prerenderStore
) )
} }
} }
...@@ -396,15 +404,20 @@ function makeErroringExoticSearchParams( ...@@ -396,15 +404,20 @@ function makeErroringExoticSearchParams(
workStore.route, workStore.route,
expression expression
) )
} else if (prerenderStore && prerenderStore.type === 'prerender') { } else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
const workUnitStore = workUnitAsyncStorage.getStore() // Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, workUnitStore) throwToInterruptStaticGeneration(
expression,
workStore,
prerenderStore
)
} }
return false return false
} }
...@@ -418,15 +431,16 @@ function makeErroringExoticSearchParams( ...@@ -418,15 +431,16 @@ function makeErroringExoticSearchParams(
workStore.route, workStore.route,
expression expression
) )
} else if (prerenderStore && prerenderStore.type === 'prerender') { } else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking( postponeWithTracking(
workStore.route, workStore.route,
expression, expression,
prerenderStore.dynamicTracking prerenderStore.dynamicTracking
) )
} else { } else {
const workUnitStore = workUnitAsyncStorage.getStore() // Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, workUnitStore) throwToInterruptStaticGeneration(expression, workStore, prerenderStore)
} }
}, },
}) })
......
...@@ -303,6 +303,7 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -303,6 +303,7 @@ export class AppRouteRouteModule extends RouteModule<
workUnitStore.type === 'request' workUnitStore.type === 'request'
? workUnitStore.url.pathname ? workUnitStore.url.pathname
: workUnitStore.type === 'prerender' || : workUnitStore.type === 'prerender' ||
workUnitStore.type === 'prerender-ppr' ||
workUnitStore.type === 'prerender-legacy' workUnitStore.type === 'prerender-legacy'
? workUnitStore.pathname ? workUnitStore.pathname
: undefined : undefined
...@@ -328,12 +329,14 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -328,12 +329,14 @@ export class AppRouteRouteModule extends RouteModule<
* Functionally though IO should still take longer than the time it takes to unwrap the response body * Functionally though IO should still take longer than the time it takes to unwrap the response body
* so our heuristic of excluding any IO should be preserved. * so our heuristic of excluding any IO should be preserved.
*/ */
const prospectiveController = new AbortController()
let prospectiveRenderIsDynamic = false let prospectiveRenderIsDynamic = false
const cacheSignal = new CacheSignal() const cacheSignal = new CacheSignal()
let dynamicTracking = createDynamicTrackingState(undefined) let dynamicTracking = createDynamicTrackingState(undefined)
const prospectiveRoutePrerenderStore: PrerenderStore = { const prospectiveRoutePrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
renderSignal: prospectiveController.signal,
pathname, pathname,
cacheSignal, cacheSignal,
// During prospective render we don't use a controller // During prospective render we don't use a controller
...@@ -397,14 +400,15 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -397,14 +400,15 @@ export class AppRouteRouteModule extends RouteModule<
// TODO start passing this controller to the route handler. We should expose // TODO start passing this controller to the route handler. We should expose
// it so the handler to abort inflight requests and other operations if we abort // it so the handler to abort inflight requests and other operations if we abort
// the prerender. // the prerender.
const controller = new AbortController() const finalController = new AbortController()
dynamicTracking = createDynamicTrackingState(undefined) dynamicTracking = createDynamicTrackingState(undefined)
const finalRoutePrerenderStore: PrerenderStore = { const finalRoutePrerenderStore: PrerenderStore = {
type: 'prerender', type: 'prerender',
renderSignal: finalController.signal,
pathname, pathname,
cacheSignal: null, cacheSignal: null,
controller, controller: finalController,
dynamicTracking, dynamicTracking,
} }
...@@ -446,7 +450,7 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -446,7 +450,7 @@ export class AppRouteRouteModule extends RouteModule<
scheduleImmediate(() => { scheduleImmediate(() => {
if (!bodyHandled) { if (!bodyHandled) {
bodyHandled = true bodyHandled = true
controller.abort() finalController.abort()
reject(createDynamicIOError(workStore.route)) reject(createDynamicIOError(workStore.route))
} }
}) })
...@@ -457,19 +461,19 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -457,19 +461,19 @@ export class AppRouteRouteModule extends RouteModule<
scheduleImmediate(() => { scheduleImmediate(() => {
if (!responseHandled) { if (!responseHandled) {
responseHandled = true responseHandled = true
controller.abort() finalController.abort()
reject(createDynamicIOError(workStore.route)) reject(createDynamicIOError(workStore.route))
} }
}) })
}) })
if (controller.signal.aborted) { if (finalController.signal.aborted) {
// We aborted from within the execution // We aborted from within the execution
throw createDynamicIOError(workStore.route) throw createDynamicIOError(workStore.route)
} else { } else {
// We didn't abort during the execution. We can abort now as a matter of semantics // We didn't abort during the execution. We can abort now as a matter of semantics
// though at the moment nothing actually consumes this signal so it won't halt any // though at the moment nothing actually consumes this signal so it won't halt any
// inflight work. // inflight work.
controller.abort() finalController.abort()
} }
} else if (isStaticGeneration) { } else if (isStaticGeneration) {
res = await workUnitAsyncStorage.run( res = await workUnitAsyncStorage.run(
......
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