Skip to content

Commit

Permalink
Set the cache as missing state when missed updates
Browse files Browse the repository at this point in the history
Differential Revision: D47029820

fbshipit-source-id: a6e014f96b4398440a519a4392e6a3eafdff7bce
  • Loading branch information
yczhu authored and facebook-github-bot committed Jul 18, 2023
1 parent b09fd94 commit 64b707d
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions packages/react-relay/relay-hooks/FragmentResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,26 @@ class FragmentResourceImpl {
// Only update the cache when the data is changed to avoid
// returning different `data` instances
if (didMissUpdates) {
this._cache.set(cacheKey, {
kind: 'done',
result: getFragmentResult(cacheKey, currentSnapshots, storeEpoch),
});
const result = getFragmentResult(
cacheKey,
currentSnapshots,
storeEpoch,
);
if (
RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE &&
result.isMissingData
) {
this._cache.set(cacheKey, {
kind: 'missing',
result,
snapshot: currentSnapshots,
});
} else {
this._cache.set(cacheKey, {
kind: 'done',
result,
});
}
}
return [didMissUpdates, currentSnapshots];
}
Expand All @@ -762,10 +778,26 @@ class FragmentResourceImpl {
relayResolverErrors: currentSnapshot.relayResolverErrors,
};
if (updatedData !== renderData) {
this._cache.set(cacheKey, {
kind: 'done',
result: getFragmentResult(cacheKey, updatedCurrentSnapshot, storeEpoch),
});
const result = getFragmentResult(
cacheKey,
updatedCurrentSnapshot,
storeEpoch,
);
if (
RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE &&
result.isMissingData
) {
this._cache.set(cacheKey, {
kind: 'missing',
result: result,
snapshot: updatedCurrentSnapshot,
});
} else {
this._cache.set(cacheKey, {
kind: 'done',
result,
});
}
}
return [updatedData !== renderData, updatedCurrentSnapshot];
}
Expand Down

0 comments on commit 64b707d

Please sign in to comment.