@@ -190,6 +190,22 @@ function makeUntrackedCookiesWithDevWarnings(
190190 underlyingCookies : ReadonlyRequestCookies ,
191191 route ?: string
192192) : Promise < ReadonlyRequestCookies > {
193+ if ( requestStore . asyncApiPromises ) {
194+ let promise : Promise < ReadonlyRequestCookies >
195+ if ( underlyingCookies === requestStore . mutableCookies ) {
196+ promise = requestStore . asyncApiPromises . mutableCookies
197+ } else if ( underlyingCookies === requestStore . cookies ) {
198+ promise = requestStore . asyncApiPromises . cookies
199+ } else {
200+ throw new InvariantError (
201+ 'Received a underlying cookies object that does not match either `cookies` or `mutableCookies`'
202+ )
203+ }
204+ // TODO(restart-on-cache-miss): Instrument with warnings
205+ // return instrumentCookiesPromiseWithDevWarnings(promise, route)
206+ return promise
207+ }
208+
193209 const cachedCookies = CachedCookies . get ( underlyingCookies )
194210 if ( cachedCookies ) {
195211 return cachedCookies
@@ -201,7 +217,22 @@ function makeUntrackedCookiesWithDevWarnings(
201217 RenderStage . Runtime
202218 )
203219
204- const proxiedPromise = new Proxy ( promise , {
220+ const proxiedPromise = instrumentCookiesPromiseWithDevWarnings ( promise , route )
221+
222+ CachedCookies . set ( underlyingCookies , proxiedPromise )
223+
224+ return proxiedPromise
225+ }
226+
227+ const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev (
228+ createCookiesAccessError
229+ )
230+
231+ function instrumentCookiesPromiseWithDevWarnings (
232+ promise : Promise < ReadonlyRequestCookies > ,
233+ route : string | undefined
234+ ) {
235+ return new Proxy ( promise , {
205236 get ( target , prop , receiver ) {
206237 switch ( prop ) {
207238 case Symbol . iterator : {
@@ -226,17 +257,12 @@ function makeUntrackedCookiesWithDevWarnings(
226257
227258 return ReflectAdapter . get ( target , prop , receiver )
228259 } ,
260+ set ( target , prop , newValue , receiver ) {
261+ return ReflectAdapter . set ( target , prop , newValue , receiver )
262+ } ,
229263 } )
230-
231- CachedCookies . set ( underlyingCookies , proxiedPromise )
232-
233- return proxiedPromise
234264}
235265
236- const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev (
237- createCookiesAccessError
238- )
239-
240266function createCookiesAccessError (
241267 route : string | undefined ,
242268 expression : string
0 commit comments