File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -1245,6 +1245,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
12451245 } )
12461246 incrementalCache . resetRequestCache ( )
12471247 addRequestMeta ( req , 'incrementalCache' , incrementalCache )
1248+ // This is needed for pages router to leverage unstable_cache
1249+ // TODO: re-work this handling to not use global and use a AsyncStore
12481250 ; ( globalThis as any ) . __incrementalCache = incrementalCache
12491251 }
12501252
@@ -2106,13 +2108,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
21062108
21072109 // use existing incrementalCache instance if available
21082110 const incrementalCache =
2109- ( globalThis as any ) . __incrementalCache ||
2110- ( await this . getIncrementalCache ( {
2111- requestHeaders : Object . assign ( { } , req . headers ) ,
2112- requestProtocol : protocol . substring ( 0 , protocol . length - 1 ) as
2113- | 'http'
2114- | 'https' ,
2115- } ) )
2111+ process . env . NEXT_RUNTIME === 'edge' &&
2112+ ( globalThis as any ) . __incrementalCache
2113+ ? ( globalThis as any ) . __incrementalCache
2114+ : await this . getIncrementalCache ( {
2115+ requestHeaders : Object . assign ( { } , req . headers ) ,
2116+ requestProtocol : protocol . substring ( 0 , protocol . length - 1 ) as
2117+ | 'http'
2118+ | 'https' ,
2119+ } )
21162120
21172121 incrementalCache ?. resetRequestCache ( )
21182122
Original file line number Diff line number Diff line change @@ -169,7 +169,10 @@ export async function adapter(
169169 }
170170
171171 if (
172- ! ( globalThis as any ) . __incrementalCache &&
172+ // If we are inside of the next start sandbox
173+ // leverage the shared instance if not we need
174+ // to create a fresh cache instance each time
175+ ! ( globalThis as any ) . __incrementalCacheShared &&
173176 ( params as any ) . IncrementalCache
174177 ) {
175178 ; ( globalThis as any ) . __incrementalCache = new (
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export async function getRuntimeContext(params: {
7272 } )
7373
7474 if ( params . incrementalCache ) {
75+ runtime . context . globalThis . __incrementalCacheShared = true
7576 runtime . context . globalThis . __incrementalCache = params . incrementalCache
7677 }
7778
You can’t perform that action at this time.
0 commit comments