@@ -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
453464function ignoreReject ( ) { }
0 commit comments