Skip to content

Commit e3276d4

Browse files
lubieowocegnoff
authored andcommitted
restore proxies, clean up caching logic for searchParams
1 parent a310c2f commit e3276d4

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

packages/next/src/server/request/cookies.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ function makeUntrackedCookiesWithDevWarnings(
201201
'Received a underlying cookies object that does not match either `cookies` or `mutableCookies`'
202202
)
203203
}
204-
// TODO(restart-on-cache-miss): Instrument with warnings
205-
// return instrumentCookiesPromiseWithDevWarnings(promise, route)
206-
return promise
204+
return instrumentCookiesPromiseWithDevWarnings(promise, route)
207205
}
208206

209207
const cachedCookies = CachedCookies.get(underlyingCookies)

packages/next/src/server/request/headers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ function makeUntrackedHeadersWithDevWarnings(
201201
): Promise<ReadonlyHeaders> {
202202
if (requestStore.asyncApiPromises) {
203203
const promise = requestStore.asyncApiPromises.headers
204-
// TODO(restart-on-cache-miss): Instrument with warnings
205-
// return instrumentHeadersPromiseWithDevWarnings(promise, route)
206-
return promise
204+
return instrumentHeadersPromiseWithDevWarnings(promise, route)
207205
}
208206

209207
const cachedHeaders = CachedHeaders.get(underlyingHeaders)

packages/next/src/server/request/params.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,20 @@ function makeDynamicallyTrackedParamsWithDevWarnings(
456456
requestStore: RequestStore
457457
): Promise<Params> {
458458
if (requestStore.asyncApiPromises && hasFallbackParams) {
459+
// Deliberately don't wrap each instance of params in a `new Promise()`.
460+
// We want React Devtools to consider all the separate `params` promises
461+
// that we create for each segment to be triggered by one IO operation --
462+
// the resolving of the underlying `sharedParamsParent` promise.
463+
// It's created above any userspace code and has a `displayName`,
464+
// so it should show up in "suspended by".
459465
const promise = requestStore.asyncApiPromises.sharedParamsParent.then(
460466
() => underlyingParams
461467
)
462-
// TODO(restart-on-cache-miss): Instrument with warnings
463-
// return instrumentParamsPromiseWithDevWarnings(
464-
// underlyingParams,
465-
// promise,
466-
// workStore
467-
// )
468-
return promise
468+
return instrumentParamsPromiseWithDevWarnings(
469+
underlyingParams,
470+
promise,
471+
workStore
472+
)
469473
}
470474

471475
const cachedParams = CachedParams.get(underlyingParams)

packages/next/src/server/request/search-params.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,34 @@ function makeUntrackedSearchParamsWithDevWarnings(
386386
workStore: WorkStore,
387387
requestStore: RequestStore
388388
): Promise<SearchParams> {
389-
const shouldCachePromise = !!requestStore.asyncApiPromises
390-
if (shouldCachePromise) {
391-
// Note: unlike some of the other functions here, we tie the lifetime of the cached search params
392-
// to the request store, not `underlyingSearchParams`.
393-
// If we didn't do that we'd end up re-using the same object across both renders in the restart-on-cache-miss flow,
394-
// meaning that the `searchParams` promise would (incorrectly) be already resolved in the restarted render.
395-
const cachedSearchParams = CachedSearchParams.get(requestStore)
389+
if (requestStore.asyncApiPromises) {
390+
// Do not cache the resulting promise. If we do, we'll only show the first "awaited at"
391+
// across all segments that receive searchParams.
392+
return makeUntrackedSearchParamsWithDevWarningsImpl(
393+
underlyingSearchParams,
394+
workStore,
395+
requestStore
396+
)
397+
} else {
398+
const cachedSearchParams = CachedSearchParams.get(underlyingSearchParams)
396399
if (cachedSearchParams) {
397400
return cachedSearchParams
398401
}
402+
const promise = makeUntrackedSearchParamsWithDevWarningsImpl(
403+
underlyingSearchParams,
404+
workStore,
405+
requestStore
406+
)
407+
CachedSearchParams.set(requestStore, promise)
408+
return promise
399409
}
410+
}
400411

412+
function makeUntrackedSearchParamsWithDevWarningsImpl(
413+
underlyingSearchParams: SearchParams,
414+
workStore: WorkStore,
415+
requestStore: RequestStore
416+
): Promise<SearchParams> {
401417
const promiseInitialized = { current: false }
402418
const proxiedUnderlying = instrumentSearchParamsObjectWithDevWarnings(
403419
underlyingSearchParams,
@@ -407,6 +423,12 @@ function makeUntrackedSearchParamsWithDevWarnings(
407423

408424
let promise: Promise<SearchParams>
409425
if (requestStore.asyncApiPromises) {
426+
// Deliberately don't wrap each instance of params in a `new Promise()`.
427+
// We want React Devtools to consider all the separate `searchParams` promises
428+
// that we create for each segment to be triggered by one IO operation --
429+
// the resolving of the underlying `sharedParamsParent` promise.
430+
// It's created above any userspace code and has a `displayName`,
431+
// so it should show up in "suspended by".
410432
promise = requestStore.asyncApiPromises.sharedSearchParamsParent.then(
411433
() => proxiedUnderlying
412434
)
@@ -432,22 +454,11 @@ function makeUntrackedSearchParamsWithDevWarnings(
432454
ignoreReject
433455
)
434456

435-
if (requestStore.asyncApiPromises) {
436-
// TODO(restart-on-cache-miss): Instrument with warnings
437-
return promise
438-
}
439-
440-
const proxiedPromise = instrumentSearchParamsPromiseWithDevWarnings(
457+
return instrumentSearchParamsPromiseWithDevWarnings(
441458
underlyingSearchParams,
442459
promise,
443460
workStore
444461
)
445-
446-
if (shouldCachePromise) {
447-
CachedSearchParams.set(requestStore, proxiedPromise)
448-
}
449-
450-
return proxiedPromise
451462
}
452463

453464
function ignoreReject() {}

0 commit comments

Comments
 (0)