diff --git a/packages/next/src/server/app-render/work-unit-async-storage.external.ts b/packages/next/src/server/app-render/work-unit-async-storage.external.ts index 1be45350eb2f2..42b1f0e6664a7 100644 --- a/packages/next/src/server/app-render/work-unit-async-storage.external.ts +++ b/packages/next/src/server/app-render/work-unit-async-storage.external.ts @@ -49,7 +49,7 @@ export type RequestStore = { * to fill all caches. */ export type PrerenderStoreModern = { - type: 'prerender', + type: 'prerender' pathname: string | undefined /** * This is the AbortController passed to React. It can be used to abort the prerender @@ -70,7 +70,7 @@ export type PrerenderStoreModern = { } export type PrerenderStoreLegacy = { - type: 'prerender-legacy', + type: 'prerender-legacy' pathname: string | undefined } diff --git a/packages/next/src/server/route-modules/app-route/module.ts b/packages/next/src/server/route-modules/app-route/module.ts index 78e4462914738..a2839593a907d 100644 --- a/packages/next/src/server/route-modules/app-route/module.ts +++ b/packages/next/src/server/route-modules/app-route/module.ts @@ -299,6 +299,14 @@ export class AppRouteRouteModule extends RouteModule< : undefined, } + const pathname = + workUnitStore.type === 'request' + ? workUnitStore.url.pathname + : workUnitStore.type === 'prerender' || + workUnitStore.type === 'prerender-legacy' + ? workUnitStore.pathname + : undefined + let res: unknown try { if (isStaticGeneration && dynamicIOEnabled) { @@ -323,9 +331,10 @@ export class AppRouteRouteModule extends RouteModule< let prospectiveRenderIsDynamic = false const cacheSignal = new CacheSignal() let dynamicTracking = createDynamicTrackingState(undefined) + const prospectiveRoutePrerenderStore: PrerenderStore = { type: 'prerender', - pathname: requestStore.url.pathname, + pathname, cacheSignal, // During prospective render we don't use a controller // because we need to let all caches fill. @@ -393,7 +402,7 @@ export class AppRouteRouteModule extends RouteModule< const finalRoutePrerenderStore: PrerenderStore = { type: 'prerender', - pathname: requestStore.url.pathname, + pathname, cacheSignal: null, controller, dynamicTracking, @@ -457,7 +466,7 @@ export class AppRouteRouteModule extends RouteModule< res = await workUnitAsyncStorage.run( { type: 'prerender-legacy', - pathname: requestStore.url.pathname, + pathname, }, handler, request, @@ -517,7 +526,6 @@ export class AppRouteRouteModule extends RouteModule< ]) addImplicitTags(workStore, workUnitStore) - ;(context.renderOpts as any).fetchTags = workStore.tags?.join(',') // It's possible cookies were set in the handler, so we need diff --git a/packages/next/src/server/web/spec-extension/unstable-cache.ts b/packages/next/src/server/web/spec-extension/unstable-cache.ts index 674618d5c4932..c75ff9fb4d97e 100644 --- a/packages/next/src/server/web/spec-extension/unstable-cache.ts +++ b/packages/next/src/server/web/spec-extension/unstable-cache.ts @@ -342,7 +342,11 @@ export function unstable_cache( type: 'unstable-cache', } // If we got this far then we had an invalid cache entry and need to generate a new one - const result = await cacheAsyncStorage.run(innerCacheStore, cb, ...args) + const result = await workUnitAsyncStorage.run( + innerCacheStore, + cb, + ...args + ) cacheNewResult( result, incrementalCache,