react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +2 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +10 -6
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,88 +1,56 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @emails oncall+relay
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
-
19
6
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
7
  var LRUCache = require('./LRUCache');
22
-
23
8
  var _require = require('./QueryResource'),
24
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
25
-
9
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
26
10
  var SuspenseResource = require('./SuspenseResource');
27
-
28
11
  var invariant = require('invariant');
29
-
30
12
  var _require2 = require('relay-runtime'),
31
- RelayFeatureFlags = _require2.RelayFeatureFlags,
32
- _require2$__internal = _require2.__internal,
33
- fetchQuery = _require2$__internal.fetchQuery,
34
- getPromiseForActiveRequest = _require2$__internal.getPromiseForActiveRequest,
35
- createOperationDescriptor = _require2.createOperationDescriptor,
36
- getFragmentIdentifier = _require2.getFragmentIdentifier,
37
- getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
38
- getSelector = _require2.getSelector,
39
- getVariablesFromFragment = _require2.getVariablesFromFragment,
40
- handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
41
- isPromise = _require2.isPromise,
42
- recycleNodesInto = _require2.recycleNodesInto;
43
-
13
+ _require2$__internal = _require2.__internal,
14
+ fetchQuery = _require2$__internal.fetchQuery,
15
+ getPromiseForActiveRequest = _require2$__internal.getPromiseForActiveRequest,
16
+ RelayFeatureFlags = _require2.RelayFeatureFlags,
17
+ createOperationDescriptor = _require2.createOperationDescriptor,
18
+ getFragmentIdentifier = _require2.getFragmentIdentifier,
19
+ getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
20
+ getSelector = _require2.getSelector,
21
+ getVariablesFromFragment = _require2.getVariablesFromFragment,
22
+ handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
23
+ isPromise = _require2.isPromise,
24
+ recycleNodesInto = _require2.recycleNodesInto;
44
25
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
45
- // TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
46
- // capacity, readSpec() will fail to find cached entries and break object
47
- // identity even if data hasn't changed.
48
- var CACHE_CAPACITY = 1000000; // this is frozen so that users don't accidentally push data into the array
49
-
26
+ var CACHE_CAPACITY = 1000000;
50
27
  var CONSTANT_READONLY_EMPTY_ARRAY = Object.freeze([]);
51
-
52
28
  function isMissingData(snapshot) {
53
29
  if (Array.isArray(snapshot)) {
54
30
  return snapshot.some(function (s) {
55
31
  return s.isMissingData;
56
32
  });
57
33
  }
58
-
59
34
  return snapshot.isMissingData;
60
35
  }
61
-
62
36
  function hasMissingClientEdges(snapshot) {
63
37
  var _snapshot$missingClie, _snapshot$missingClie2;
64
-
65
38
  if (Array.isArray(snapshot)) {
66
39
  return snapshot.some(function (s) {
67
40
  var _s$missingClientEdges, _s$missingClientEdges2;
68
-
69
41
  return ((_s$missingClientEdges = (_s$missingClientEdges2 = s.missingClientEdges) === null || _s$missingClientEdges2 === void 0 ? void 0 : _s$missingClientEdges2.length) !== null && _s$missingClientEdges !== void 0 ? _s$missingClientEdges : 0) > 0;
70
42
  });
71
43
  }
72
-
73
44
  return ((_snapshot$missingClie = (_snapshot$missingClie2 = snapshot.missingClientEdges) === null || _snapshot$missingClie2 === void 0 ? void 0 : _snapshot$missingClie2.length) !== null && _snapshot$missingClie !== void 0 ? _snapshot$missingClie : 0) > 0;
74
45
  }
75
-
76
46
  function missingLiveResolverFields(snapshot) {
77
47
  if (Array.isArray(snapshot)) {
78
48
  return snapshot.map(function (s) {
79
49
  return s.missingLiveResolverFields;
80
50
  }).filter(Boolean).flat();
81
51
  }
82
-
83
52
  return snapshot.missingLiveResolverFields;
84
53
  }
