Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Oct 7, 2024
1 parent 15cbe5d commit 0b8a8ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,7 +70,7 @@ export type PrerenderStoreModern = {
}

export type PrerenderStoreLegacy = {
type: 'prerender-legacy',
type: 'prerender-legacy'
pathname: string | undefined
}

Expand Down
16 changes: 12 additions & 4 deletions packages/next/src/server/route-modules/app-route/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down Expand Up @@ -393,7 +402,7 @@ export class AppRouteRouteModule extends RouteModule<

const finalRoutePrerenderStore: PrerenderStore = {
type: 'prerender',
pathname: requestStore.url.pathname,
pathname,
cacheSignal: null,
controller,
dynamicTracking,
Expand Down Expand Up @@ -457,7 +466,7 @@ export class AppRouteRouteModule extends RouteModule<
res = await workUnitAsyncStorage.run(
{
type: 'prerender-legacy',
pathname: requestStore.url.pathname,
pathname,
},
handler,
request,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ export function unstable_cache<T extends Callback>(
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,
Expand Down

0 comments on commit 0b8a8ee

Please sign in to comment.