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> { ...@@ -1245,6 +1245,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}) })
incrementalCache.resetRequestCache() incrementalCache.resetRequestCache()
addRequestMeta(req, 'incrementalCache', incrementalCache) 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 ;(globalThis as any).__incrementalCache = incrementalCache
} }
...@@ -2106,13 +2108,15 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2106,13 +2108,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// use existing incrementalCache instance if available // use existing incrementalCache instance if available
const incrementalCache = const incrementalCache =
(globalThis as any).__incrementalCache || process.env.NEXT_RUNTIME === 'edge' &&
(await this.getIncrementalCache({ (globalThis as any).__incrementalCache
requestHeaders: Object.assign({}, req.headers), ? (globalThis as any).__incrementalCache
requestProtocol: protocol.substring(0, protocol.length - 1) as : await this.getIncrementalCache({
| 'http' requestHeaders: Object.assign({}, req.headers),
| 'https', requestProtocol: protocol.substring(0, protocol.length - 1) as
})) | 'http'
| 'https',
})
incrementalCache?.resetRequestCache() incrementalCache?.resetRequestCache()
......
...@@ -169,7 +169,10 @@ export async function adapter( ...@@ -169,7 +169,10 @@ export async function adapter(
} }
if ( 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 (params as any).IncrementalCache
) { ) {
;(globalThis as any).__incrementalCache = new ( ;(globalThis as any).__incrementalCache = new (
......
...@@ -72,6 +72,7 @@ export async function getRuntimeContext(params: { ...@@ -72,6 +72,7 @@ export async function getRuntimeContext(params: {
}) })
if (params.incrementalCache) { if (params.incrementalCache) {
runtime.context.globalThis.__incrementalCacheShared = true
runtime.context.globalThis.__incrementalCache = params.incrementalCache 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