85
-
86
54
  function singularOrPluralForEach(snapshot, f) {
87
55
  if (Array.isArray(snapshot)) {
88
56
  snapshot.forEach(f);
@@ -90,7 +58,6 @@ function singularOrPluralForEach(snapshot, f) {
90
58
  f(snapshot);
91
59
  }
92
60
  }
93
-
94
61
  function getFragmentResult(cacheKey, snapshot, storeEpoch) {
95
62
  if (Array.isArray(snapshot)) {
96
63
  return {
@@ -103,7 +70,6 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
103
70
  storeEpoch: storeEpoch
104
71
  };
105
72
  }
106
-
107
73
  return {
108
74
  cacheKey: cacheKey,
109
75
  snapshot: snapshot,
@@ -112,120 +78,71 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
112
78
  storeEpoch: storeEpoch
113
79
  };
114
80
  }
115
- /**
116
- * The purpose of this cache is to allow information to be passed from an
117
- * initial read which suspends through to the commit that follows a subsequent
118
- * successful read. Specifically, the QueryResource result for the data fetch
119
- * is passed through so that that query can be retained on commit.
120
- */
121
-
122
-
123
81
  var ClientEdgeQueryResultsCache = /*#__PURE__*/function () {
124
82
  function ClientEdgeQueryResultsCache(environment) {
125
83
  (0, _defineProperty2["default"])(this, "_cache", new Map());
126
84
  (0, _defineProperty2["default"])(this, "_retainCounts", new Map());
127
85
  this._environment = environment;
128
86
  }
129
-
130
87
  var _proto = ClientEdgeQueryResultsCache.prototype;
131
-
132
88
  _proto.get = function get(fragmentIdentifier) {
133
89
  var _this$_cache$get$, _this$_cache$get;
134
-
135
90
  return (_this$_cache$get$ = (_this$_cache$get = this._cache.get(fragmentIdentifier)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get[0]) !== null && _this$_cache$get$ !== void 0 ? _this$_cache$get$ : undefined;
136
91
  };
137
-
138
- _proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value // may be mutated after being passed here
139
- ) {
92
+ _proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value) {
140
93
  var _this = this;
141
-
142
94
  var existing = this._cache.get(fragmentIdentifier);
143
-
144
95
  if (!existing) {
145
96
  var suspenseResource = new SuspenseResource(function () {
146
97
  return _this._retain(fragmentIdentifier);
147
98
  });
148
-
149
99
  this._cache.set(fragmentIdentifier, [value, suspenseResource]);
150
-
151
100
  suspenseResource.temporaryRetain(this._environment);
152
101
  } else {
153
102
  var existingResults = existing[0],
154
- _suspenseResource = existing[1];
103
+ _suspenseResource = existing[1];
155
104
  value.forEach(function (queryResult) {
156
105
  existingResults.push(queryResult);
157
106
  });
158
-
159
107
  _suspenseResource.temporaryRetain(this._environment);
160
108
  }
161
109
  };
162
-
163
110
  _proto._retain = function _retain(id) {
164
111
  var _this2 = this;
165
-
166
112
  var _this$_retainCounts$g;
167
-
168
113
  var retainCount = ((_this$_retainCounts$g = this._retainCounts.get(id)) !== null && _this$_retainCounts$g !== void 0 ? _this$_retainCounts$g : 0) + 1;
169
-
170
114
  this._retainCounts.set(id, retainCount);
171
-
172
115
  return {
173
116
  dispose: function dispose() {
174
117
  var _this$_retainCounts$g2;
175
-
176
118
  var newRetainCount = ((_this$_retainCounts$g2 = _this2._retainCounts.get(id)) !== null && _this$_retainCounts$g2 !== void 0 ? _this$_retainCounts$g2 : 0) - 1;
177
-
178
119
  if (newRetainCount > 0) {
179
120
  _this2._retainCounts.set(id, newRetainCount);
180
121
  } else {
181
122
  _this2._retainCounts["delete"](id);
182
-
183
123
  _this2._cache["delete"](id);
184
124
  }
185
125
  }
186
126
  };
187
127
  };
188
-
189
128
  return ClientEdgeQueryResultsCache;
190
129
  }();
191
-
192
130
  var FragmentResourceImpl = /*#__PURE__*/function () {
193
131
  function FragmentResourceImpl(environment) {
194
132
  this._environment = environment;
195
133
  this._cache = LRUCache.create(CACHE_CAPACITY);
196
-
197
134
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
198
135
  this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(environment);
199
136
  }
200
137
  }
201
- /**
202
- * This function should be called during a Component's render function,
203
- * to read the data for a fragment, or suspend if the fragment is being
204
- * fetched.
205
- */
206
-
207
-
208
138
  var _proto2 = FragmentResourceImpl.prototype;
209
-
210
139
  _proto2.read = function read(fragmentNode, fragmentRef, componentDisplayName, fragmentKey) {
211
140
  return this.readWithIdentifier(fragmentNode, fragmentRef, getFragmentIdentifier(fragmentNode, fragmentRef), componentDisplayName, fragmentKey);
212
- }
213
- /**
214
- * Like `read`, but with a pre-computed fragmentIdentifier that should be
215
- * equal to `getFragmentIdentifier(fragmentNode, fragmentRef)` from the
216
- * arguments.
217
- */
218
- ;
219
-
141
+ };
220
142
  _proto2.readWithIdentifier = function readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName, fragmentKey) {
221
143
  var _this3 = this;
222
-
223
144
  var _fragmentNode$metadat, _fragmentNode$metadat2, _missingLiveResolverF2, _missingLiveResolverF3;
224
-
225
- var environment = this._environment; // If fragmentRef is null or undefined, pass it directly through.
226
- // This is a convenience when consuming fragments via a HOC API, when the
227
- // prop corresponding to the fragment ref might be passed as null.
228
-
145
+ var environment = this._environment;
229
146
  if (fragmentRef == null) {
230
147
  return {
231
148
  cacheKey: fragmentIdentifier,
@@ -235,13 +152,9 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
235
152
  storeEpoch: 0
236
153
  };
237
154
  }
238
-
239
- var storeEpoch = environment.getStore().getEpoch(); // If fragmentRef is plural, ensure that it is an array.
240
- // If it's empty, return the empty array directly before doing any more work.
241
-
155
+ var storeEpoch = environment.getStore().getEpoch();
242
156
  if ((fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true) {
243
157
  !Array.isArray(fragmentRef) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected fragment pointer%s for fragment `%s` to be ' + 'an array, instead got `%s`. Remove `@relay(plural: true)` ' + 'from fragment `%s` to allow the prop to be an object.', fragmentKey != null ? " for key `".concat(fragmentKey, "`") : '', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
244
-
245
158
  if (fragmentRef.length === 0) {
246
159
  return {
247
160
  cacheKey: fragmentIdentifier,
@@ -251,15 +164,10 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
251
164
  storeEpoch: storeEpoch
252
165
  };
253
166
  }
254
- } // Now we actually attempt to read the fragment:
255
- // 1. Check if there's a cached value for this fragment
256
-
257
-
167
+ }
258
168
  var cachedValue = this._cache.get(fragmentIdentifier);
259
-
260
169
  if (cachedValue != null) {
261
170
  var _missingLiveResolverF;
262
-
263
171
  if (cachedValue.kind === 'pending' && isPromise(cachedValue.promise)) {
264
172
  environment.__log({
265
173
  name: 'suspense.fragment',
@@ -270,101 +178,80 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
270
178
  isPromiseCached: true,
271
179
  pendingOperations: cachedValue.pendingOperations
272
180
  });
273
-
274
181
  throw cachedValue.promise;
275
182
  }
276
-
277
183
  if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) !== null && _missingLiveResolverF !== void 0 && _missingLiveResolverF.length)) {
278
- this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
279
-
184
+ this._throwOrLogErrorsInSnapshot(cachedValue.result.snapshot);
185
+ if (cachedValue.result.isMissingData) {
186
+ environment.__log({
187
+ name: 'fragmentresource.missing_data',
188
+ data: cachedValue.result.data,
189
+ fragment: fragmentNode,
190
+ isRelayHooks: true,
191
+ cached: true
192
+ });
193
+ }
280
194
  return cachedValue.result;
281
195
  }
