Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,8 @@ export default abstract class Server<

incrementalCache.resetRequestCache()
addRequestMeta(req, 'incrementalCache', incrementalCache)
// This is needed for pages router to leverage unstable_cache
// TODO: re-work this handling to not use global and use a AsyncStore
;(globalThis as any).__incrementalCache = incrementalCache
}

Expand Down Expand Up @@ -2457,13 +2459,15 @@ export default abstract class Server<

// use existing incrementalCache instance if available
const incrementalCache: import('./lib/incremental-cache').IncrementalCache =
(globalThis as any).__incrementalCache ||
(await this.getIncrementalCache({
requestHeaders: Object.assign({}, req.headers),
requestProtocol: protocol.substring(0, protocol.length - 1) as
| 'http'
| 'https',
}))
process.env.NEXT_RUNTIME === 'edge' &&
(globalThis as any).__incrementalCache
? (globalThis as any).__incrementalCache
: await this.getIncrementalCache({
requestHeaders: Object.assign({}, req.headers),
requestProtocol: protocol.substring(0, protocol.length - 1) as
| 'http'
| 'https',
})

// TODO: investigate, this is not safe across multiple concurrent requests
incrementalCache.resetRequestCache()
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/web/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ export async function adapter(
}

if (
!(globalThis as any).__incrementalCache &&
// If we are inside of the next start sandbox
// leverage the shared instance if not we need
// to create a fresh cache instance each time
!(globalThis as any).__incrementalCacheShared &&
(params as any).IncrementalCache
) {
;(globalThis as any).__incrementalCache = new (
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/web/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export async function getRuntimeContext(
})

if (params.incrementalCache) {
runtime.context.globalThis.__incrementalCacheShared = true
runtime.context.globalThis.__incrementalCache = params.incrementalCache
}

Expand Down
Loading