Skip to content

Commit 5ec796e

Browse files
tyao1facebook-github-bot
authored andcommitted
Annotate read time resolver promises
Reviewed By: captbaritone Differential Revision: D76390067 Privacy Context Container: L1125407 fbshipit-source-id: aa1409da7e3163663c889e190a18093521509bfb
1 parent 2b85d37 commit 5ec796e

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ function handleMissedUpdates(
222222
}
223223
}
224224

225+
type PromiseWithDisplayName = Promise<mixed> & {displayName?: string};
226+
225227
function handleMissingClientEdge(
226228
environment: IEnvironment,
227229
parentFragmentNode: ReaderFragment,
228230
parentFragmentRef: mixed,
229231
missingClientEdgeRequestInfo: MissingClientEdgeRequestInfo,
230232
queryOptions?: FragmentQueryOptions,
231-
): [QueryResult, ?Promise<mixed>] {
233+
): [QueryResult, ?PromiseWithDisplayName] {
232234
const originalVariables = getVariablesFromFragment(
233235
parentFragmentNode,
234236
parentFragmentRef,
@@ -253,10 +255,17 @@ function handleMissingClientEdge(
253255
queryOptions?.fetchPolicy,
254256
);
255257

256-
return [
257-
queryResult,
258-
getPromiseForActiveRequest(environment, queryOperationDescriptor.request),
259-
];
258+
const promise = getPromiseForActiveRequest(
259+
environment,
260+
queryOperationDescriptor.request,
261+
);
262+
// $FlowExpectedError[prop-missing]
263+
if (promise != null && promise.displayName == null) {
264+
// $FlowExpectedError[prop-missing]
265+
promise.displayName = missingClientEdgeRequestInfo.request.params.name;
266+
}
267+
// $FlowFixMe[incompatible-exact] - Intentionally bypassing exactness check
268+
return [queryResult, promise];
260269
}
261270

262271
function subscribeToSnapshot(
@@ -490,7 +499,7 @@ hook useFragmentInternal_EXPERIMENTAL(
490499
const missingClientEdges = getMissingClientEdges(state);
491500
// eslint-disable-next-line no-shadow
492501
let clientEdgeQueries;
493-
const activeRequestPromises = [];
502+
const activeRequestPromises: Array<PromiseWithDisplayName> = [];
494503
if (missingClientEdges?.length) {
495504
clientEdgeQueries = ([]: Array<QueryResult>);
496505
for (const edge of missingClientEdges) {
@@ -511,7 +520,12 @@ hook useFragmentInternal_EXPERIMENTAL(
511520
}, [state, environment, fragmentNode, fragmentRef, queryOptions]);
512521

513522
if (activeRequestPromises.length) {
514-
throw Promise.all(activeRequestPromises);
523+
const allPromises = Promise.all(activeRequestPromises);
524+
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
525+
allPromises.displayName = `RelayClientEdge(${activeRequestPromises
526+
.map(promise => promise.displayName)
527+
.join(',')})`;
528+
throw allPromises;
515529
}
516530

517531
// See above note
@@ -538,12 +552,15 @@ hook useFragmentInternal_EXPERIMENTAL(
538552
// Suspend if a Live Resolver within this fragment is in a suspended state:
539553
const suspendingLiveResolvers = getSuspendingLiveResolver(state);
540554
if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
541-
throw Promise.all(
555+
const promise = Promise.all(
542556
suspendingLiveResolvers.map(liveStateID => {
543557
// $FlowFixMe[prop-missing] This is expected to be a RelayModernStore
544558
return environment.getStore().getLiveResolverPromise(liveStateID);
545559
}),
546560
);
561+
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
562+
promise.displayName = 'RelayLiveResolver(' + fragmentNode.name + ')';
563+
throw promise;
547564
}
548565
// Suspend if an active operation bears on this fragment, either the
549566
// fragment's owner or some other mutation etc. that could affect it.

0 commit comments

Comments
 (0)