282
- } // 2. If not, try reading the fragment from the Relay store.
283
- // If the snapshot has data, return it and save it in cache
284
-
285
-
196
+ }
286
197
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
287
198
  !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to receive an object where `...%s` was spread, ' + 'but the fragment reference was not found`. This is most ' + 'likely the result of:\n' + "- Forgetting to spread `%s` in `%s`'s parent's fragment.\n" + '- Conditionally fetching `%s` but unconditionally passing %s prop ' + 'to `%s`. If the parent fragment only fetches the fragment conditionally ' + '- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' + 'spread - then the fragment reference will not exist. ' + 'In this case, pass `null` if the conditions for evaluating the ' + 'fragment are not met (e.g. if the `@include(if)` value is false.)', fragmentNode.name, fragmentNode.name, componentDisplayName, fragmentNode.name, fragmentKey == null ? 'a fragment reference' : "the `".concat(fragmentKey, "`"), componentDisplayName) : invariant(false) : void 0;
288
- var snapshot = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors.map(function (s) {
289
- return environment.lookup(s);
290
- }) : environment.lookup(fragmentSelector);
291
- var fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
292
-
199
+ var fragmentResult = null;
200
+ var snapshot = null;
201
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && cachedValue != null && cachedValue.kind === 'missing') {
202
+ fragmentResult = cachedValue.result;
203
+ snapshot = cachedValue.snapshot;
204
+ } else {
205
+ snapshot = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors.map(function (s) {
206
+ return environment.lookup(s);
207
+ }) : environment.lookup(fragmentSelector);
208
+ fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
209
+ }
293
210
  if (!fragmentResult.isMissingData) {
294
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
295
-
211
+ this._throwOrLogErrorsInSnapshot(snapshot);
296
212
  this._cache.set(fragmentIdentifier, {
297
213
  kind: 'done',
298
214
  result: fragmentResult
299
215
  });
300
-
301
216
  return fragmentResult;
302
- } // 3. If we don't have data in the store, there's two cases where we should
303
- // suspend to await the data: First if any client edges were traversed where
304
- // the destination record was missing data; in that case we initiate a query
305
- // here to fetch the missing data. Second, there may already be a request
306
- // in flight for the fragment's parent query, or for another operation that
307
- // may affect the parent's query data, such as a mutation or subscription.
308
- // For any of these cases we can get a promise, which we will cache and
309
- // suspend on.
310
- // First, initiate a query for any client edges that were missing data:
311
-
312
-
217
+ }
313
218
  var clientEdgeRequests = null;
314
-
315
219
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true && hasMissingClientEdges(snapshot)) {
316
220
  clientEdgeRequests = [];
317
221
  var queryResource = getQueryResourceForEnvironment(this._environment);
318
222
  var queryResults = [];
319
223
  singularOrPluralForEach(snapshot, function (snap) {
320
224
  var _snap$missingClientEd;
321
-
322
225
  (_snap$missingClientEd = snap.missingClientEdges) === null || _snap$missingClientEd === void 0 ? void 0 : _snap$missingClientEd.forEach(function (_ref) {
323
226
  var _clientEdgeRequests;
324
-
325
227
  var request = _ref.request,
326
- clientEdgeDestinationID = _ref.clientEdgeDestinationID;
327
-
228
+ clientEdgeDestinationID = _ref.clientEdgeDestinationID;
328
229
  var _this3$_performClient = _this3._performClientEdgeQuery(queryResource, fragmentNode, fragmentRef, request, clientEdgeDestinationID),
329
- queryResult = _this3$_performClient.queryResult,
330
- requestDescriptor = _this3$_performClient.requestDescriptor;
331
-
230
+ queryResult = _this3$_performClient.queryResult,
231
+ requestDescriptor = _this3$_performClient.requestDescriptor;
332
232
  queryResults.push(queryResult);
333
233
  (_clientEdgeRequests = clientEdgeRequests) === null || _clientEdgeRequests === void 0 ? void 0 : _clientEdgeRequests.push(requestDescriptor);
334
234
  });
335
- }); // Store the query so that it can be retained when our own fragment is
336
- // subscribed to. This merges with any existing query results:
337
-
235
+ });
338
236
  !(this._clientEdgeQueryResultsCache != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Client edge query result cache should exist when ENABLE_CLIENT_EDGES is on.') : invariant(false) : void 0;
339
-
340
237
  this._clientEdgeQueryResultsCache.recordQueryResults(fragmentIdentifier, queryResults);
341
238
  }
342
-
343
239
  var clientEdgePromises = [];
344
-
345
240
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && clientEdgeRequests) {
346
241
  clientEdgePromises = clientEdgeRequests.map(function (request) {
347
242
  return getPromiseForActiveRequest(_this3._environment, request);
348
243
  }).filter(Boolean);
349
- } // Finally look for operations in flight for our parent query:
350
-
351
-
244
+ }
352
245
  var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
353
-
354
246
  var parentQueryPromiseResult = this._getAndSavePromiseForFragmentRequestInFlight(fragmentIdentifier, fragmentNode, fragmentOwner, fragmentResult);
355
-
356
- var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise; // for refinement
357
-
247
+ var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise;
358
248
  var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (_ref2) {
359
249
  var liveStateID = _ref2.liveStateID;
360
- var store = environment.getStore(); // $FlowFixMe[prop-missing] This is expected to be a LiveResolverStore
361
-
250
+ var store = environment.getStore();
362
251
  return store.getLiveResolverPromise(liveStateID);
363
252
  })) !== null && _missingLiveResolverF2 !== void 0 ? _missingLiveResolverF2 : [];
364
-
365
253
  if (clientEdgePromises.length || missingResolverFieldPromises.length || isPromise(parentQueryPromiseResultPromise)) {
366
254
  var _parentQueryPromiseRe, _clientEdgeRequests2;
367
-
368
255
  environment.__log({
369
256
  name: 'suspense.fragment',
370
257
  data: fragmentResult.data,
@@ -372,61 +259,56 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
372
259
  isRelayHooks: true,
373
260
  isPromiseCached: false,
374
261
  isMissingData: fragmentResult.isMissingData,
375
- // TODO! Attach information here about missing live resolver fields
376
262
  pendingOperations: [].concat((0, _toConsumableArray2["default"])((_parentQueryPromiseRe = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.pendingOperations) !== null && _parentQueryPromiseRe !== void 0 ? _parentQueryPromiseRe : []), (0, _toConsumableArray2["default"])((_clientEdgeRequests2 = clientEdgeRequests) !== null && _clientEdgeRequests2 !== void 0 ? _clientEdgeRequests2 : []))
377
263
  });
378
-
379
264
  var promises = [];
380
-
381
265
  if (clientEdgePromises.length > 0) {
382
266
  promises = promises.concat(clientEdgePromises);
383
267
  }
384
-
385
268
  if (missingResolverFieldPromises.length > 0) {
386
269
  promises = promises.concat(missingResolverFieldPromises);
387
270
  }
388
-
389
271
  if (promises.length > 0) {
390
272
  if (parentQueryPromiseResultPromise) {
391
273
  promises.push(parentQueryPromiseResultPromise);
392
274
  }
393
-
394
275
  throw Promise.all(promises);
395
- } // Note: we are re-throwing the `parentQueryPromiseResultPromise` here,
396
- // because some of our suspense-related code is relying on the instance equality
397
- // of thrown promises. See FragmentResource-test.js
398
-
399
-
276
+ }
400
277
  if (parentQueryPromiseResultPromise) {
401
278
  throw parentQueryPromiseResultPromise;
402
279
  }
403
280
  }
404
-
405
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
406
-
281
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && fragmentResult.isMissingData) {
282
+ this._cache.set(fragmentIdentifier, {
283
+ kind: 'done',
284
+ result: fragmentResult
285
+ });
286
+ }
287
+ this._throwOrLogErrorsInSnapshot(snapshot);
288
+ environment.__log({
289
+ name: 'fragmentresource.missing_data',
290
+ data: fragmentResult.data,
291
+ fragment: fragmentNode,
292
+ isRelayHooks: true,
293
+ cached: false
294
+ });
407
295
  return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
408
296
  };
409
-
410
297
  _proto2._performClientEdgeQuery = function _performClientEdgeQuery(queryResource, fragmentNode, fragmentRef, request, clientEdgeDestinationID) {
411
298
  var originalVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
412
299
  var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
413
- id: clientEdgeDestinationID // TODO should be a reserved name
414
-
300
+ id: clientEdgeDestinationID
415
301
  });
416
- var operation = createOperationDescriptor(request, variables, {} // TODO cacheConfig should probably inherent from parent operation
417
- );
302
+ var operation = createOperationDescriptor(request, variables, {});
418
303
  var fetchObservable = fetchQuery(this._environment, operation);
419
- var queryResult = queryResource.prepare(operation, fetchObservable // TODO should inherent render policy etc. from parent operation
420
- );
304
+ var queryResult = queryResource.prepare(operation, fetchObservable);
421
305
  return {
422
306
  requestDescriptor: operation.request,
423
307
  queryResult: queryResult
424
308
  };
425
309
  };
426
-
427
- _proto2._handlePotentialSnapshotErrorsInSnapshot = function _handlePotentialSnapshotErrorsInSnapshot(snapshot) {
310
+ _proto2._throwOrLogErrorsInSnapshot = function _throwOrLogErrorsInSnapshot(snapshot) {
428
311
  var _this4 = this;
429
-
430
312
  if (Array.isArray(snapshot)) {
431
313
  snapshot.forEach(function (s) {
432
314
  handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors);
@@ -435,53 +317,36 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
435
317
  handlePotentialSnapshotErrors(this._environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
436
318
  }
437
319
  };
438
-
439
320
  _proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
440
321
  var result = {};
441
-
442
322
  for (var key in fragmentNodes) {
443
323
  result[key] = this.read(fragmentNodes[key], fragmentRefs[key], componentDisplayName, key);
444
324
  }
445
-
446
325
  return result;
447
326
  };
448
-
449
327
  _proto2.subscribe = function subscribe(fragmentResult, callback) {
450
328
  var _this5 = this;
451
-
452
329
  var environment = this._environment;
453
330
  var cacheKey = fragmentResult.cacheKey;
454
331
  var renderedSnapshot = fragmentResult.snapshot;
455
-
456
332
  if (!renderedSnapshot) {
457
333
  return {
458
334
  dispose: function dispose() {}
459
335
  };
460
- } // 1. Check for any updates missed during render phase
461
- // TODO(T44066760): More efficiently detect if we missed an update
462
-
463
-
336
+ }
464
337
  var _this$checkMissedUpda = this.checkMissedUpdates(fragmentResult),
465
- didMissUpdates = _this$checkMissedUpda[0],
466
- currentSnapshot = _this$checkMissedUpda[1]; // 2. If an update was missed, notify the component so it updates with
467
- // the latest data.
468
-
469
-
338
+ didMissUpdates = _this$checkMissedUpda[0],
339
+ currentSnapshot = _this$checkMissedUpda[1];
470
340
  if (didMissUpdates) {
471
341
  callback();
472
- } // 3. Establish subscriptions on the snapshot(s)
473
-
474
-
342
+ }
475
343
  var disposables = [];
476
-
477
344
  if (Array.isArray(renderedSnapshot)) {
478
345
  !Array.isArray(currentSnapshot) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected snapshots to be plural. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
479
346
  currentSnapshot.forEach(function (snapshot, idx) {
480
347
  disposables.push(environment.subscribe(snapshot, function (latestSnapshot) {
481
348
  var storeEpoch = environment.getStore().getEpoch();
482
-
483
349
  _this5._updatePluralSnapshot(cacheKey, currentSnapshot, latestSnapshot, idx, storeEpoch);
484
-
485
350
  callback();
486
351
  }));
487
352
  });
@@ -489,21 +354,25 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
489
354
  !(currentSnapshot != null && !Array.isArray(currentSnapshot)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected snapshot to be singular. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
490
355
  disposables.push(environment.subscribe(currentSnapshot, function (latestSnapshot) {
491
356
  var storeEpoch = environment.getStore().getEpoch();
492
-
493
- _this5._cache.set(cacheKey, {
494
- kind: 'done',
495
- result: getFragmentResult(cacheKey, latestSnapshot, storeEpoch)
496
- });
497
-
357
+ var result = getFragmentResult(cacheKey, latestSnapshot, storeEpoch);
358
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && result.isMissingData) {
359
+ _this5._cache.set(cacheKey, {
360
+ kind: 'missing',
361
+ result: result,
362
+ snapshot: latestSnapshot
363
+ });
364
+ } else {
365
+ _this5._cache.set(cacheKey, {
366
+ kind: 'done',
367
+ result: getFragmentResult(cacheKey, latestSnapshot, storeEpoch)
368
+ });
369
+ }
498
370
  callback();
499
371
  }));
500
372
  }
501
-
502
373
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
503
374
  var _this$_clientEdgeQuer, _this$_clientEdgeQuer2;
504
-
505
375
  var clientEdgeQueryResults = (_this$_clientEdgeQuer = (_this$_clientEdgeQuer2 = this._clientEdgeQueryResultsCache) === null || _this$_clientEdgeQuer2 === void 0 ? void 0 : _this$_clientEdgeQuer2.get(cacheKey)) !== null && _this$_clientEdgeQuer !== void 0 ? _this$_clientEdgeQuer : undefined;
506
-
507
376
  if (clientEdgeQueryResults !== null && clientEdgeQueryResults !== void 0 && clientEdgeQueryResults.length) {
508
377
  var queryResource = getQueryResourceForEnvironment(this._environment);
509
378
  clientEdgeQueryResults.forEach(function (queryResult) {
@@ -511,21 +380,17 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
511
380
  });
512
381
  }
513
382
  }
514
-
515
383
  return {
516
384
  dispose: function dispose() {
517
385
  disposables.forEach(function (s) {
518
386
  return s.dispose();
519
387
  });
520
-
521
388
  _this5._cache["delete"](cacheKey);
522
389
  }
523
390
  };
524
391
  };
525
-
526
392
  _proto2.subscribeSpec = function subscribeSpec(fragmentResults, callback) {
527
393
  var _this6 = this;
528
-
529
394
  var disposables = Object.keys(fragmentResults).map(function (key) {
530
395
  return _this6.subscribe(fragmentResults[key], callback);
531
396
  });
@@ -537,25 +402,18 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
537
402
  }
538
403
  };
539
404
  };
540
-
541
405
  _proto2.checkMissedUpdates = function checkMissedUpdates(fragmentResult) {
542
406
  var environment = this._environment;
543
407
  var renderedSnapshot = fragmentResult.snapshot;
544
-
545
408
  if (!renderedSnapshot) {
546
409
  return [false, null];
547
410
  }
548
-
549
- var storeEpoch = null; // Bail out if the store hasn't been written since last read
550
-
411
+ var storeEpoch = null;
551
412
  storeEpoch = environment.getStore().getEpoch();
552
-
553
413
  if (fragmentResult.storeEpoch === storeEpoch) {
554
414
  return [false, fragmentResult.snapshot];
555
415
  }
556
-
557
416
  var cacheKey = fragmentResult.cacheKey;
558
-
559
417
  if (Array.isArray(renderedSnapshot)) {
560
418
  var didMissUpdates = false;
561
419
  var currentSnapshots = [];
@@ -564,28 +422,31 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
564
422
  var renderData = snapshot.data;
565
423
  var currentData = currentSnapshot.data;
566
424
  var updatedData = recycleNodesInto(renderData, currentData);
567
-
568
425
  if (updatedData !== renderData) {
569
426
  currentSnapshot = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentSnapshot), {}, {
570
427
  data: updatedData
571
428
  });
572
429
  didMissUpdates = true;
573
430
  }
574
-
575
431
  currentSnapshots[idx] = currentSnapshot;
576
- }); // Only update the cache when the data is changed to avoid
577
- // returning different `data` instances
578
-
432
+ });
579
433
  if (didMissUpdates) {
580
- this._cache.set(cacheKey, {
581
- kind: 'done',
582
- result: getFragmentResult(cacheKey, currentSnapshots, storeEpoch)
583
- });
434
+ var result = getFragmentResult(cacheKey, currentSnapshots, storeEpoch);
435
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && result.isMissingData) {
436
+ this._cache.set(cacheKey, {
437
+ kind: 'missing',
438
+ result: result,
439
+ snapshot: currentSnapshots
440
+ });
441
+ } else {
442
+ this._cache.set(cacheKey, {
443
+ kind: 'done',
444
+ result: result
445
+ });
446
+ }
584
447
  }
585
-
586
448
  return [didMissUpdates, currentSnapshots];
587
449
  }
588
-
589
450
  var currentSnapshot = environment.lookup(renderedSnapshot.selector);
590
451
  var renderData = renderedSnapshot.data;
591
452
  var currentData = currentSnapshot.data;
@@ -600,111 +461,100 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
600
461
  missingRequiredFields: currentSnapshot.missingRequiredFields,
601
462
  relayResolverErrors: currentSnapshot.relayResolverErrors
602
463
  };
603
-
604
464
  if (updatedData !== renderData) {
605
- this._cache.set(cacheKey, {
606
- kind: 'done',
607
- result: getFragmentResult(cacheKey, updatedCurrentSnapshot, storeEpoch)
608
- });
465
+ var _result = getFragmentResult(cacheKey, updatedCurrentSnapshot, storeEpoch);
466
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && _result.isMissingData) {
467
+ this._cache.set(cacheKey, {
468
+ kind: 'missing',
469
+ result: _result,
470
+ snapshot: updatedCurrentSnapshot
471
+ });
472
+ } else {
473
+ this._cache.set(cacheKey, {
474
+ kind: 'done',
475
+ result: _result
476
+ });
477
+ }
609
478
  }
610
-
611
479
  return [updatedData !== renderData, updatedCurrentSnapshot];
612
480
  };
613
-
614
481
  _proto2.checkMissedUpdatesSpec = function checkMissedUpdatesSpec(fragmentResults) {
615
482
  var _this7 = this;
616
-
617
483
  return Object.keys(fragmentResults).some(function (key) {
618
484
  return _this7.checkMissedUpdates(fragmentResults[key])[0];
619
485
  });
620
486
  };
621
-
622
487
  _proto2._getAndSavePromiseForFragmentRequestInFlight = function _getAndSavePromiseForFragmentRequestInFlight(cacheKey, fragmentNode, fragmentOwner, fragmentResult) {
623
488
  var _this8 = this;
624
-
625
489
  var pendingOperationsResult = getPendingOperationsForFragment(this._environment, fragmentNode, fragmentOwner);
626
-
627
490
  if (pendingOperationsResult == null) {
628
491
  return null;
629
- } // When the Promise for the request resolves, we need to make sure to
630
- // update the cache with the latest data available in the store before
631
- // resolving the Promise
632
-
633
-
492
+ }
634
493
  var networkPromise = pendingOperationsResult.promise;
635
494
  var pendingOperations = pendingOperationsResult.pendingOperations;
636
495
  var promise = networkPromise.then(function () {
637
496
  _this8._cache["delete"](cacheKey);
638
497
  })["catch"](function (error) {
639
498
  _this8._cache["delete"](cacheKey);
640
- }); // $FlowExpectedError[prop-missing] Expando to annotate Promises.
641
-
499
+ });
642
500
  promise.displayName = networkPromise.displayName;
643
-
644
501
  this._cache.set(cacheKey, {
645
502
  kind: 'pending',
646
503
  pendingOperations: pendingOperations,
647
504
  promise: promise,
648
505
  result: fragmentResult
649
506
  });
650
-
651
507
  return {
652
508
  promise: promise,
653
509
  pendingOperations: pendingOperations
654
510
  };
655
511
  };
656
-
657
512
  _proto2._updatePluralSnapshot = function _updatePluralSnapshot(cacheKey, baseSnapshots, latestSnapshot, idx, storeEpoch) {
658
513
  var _currentFragmentResul;
659
-
660
514
  var currentFragmentResult = this._cache.get(cacheKey);
661
-
662
515
  if (isPromise(currentFragmentResult)) {
663
516
  reportInvalidCachedData(latestSnapshot.selector.node.name);
664
517
  return;
665
518
  }
666
-
667
519
  var currentSnapshot = currentFragmentResult === null || currentFragmentResult === void 0 ? void 0 : (_currentFragmentResul = currentFragmentResult.result) === null || _currentFragmentResul === void 0 ? void 0 : _currentFragmentResul.snapshot;
668
-
669
520
  if (currentSnapshot && !Array.isArray(currentSnapshot)) {
670
521
  reportInvalidCachedData(latestSnapshot.selector.node.name);
671
522
  return;
672
523
  }
673
-
674
524
  var nextSnapshots = currentSnapshot ? (0, _toConsumableArray2["default"])(currentSnapshot) : (0, _toConsumableArray2["default"])(baseSnapshots);
675
525
  nextSnapshots[idx] = latestSnapshot;
676
-
677
- this._cache.set(cacheKey, {
678
- kind: 'done',
679
- result: getFragmentResult(cacheKey, nextSnapshots, storeEpoch)
680
- });
526
+ var result = getFragmentResult(cacheKey, nextSnapshots, storeEpoch);
527
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE && result.isMissingData) {
528
+ this._cache.set(cacheKey, {
529
+ kind: 'missing',
530
+ result: result,
531
+ snapshot: nextSnapshots
532
+ });
533
+ } else {
534
+ this._cache.set(cacheKey, {
535
+ kind: 'done',
536
+ result: result
537
+ });
538
+ }
681
539
  };
682
-
683
540
  return FragmentResourceImpl;
684
541
  }();
685
-
686
542
  function reportInvalidCachedData(nodeName) {
687
543
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to find cached data for plural fragment `%s` when ' + 'receiving a subscription. ' + "If you're seeing this, this is likely a bug in Relay.", nodeName) : invariant(false) : void 0;
688
544
  }
689
-
690
545
  function createFragmentResource(environment) {
691
546
  return new FragmentResourceImpl(environment);
692
547
  }
693
-
694
548
  var dataResources = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
695
-
696
549
  function getFragmentResourceForEnvironment(environment) {
697
550
  var cached = dataResources.get(environment);
698
-
699
551
  if (cached) {
700
552
  return cached;
701
553
  }
702
-
703
554
  var newDataResource = createFragmentResource(environment);
704
555
  dataResources.set(environment, newDataResource);
705
556
  return newDataResource;
706
557
  }
707
-
708
558
  module.exports = {
709
559
  createFragmentResource: createFragmentResource,
710
560
  getFragmentResourceForEnvironment: getFragmentResourceForEnvironment