From 81eab037a9259ef8a4a506de47410bd69fe317c1 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 11 Nov 2024 15:45:09 -0800 Subject: [PATCH] Remove unused fieldPath from resolver suspense objects Reviewed By: evanyeung Differential Revision: D65491871 fbshipit-source-id: abab46ded30ccf9354c30c67e80f7cc7e3a98843 --- .../relay-hooks/legacy/FragmentResource.js | 5 ++--- .../relay-hooks/useFragmentInternal_CURRENT.js | 12 +++++------- .../relay-hooks/useFragmentInternal_EXPERIMENTAL.js | 12 +++++------- packages/relay-runtime/store/RelayReader.js | 8 ++------ packages/relay-runtime/store/RelayStoreTypes.js | 7 +------ .../__tests__/RelayReader-RequiredFields-test.js | 5 +---- 6 files changed, 16 insertions(+), 33 deletions(-) diff --git a/packages/react-relay/relay-hooks/legacy/FragmentResource.js b/packages/react-relay/relay-hooks/legacy/FragmentResource.js index f0621cbb55e62..4f4289db7cadf 100644 --- a/packages/react-relay/relay-hooks/legacy/FragmentResource.js +++ b/packages/react-relay/relay-hooks/legacy/FragmentResource.js @@ -22,7 +22,6 @@ import type { RequestDescriptor, Snapshot, } from 'relay-runtime'; -import type {MissingLiveResolverField} from 'relay-runtime/store/RelayStoreTypes'; const LRUCache = require('../LRUCache'); const {getQueryResourceForEnvironment} = require('../QueryResource'); @@ -98,7 +97,7 @@ function hasMissingClientEdges(snapshot: SingularOrPluralSnapshot): boolean { function missingLiveResolverFields( snapshot: SingularOrPluralSnapshot, -): ?$ReadOnlyArray { +): ?$ReadOnlyArray { if (Array.isArray(snapshot)) { return snapshot .map(s => s.missingLiveResolverFields) @@ -449,7 +448,7 @@ class FragmentResourceImpl { ); const parentQueryPromiseResultPromise = parentQueryPromiseResult?.promise; // for refinement const missingResolverFieldPromises = - missingLiveResolverFields(snapshot)?.map(({liveStateID}) => { + missingLiveResolverFields(snapshot)?.map(liveStateID => { const store = environment.getStore(); // $FlowFixMe[prop-missing] This is expected to be a RelayModernStore diff --git a/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js b/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js index 9984953f32347..5b8252dec4bef 100644 --- a/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js +++ b/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js @@ -14,6 +14,7 @@ import type {QueryResult} from './QueryResource'; import type { CacheConfig, + DataID, FetchPolicy, IEnvironment, ReaderFragment, @@ -21,10 +22,7 @@ import type { SelectorData, Snapshot, } from 'relay-runtime'; -import type { - MissingClientEdgeRequestInfo, - MissingLiveResolverField, -} from 'relay-runtime/store/RelayStoreTypes'; +import type {MissingClientEdgeRequestInfo} from 'relay-runtime/store/RelayStoreTypes'; const {getQueryResourceForEnvironment} = require('./QueryResource'); const useRelayEnvironment = require('./useRelayEnvironment'); @@ -89,13 +87,13 @@ function getMissingClientEdges( function getSuspendingLiveResolver( state: FragmentState, -): $ReadOnlyArray | null { +): $ReadOnlyArray | null { if (state.kind === 'bailout') { return null; } else if (state.kind === 'singular') { return state.snapshot.missingLiveResolverFields ?? null; } else { - let missingFields: null | Array = null; + let missingFields: null | Array = null; for (const snapshot of state.snapshots) { if (snapshot.missingLiveResolverFields) { missingFields = missingFields ?? []; @@ -508,7 +506,7 @@ hook useFragmentInternal( const suspendingLiveResolvers = getSuspendingLiveResolver(state); if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) { throw Promise.all( - suspendingLiveResolvers.map(({liveStateID}) => { + suspendingLiveResolvers.map(liveStateID => { // $FlowFixMe[prop-missing] This is expected to be a RelayModernStore return environment.getStore().getLiveResolverPromise(liveStateID); }), diff --git a/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js b/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js index 4afaa12972f9f..68f35c2d65d56 100644 --- a/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +++ b/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js @@ -14,6 +14,7 @@ import type {QueryResult} from './QueryResource'; import type { CacheConfig, + DataID, FetchPolicy, IEnvironment, ReaderFragment, @@ -21,10 +22,7 @@ import type { SelectorData, Snapshot, } from 'relay-runtime'; -import type { - MissingClientEdgeRequestInfo, - MissingLiveResolverField, -} from 'relay-runtime/store/RelayStoreTypes'; +import type {MissingClientEdgeRequestInfo} from 'relay-runtime/store/RelayStoreTypes'; const {getQueryResourceForEnvironment} = require('./QueryResource'); const useRelayEnvironment = require('./useRelayEnvironment'); @@ -101,13 +99,13 @@ function getMissingClientEdges( function getSuspendingLiveResolver( state: FragmentState, -): $ReadOnlyArray | null { +): $ReadOnlyArray | null { if (state.kind === 'bailout') { return null; } else if (state.kind === 'singular') { return state.snapshot.missingLiveResolverFields ?? null; } else { - let missingFields: null | Array = null; + let missingFields: null | Array = null; for (const snapshot of state.snapshots) { if (snapshot.missingLiveResolverFields) { missingFields = missingFields ?? []; @@ -523,7 +521,7 @@ hook useFragmentInternal_EXPERIMENTAL( const suspendingLiveResolvers = getSuspendingLiveResolver(state); if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) { throw Promise.all( - suspendingLiveResolvers.map(({liveStateID}) => { + suspendingLiveResolvers.map(liveStateID => { // $FlowFixMe[prop-missing] This is expected to be a RelayModernStore return environment.getStore().getLiveResolverPromise(liveStateID); }), diff --git a/packages/relay-runtime/store/RelayReader.js b/packages/relay-runtime/store/RelayReader.js index e5ff4191f049d..7f89004dc5706 100644 --- a/packages/relay-runtime/store/RelayReader.js +++ b/packages/relay-runtime/store/RelayReader.js @@ -38,7 +38,6 @@ import type { ErrorResponseField, ErrorResponseFields, MissingClientEdgeRequestInfo, - MissingLiveResolverField, Record, RecordSource, RequestDescriptor, @@ -97,7 +96,7 @@ class RelayReader { _clientEdgeTraversalPath: Array; _isMissingData: boolean; _missingClientEdges: Array; - _missingLiveResolverFields: Array; + _missingLiveResolverFields: Array; _isWithinUnmatchedTypeRefinement: boolean; _errorResponseFields: ?ErrorResponseFields; _owner: RequestDescriptor; @@ -869,10 +868,7 @@ class RelayReader { // they know when to unsuspend. if (suspenseID != null) { this._isMissingData = true; - this._missingLiveResolverFields.push({ - path: `${this._fragmentName}.${fieldPath}`, - liveStateID: suspenseID, - }); + this._missingLiveResolverFields.push(suspenseID); } if (updatedDataIDs != null) { for (const recordID of updatedDataIDs) { diff --git a/packages/relay-runtime/store/RelayStoreTypes.js b/packages/relay-runtime/store/RelayStoreTypes.js index b838e1e1acc99..d2d04fae95b99 100644 --- a/packages/relay-runtime/store/RelayStoreTypes.js +++ b/packages/relay-runtime/store/RelayStoreTypes.js @@ -139,18 +139,13 @@ export type MissingClientEdgeRequestInfo = { +clientEdgeDestinationID: DataID, }; -export type MissingLiveResolverField = { - +path: string, - +liveStateID: DataID, -}; - /** * A representation of a selector and its results at a particular point in time. */ export type Snapshot = { +data: ?SelectorData, +isMissingData: boolean, - +missingLiveResolverFields?: $ReadOnlyArray, + +missingLiveResolverFields?: $ReadOnlyArray, +missingClientEdges: null | $ReadOnlyArray, +seenRecords: DataIDSet, +selector: SingularReaderSelector, diff --git a/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js b/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js index 28ae1115780a9..2cec55e88c78b 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js @@ -1056,10 +1056,7 @@ describe('RelayReader @required', () => { const snapshot = read(source, operation.fragment, resolverCache); expect(snapshot.errorResponseFields).toEqual(null); expect(snapshot.missingLiveResolverFields).toEqual([ - { - path: 'RelayReaderRequiredFieldsTest28Query.live_user_resolver_always_suspend', - liveStateID: 'client:root:live_user_resolver_always_suspend', - }, + 'client:root:live_user_resolver_always_suspend', ]); }); });