Skip to content

Commit f0f08d4

Browse files
committed
Only share incremental cache for edge in next start
1 parent c17942f commit f0f08d4

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

packages/next/src/server/base-server.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,6 @@ export default abstract class Server<
14671467

14681468
incrementalCache.resetRequestCache()
14691469
addRequestMeta(req, 'incrementalCache', incrementalCache)
1470-
;(globalThis as any).__incrementalCache = incrementalCache
14711470
}
14721471

14731472
const cacheHandlers = getCacheHandlers()
@@ -2457,13 +2456,15 @@ export default abstract class Server<
24572456

24582457
// use existing incrementalCache instance if available
24592458
const incrementalCache: import('./lib/incremental-cache').IncrementalCache =
2460-
(globalThis as any).__incrementalCache ||
2461-
(await this.getIncrementalCache({
2462-
requestHeaders: Object.assign({}, req.headers),
2463-
requestProtocol: protocol.substring(0, protocol.length - 1) as
2464-
| 'http'
2465-
| 'https',
2466-
}))
2459+
process.env.NEXT_RUNTIME === 'edge' &&
2460+
(globalThis as any).__incrementalCache
2461+
? (globalThis as any).__incrementalCache
2462+
: await this.getIncrementalCache({
2463+
requestHeaders: Object.assign({}, req.headers),
2464+
requestProtocol: protocol.substring(0, protocol.length - 1) as
2465+
| 'http'
2466+
| 'https',
2467+
})
24672468

24682469
// TODO: investigate, this is not safe across multiple concurrent requests
24692470
incrementalCache.resetRequestCache()

packages/next/src/server/web/adapter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ export async function adapter(
186186
}
187187

188188
if (
189-
!(globalThis as any).__incrementalCache &&
189+
// If we are inside of the next start sandbox
190+
// leverage the shared instance if not we need
191+
// to create a fresh cache instance each time
192+
!(globalThis as any).__incrementalCacheShared &&
190193
(params as any).IncrementalCache
191194
) {
192195
;(globalThis as any).__incrementalCache = new (

packages/next/src/server/web/sandbox/sandbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function getRuntimeContext(
7777
})
7878

7979
if (params.incrementalCache) {
80+
runtime.context.globalThis.__incrementalCacheShared = true
8081
runtime.context.globalThis.__incrementalCache = params.incrementalCache
8182
}
8283

0 commit comments

Comments
 (0)