Unverified Commit ec9ee874 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Only share incremental cache for edge in next start (#79389)

This backports https://github.com/vercel/next.js/pull/79386 to 14
release channel
parent e65628a2
......@@ -1245,6 +1245,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
})
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
}
......@@ -2106,13 +2108,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// use existing incrementalCache instance if available
const 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',
})
incrementalCache?.resetRequestCache()
......
......@@ -169,7 +169,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 (
......
......@@ -72,6 +72,7 @@ export async function getRuntimeContext(params: {
})
if (params.incrementalCache) {
runtime.context.globalThis.__incrementalCacheShared = true
runtime.context.globalThis.__incrementalCache = params.incrementalCache
}
......
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