Skip to content

Commit

Permalink
Remove unused fieldPath from resolver suspense objects
Browse files Browse the repository at this point in the history
Reviewed By: evanyeung

Differential Revision: D65491871

fbshipit-source-id: abab46ded30ccf9354c30c67e80f7cc7e3a98843
  • Loading branch information
captbaritone authored and facebook-github-bot committed Nov 11, 2024
1 parent d982b5b commit 81eab03
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
5 changes: 2 additions & 3 deletions packages/react-relay/relay-hooks/legacy/FragmentResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -98,7 +97,7 @@ function hasMissingClientEdges(snapshot: SingularOrPluralSnapshot): boolean {

function missingLiveResolverFields(
snapshot: SingularOrPluralSnapshot,
): ?$ReadOnlyArray<MissingLiveResolverField> {
): ?$ReadOnlyArray<DataID> {
if (Array.isArray(snapshot)) {
return snapshot
.map(s => s.missingLiveResolverFields)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
import type {QueryResult} from './QueryResource';
import type {
CacheConfig,
DataID,
FetchPolicy,
IEnvironment,
ReaderFragment,
ReaderSelector,
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');
Expand Down Expand Up @@ -89,13 +87,13 @@ function getMissingClientEdges(

function getSuspendingLiveResolver(
state: FragmentState,
): $ReadOnlyArray<MissingLiveResolverField> | null {
): $ReadOnlyArray<DataID> | null {
if (state.kind === 'bailout') {
return null;
} else if (state.kind === 'singular') {
return state.snapshot.missingLiveResolverFields ?? null;
} else {
let missingFields: null | Array<MissingLiveResolverField> = null;
let missingFields: null | Array<DataID> = null;
for (const snapshot of state.snapshots) {
if (snapshot.missingLiveResolverFields) {
missingFields = missingFields ?? [];
Expand Down Expand Up @@ -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);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
import type {QueryResult} from './QueryResource';
import type {
CacheConfig,
DataID,
FetchPolicy,
IEnvironment,
ReaderFragment,
ReaderSelector,
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');
Expand Down Expand Up @@ -101,13 +99,13 @@ function getMissingClientEdges(

function getSuspendingLiveResolver(
state: FragmentState,
): $ReadOnlyArray<MissingLiveResolverField> | null {
): $ReadOnlyArray<DataID> | null {
if (state.kind === 'bailout') {
return null;
} else if (state.kind === 'singular') {
return state.snapshot.missingLiveResolverFields ?? null;
} else {
let missingFields: null | Array<MissingLiveResolverField> = null;
let missingFields: null | Array<DataID> = null;
for (const snapshot of state.snapshots) {
if (snapshot.missingLiveResolverFields) {
missingFields = missingFields ?? [];
Expand Down Expand Up @@ -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);
}),
Expand Down
8 changes: 2 additions & 6 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import type {
ErrorResponseField,
ErrorResponseFields,
MissingClientEdgeRequestInfo,
MissingLiveResolverField,
Record,
RecordSource,
RequestDescriptor,
Expand Down Expand Up @@ -97,7 +96,7 @@ class RelayReader {
_clientEdgeTraversalPath: Array<ClientEdgeTraversalInfo | null>;
_isMissingData: boolean;
_missingClientEdges: Array<MissingClientEdgeRequestInfo>;
_missingLiveResolverFields: Array<MissingLiveResolverField>;
_missingLiveResolverFields: Array<DataID>;
_isWithinUnmatchedTypeRefinement: boolean;
_errorResponseFields: ?ErrorResponseFields;
_owner: RequestDescriptor;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<MissingLiveResolverField>,
+missingLiveResolverFields?: $ReadOnlyArray<DataID>,
+missingClientEdges: null | $ReadOnlyArray<MissingClientEdgeRequestInfo>,
+seenRecords: DataIDSet,
+selector: SingularReaderSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
});
Expand Down

0 comments on commit 81eab03

Please sign in to comment.