react-relay 17.0.0 → 18.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/ReactRelayContainerUtils.js.flow +2 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -1
  4. package/ReactRelayFragmentContainer.js.flow +2 -2
  5. package/ReactRelayPaginationContainer.js.flow +2 -2
  6. package/ReactRelayQueryRenderer.js.flow +1 -1
  7. package/ReactRelayQueryRendererContext.js.flow +1 -1
  8. package/ReactRelayRefetchContainer.js.flow +2 -2
  9. package/ReactRelayTypes.js.flow +45 -18
  10. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
  11. package/buildReactRelayContainer.js.flow +6 -5
  12. package/hooks.js +1 -1
  13. package/index.js +1 -1
  14. package/legacy.js +1 -1
  15. package/lib/relay-hooks/getConnectionState.js +47 -0
  16. package/lib/relay-hooks/legacy/FragmentResource.js +2 -6
  17. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  18. package/lib/relay-hooks/loadQuery.js +2 -14
  19. package/lib/relay-hooks/readFragmentInternal.js +2 -4
  20. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  21. package/lib/relay-hooks/useFragment.js +4 -7
  22. package/lib/relay-hooks/useFragmentInternal.js +6 -484
  23. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +477 -0
  24. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +499 -0
  25. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  26. package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
  27. package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
  28. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  29. package/lib/relay-hooks/useQueryLoader.js +9 -3
  30. package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
  31. package/multi-actor/ActorChange.js.flow +1 -1
  32. package/package.json +3 -3
  33. package/react-relay-hooks.js +2 -2
  34. package/react-relay-hooks.min.js +2 -2
  35. package/react-relay-legacy.js +1 -1
  36. package/react-relay-legacy.min.js +1 -1
  37. package/react-relay.js +2 -2
  38. package/react-relay.min.js +2 -2
  39. package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
  40. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
  41. package/relay-hooks/MatchContainer.js.flow +1 -1
  42. package/relay-hooks/ProfilerContext.js.flow +1 -1
  43. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  44. package/relay-hooks/getConnectionState.js.flow +97 -0
  45. package/relay-hooks/legacy/FragmentResource.js.flow +2 -13
  46. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  47. package/relay-hooks/loadQuery.js.flow +4 -28
  48. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  49. package/relay-hooks/readFragmentInternal.js.flow +1 -10
  50. package/relay-hooks/useEntryPointLoader.js.flow +3 -4
  51. package/relay-hooks/useFragment.js.flow +0 -5
  52. package/relay-hooks/useFragmentInternal.js.flow +19 -643
  53. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +656 -0
  54. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +718 -0
  55. package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
  56. package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
  57. package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
  58. package/relay-hooks/usePaginationFragment.js.flow +1 -1
  59. package/relay-hooks/usePreloadedQuery.js.flow +0 -5
  60. package/relay-hooks/useQueryLoader.js.flow +28 -5
  61. package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -0,0 +1,477 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
6
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
+ var _require = require('./QueryResource'),
8
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
9
+ var useRelayEnvironment = require('./useRelayEnvironment');
10
+ var invariant = require('invariant');
11
+ var _require2 = require('react'),
12
+ useDebugValue = _require2.useDebugValue,
13
+ useEffect = _require2.useEffect,
14
+ useMemo = _require2.useMemo,
15
+ useRef = _require2.useRef,
16
+ useState = _require2.useState;
17
+ var _require3 = require('relay-runtime'),
18
+ _require3$__internal = _require3.__internal,
19
+ fetchQueryInternal = _require3$__internal.fetchQuery,
20
+ getPromiseForActiveRequest = _require3$__internal.getPromiseForActiveRequest,
21
+ RelayFeatureFlags = _require3.RelayFeatureFlags,
22
+ areEqualSelectors = _require3.areEqualSelectors,
23
+ createOperationDescriptor = _require3.createOperationDescriptor,
24
+ getPendingOperationsForFragment = _require3.getPendingOperationsForFragment,
25
+ getSelector = _require3.getSelector,
26
+ getVariablesFromFragment = _require3.getVariablesFromFragment,
27
+ handlePotentialSnapshotErrors = _require3.handlePotentialSnapshotErrors,
28
+ recycleNodesInto = _require3.recycleNodesInto;
29
+ var warning = require("fbjs/lib/warning");
30
+ function isMissingData(state) {
31
+ if (state.kind === 'bailout') {
32
+ return false;
33
+ } else if (state.kind === 'singular') {
34
+ return state.snapshot.isMissingData;
35
+ } else {
36
+ return state.snapshots.some(function (s) {
37
+ return s.isMissingData;
38
+ });
39
+ }
40
+ }
41
+ function getMissingClientEdges(state) {
42
+ if (state.kind === 'bailout') {
43
+ return null;
44
+ } else if (state.kind === 'singular') {
45
+ var _state$snapshot$missi;
46
+ return (_state$snapshot$missi = state.snapshot.missingClientEdges) !== null && _state$snapshot$missi !== void 0 ? _state$snapshot$missi : null;
47
+ } else {
48
+ var edges = null;
49
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
50
+ _step;
51
+ try {
52
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
53
+ var snapshot = _step.value;
54
+ if (snapshot.missingClientEdges) {
55
+ var _edges;
56
+ edges = (_edges = edges) !== null && _edges !== void 0 ? _edges : [];
57
+ var _iterator2 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingClientEdges),
58
+ _step2;
59
+ try {
60
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
61
+ var edge = _step2.value;
62
+ edges.push(edge);
63
+ }
64
+ } catch (err) {
65
+ _iterator2.e(err);
66
+ } finally {
67
+ _iterator2.f();
68
+ }
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator.e(err);
73
+ } finally {
74
+ _iterator.f();
75
+ }
76
+ return edges;
77
+ }
78
+ }
79
+ function getSuspendingLiveResolver(state) {
80
+ if (state.kind === 'bailout') {
81
+ return null;
82
+ } else if (state.kind === 'singular') {
83
+ var _state$snapshot$missi2;
84
+ return (_state$snapshot$missi2 = state.snapshot.missingLiveResolverFields) !== null && _state$snapshot$missi2 !== void 0 ? _state$snapshot$missi2 : null;
85
+ } else {
86
+ var missingFields = null;
87
+ var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
88
+ _step3;
89
+ try {
90
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
91
+ var snapshot = _step3.value;
92
+ if (snapshot.missingLiveResolverFields) {
93
+ var _missingFields;
94
+ missingFields = (_missingFields = missingFields) !== null && _missingFields !== void 0 ? _missingFields : [];
95
+ var _iterator4 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingLiveResolverFields),
96
+ _step4;
97
+ try {
98
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
99
+ var edge = _step4.value;
100
+ missingFields.push(edge);
101
+ }
102
+ } catch (err) {
103
+ _iterator4.e(err);
104
+ } finally {
105
+ _iterator4.f();
106
+ }
107
+ }
108
+ }
109
+ } catch (err) {
110
+ _iterator3.e(err);
111
+ } finally {
112
+ _iterator3.f();
113
+ }
114
+ return missingFields;
115
+ }
116
+ }
117
+ function handlePotentialSnapshotErrorsForState(environment, state) {
118
+ if (state.kind === 'singular') {
119
+ handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
120
+ } else if (state.kind === 'plural') {
121
+ var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
122
+ _step5;
123
+ try {
124
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
125
+ var snapshot = _step5.value;
126
+ handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
127
+ }
128
+ } catch (err) {
129
+ _iterator5.e(err);
130
+ } finally {
131
+ _iterator5.f();
132
+ }
133
+ }
134
+ }
135
+ function handleMissedUpdates(environment, state) {
136
+ if (state.kind === 'bailout') {
137
+ return null;
138
+ }
139
+ var currentEpoch = environment.getStore().getEpoch();
140
+ if (currentEpoch === state.epoch) {
141
+ return null;
142
+ }
143
+ if (state.kind === 'singular') {
144
+ var currentSnapshot = environment.lookup(state.snapshot.selector);
145
+ var updatedData = recycleNodesInto(state.snapshot.data, currentSnapshot.data);
146
+ var updatedCurrentSnapshot = {
147
+ data: updatedData,
148
+ isMissingData: currentSnapshot.isMissingData,
149
+ missingClientEdges: currentSnapshot.missingClientEdges,
150
+ missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
151
+ seenRecords: currentSnapshot.seenRecords,
152
+ selector: currentSnapshot.selector,
153
+ errorResponseFields: currentSnapshot.errorResponseFields
154
+ };
155
+ return [updatedData !== state.snapshot.data, {
156
+ kind: 'singular',
157
+ snapshot: updatedCurrentSnapshot,
158
+ epoch: currentEpoch
159
+ }];
160
+ } else {
161
+ var didMissUpdates = false;
162
+ var currentSnapshots = [];
163
+ for (var index = 0; index < state.snapshots.length; index++) {
164
+ var snapshot = state.snapshots[index];
165
+ var _currentSnapshot = environment.lookup(snapshot.selector);
166
+ var _updatedData = recycleNodesInto(snapshot.data, _currentSnapshot.data);
167
+ var _updatedCurrentSnapshot = {
168
+ data: _updatedData,
169
+ isMissingData: _currentSnapshot.isMissingData,
170
+ missingClientEdges: _currentSnapshot.missingClientEdges,
171
+ missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
172
+ seenRecords: _currentSnapshot.seenRecords,
173
+ selector: _currentSnapshot.selector,
174
+ errorResponseFields: _currentSnapshot.errorResponseFields
175
+ };
176
+ if (_updatedData !== snapshot.data) {
177
+ didMissUpdates = true;
178
+ }
179
+ currentSnapshots.push(_updatedCurrentSnapshot);
180
+ }
181
+ !(currentSnapshots.length === state.snapshots.length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected same number of snapshots') : invariant(false) : void 0;
182
+ return [didMissUpdates, {
183
+ kind: 'plural',
184
+ snapshots: currentSnapshots,
185
+ epoch: currentEpoch
186
+ }];
187
+ }
188
+ }
189
+ function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
190
+ var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
191
+ var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
192
+ id: missingClientEdgeRequestInfo.clientEdgeDestinationID
193
+ });
194
+ var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
195
+ var QueryResource = getQueryResourceForEnvironment(environment);
196
+ var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
197
+ return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
198
+ }
199
+ function subscribeToSnapshot(environment, state, setState, hasPendingStateChanges) {
200
+ if (state.kind === 'bailout') {
201
+ return function () {};
202
+ } else if (state.kind === 'singular') {
203
+ var disposable = environment.subscribe(state.snapshot, function (latestSnapshot) {
204
+ setState(function (prevState) {
205
+ if (prevState.kind !== 'singular' || prevState.snapshot.selector !== latestSnapshot.selector) {
206
+ var updates = handleMissedUpdates(environment, prevState);
207
+ if (updates != null) {
208
+ var dataChanged = updates[0],
209
+ nextState = updates[1];
210
+ environment.__log({
211
+ name: 'useFragment.subscription.missedUpdates',
212
+ hasDataChanges: dataChanged
213
+ });
214
+ hasPendingStateChanges.current = dataChanged;
215
+ return dataChanged ? nextState : prevState;
216
+ } else {
217
+ return prevState;
218
+ }
219
+ }
220
+ hasPendingStateChanges.current = true;
221
+ return {
222
+ kind: 'singular',
223
+ snapshot: latestSnapshot,
224
+ epoch: environment.getStore().getEpoch()
225
+ };
226
+ });
227
+ });
228
+ return function () {
229
+ disposable.dispose();
230
+ };
231
+ } else {
232
+ var disposables = state.snapshots.map(function (snapshot, index) {
233
+ return environment.subscribe(snapshot, function (latestSnapshot) {
234
+ setState(function (prevState) {
235
+ var _prevState$snapshots$;
236
+ if (prevState.kind !== 'plural' || ((_prevState$snapshots$ = prevState.snapshots[index]) === null || _prevState$snapshots$ === void 0 ? void 0 : _prevState$snapshots$.selector) !== latestSnapshot.selector) {
237
+ var updates = handleMissedUpdates(environment, prevState);
238
+ if (updates != null) {
239
+ var dataChanged = updates[0],
240
+ nextState = updates[1];
241
+ environment.__log({
242
+ name: 'useFragment.subscription.missedUpdates',
243
+ hasDataChanges: dataChanged
244
+ });
245
+ hasPendingStateChanges.current = hasPendingStateChanges.current || dataChanged;
246
+ return dataChanged ? nextState : prevState;
247
+ } else {
248
+ return prevState;
249
+ }
250
+ }
251
+ var updated = (0, _toConsumableArray2["default"])(prevState.snapshots);
252
+ updated[index] = latestSnapshot;
253
+ hasPendingStateChanges.current = true;
254
+ return {
255
+ kind: 'plural',
256
+ snapshots: updated,
257
+ epoch: environment.getStore().getEpoch()
258
+ };
259
+ });
260
+ });
261
+ });
262
+ return function () {
263
+ var _iterator6 = (0, _createForOfIteratorHelper2["default"])(disposables),
264
+ _step6;
265
+ try {
266
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
267
+ var d = _step6.value;
268
+ d.dispose();
269
+ }
270
+ } catch (err) {
271
+ _iterator6.e(err);
272
+ } finally {
273
+ _iterator6.f();
274
+ }
275
+ };
276
+ }
277
+ }
278
+ function getFragmentState(environment, fragmentSelector) {
279
+ if (fragmentSelector == null) {
280
+ return {
281
+ kind: 'bailout'
282
+ };
283
+ } else if (fragmentSelector.kind === 'PluralReaderSelector') {
284
+ return {
285
+ kind: 'plural',
286
+ snapshots: fragmentSelector.selectors.map(function (s) {
287
+ return environment.lookup(s);
288
+ }),
289
+ epoch: environment.getStore().getEpoch()
290
+ };
291
+ } else {
292
+ return {
293
+ kind: 'singular',
294
+ snapshot: environment.lookup(fragmentSelector),
295
+ epoch: environment.getStore().getEpoch()
296
+ };
297
+ }
298
+ }
299
+ function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
300
+ var _fragmentNode$metadat, _fragmentNode$metadat2;
301
+ var fragmentSelector = useMemo(function () {
302
+ return getSelector(fragmentNode, fragmentRef);
303
+ }, [fragmentNode, fragmentRef]);
304
+ var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
305
+ if (isPlural) {
306
+ !(fragmentRef == null || 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.', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
307
+ } else {
308
+ !!Array.isArray(fragmentRef) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected fragment pointer%s for fragment `%s` not to be ' + 'an array, instead got `%s`. Add `@relay(plural: true)` ' + 'to fragment `%s` to allow the prop to be an array.', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
309
+ }
310
+ !(fragmentRef == null || isPlural && Array.isArray(fragmentRef) && fragmentRef.length === 0 || 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, hookDisplayName, fragmentNode.name, hookDisplayName) : invariant(false) : void 0;
311
+ var environment = useRelayEnvironment();
312
+ var _useState = useState(function () {
313
+ return getFragmentState(environment, fragmentSelector);
314
+ }),
315
+ _state = _useState[0],
316
+ setState = _useState[1];
317
+ var state = _state;
318
+ var _useState2 = useState(state),
319
+ _subscribedState = _useState2[0],
320
+ setSubscribedState = _useState2[1];
321
+ var subscribedState = _subscribedState;
322
+ var _useState3 = useState(fragmentSelector),
323
+ previousFragmentSelector = _useState3[0],
324
+ setPreviousFragmentSelector = _useState3[1];
325
+ var _useState4 = useState(environment),
326
+ previousEnvironment = _useState4[0],
327
+ setPreviousEnvironment = _useState4[1];
328
+ if (!areEqualSelectors(fragmentSelector, previousFragmentSelector) || environment !== previousEnvironment) {
329
+ setPreviousFragmentSelector(fragmentSelector);
330
+ setPreviousEnvironment(environment);
331
+ var newState = getFragmentState(environment, fragmentSelector);
332
+ setState(newState);
333
+ setSubscribedState(newState);
334
+ state = newState;
335
+ subscribedState = newState;
336
+ }
337
+ var committedFragmentSelectorRef = useRef(false);
338
+ useEffect(function () {
339
+ committedFragmentSelectorRef.current = fragmentSelector;
340
+ }, [fragmentSelector]);
341
+ if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
342
+ var _useMemo = useMemo(function () {
343
+ var missingClientEdges = getMissingClientEdges(state);
344
+ var clientEdgeQueries;
345
+ var activeRequestPromises = [];
346
+ if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
347
+ clientEdgeQueries = [];
348
+ var _iterator7 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
349
+ _step7;
350
+ try {
351
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
352
+ var edge = _step7.value;
353
+ var _handleMissingClientE = handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions),
354
+ queryResult = _handleMissingClientE[0],
355
+ requestPromise = _handleMissingClientE[1];
356
+ clientEdgeQueries.push(queryResult);
357
+ if (requestPromise != null) {
358
+ activeRequestPromises.push(requestPromise);
359
+ }
360
+ }
361
+ } catch (err) {
362
+ _iterator7.e(err);
363
+ } finally {
364
+ _iterator7.f();
365
+ }
366
+ }
367
+ return [clientEdgeQueries, activeRequestPromises];
368
+ }, [state, environment, fragmentNode, fragmentRef, queryOptions]),
369
+ clientEdgeQueries = _useMemo[0],
370
+ activeRequestPromises = _useMemo[1];
371
+ if (activeRequestPromises.length) {
372
+ throw Promise.all(activeRequestPromises);
373
+ }
374
+ useEffect(function () {
375
+ var QueryResource = getQueryResourceForEnvironment(environment);
376
+ if (clientEdgeQueries !== null && clientEdgeQueries !== void 0 && clientEdgeQueries.length) {
377
+ var disposables = [];
378
+ var _iterator8 = (0, _createForOfIteratorHelper2["default"])(clientEdgeQueries),
379
+ _step8;
380
+ try {
381
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
382
+ var query = _step8.value;
383
+ disposables.push(QueryResource.retain(query));
384
+ }
385
+ } catch (err) {
386
+ _iterator8.e(err);
387
+ } finally {
388
+ _iterator8.f();
389
+ }
390
+ return function () {
391
+ for (var _i = 0, _disposables = disposables; _i < _disposables.length; _i++) {
392
+ var disposable = _disposables[_i];
393
+ disposable.dispose();
394
+ }
395
+ };
396
+ }
397
+ }, [environment, clientEdgeQueries]);
398
+ }
399
+ if (isMissingData(state)) {
400
+ var suspendingLiveResolvers = getSuspendingLiveResolver(state);
401
+ if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
402
+ throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
403
+ var liveStateID = _ref.liveStateID;
404
+ return environment.getStore().getLiveResolverPromise(liveStateID);
405
+ }));
406
+ }
407
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
408
+ !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
409
+ var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
410
+ var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
411
+ if (pendingOperationsResult) {
412
+ throw pendingOperationsResult.promise;
413
+ }
414
+ }
415
+ }
416
+ handlePotentialSnapshotErrorsForState(environment, state);
417
+ var hasPendingStateChanges = useRef(false);
418
+ useEffect(function () {
419
+ var currentState = subscribedState;
420
+ var updates = handleMissedUpdates(environment, subscribedState);
421
+ if (updates !== null) {
422
+ var didMissUpdates = updates[0],
423
+ updatedState = updates[1];
424
+ if (didMissUpdates) {
425
+ setState(updatedState);
426
+ }
427
+ currentState = updatedState;
428
+ }
429
+ return subscribeToSnapshot(environment, currentState, setState, hasPendingStateChanges);
430
+ }, [environment, subscribedState]);
431
+ if (hasPendingStateChanges.current) {
432
+ var updates = handleMissedUpdates(environment, state);
433
+ if (updates != null) {
434
+ var hasStateUpdates = updates[0],
435
+ updatedState = updates[1];
436
+ if (hasStateUpdates) {
437
+ setState(updatedState);
438
+ state = updatedState;
439
+ }
440
+ }
441
+ hasPendingStateChanges.current = false;
442
+ }
443
+ var data;
444
+ if (isPlural) {
445
+ var fragmentRefIsNullish = fragmentRef == null;
446
+ data = useMemo(function () {
447
+ if (state.kind === 'bailout') {
448
+ return fragmentRefIsNullish ? null : [];
449
+ } else {
450
+ !(state.kind === 'plural') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be plural because fragment is plural') : invariant(false) : void 0;
451
+ return state.snapshots.map(function (s) {
452
+ return s.data;
453
+ });
454
+ }
455
+ }, [state, fragmentRefIsNullish]);
456
+ } else if (state.kind === 'bailout') {
457
+ data = null;
458
+ } else {
459
+ !(state.kind === 'singular') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be singular because fragment is singular') : invariant(false) : void 0;
460
+ data = state.snapshot.data;
461
+ }
462
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
463
+ if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
464
+ return d === undefined;
465
+ }))) {
466
+ process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected to have been able to read non-null data for ' + 'fragment `%s` declared in ' + '`%s`, since fragment reference was non-null. ' + "Make sure that that `%s`'s parent isn't " + 'holding on to and/or passing a fragment reference for data that ' + 'has been deleted.', fragmentNode.name, hookDisplayName, hookDisplayName) : void 0;
467
+ }
468
+ }
469
+ if (process.env.NODE_ENV !== "production") {
470
+ useDebugValue({
471
+ fragment: fragmentNode.name,
472
+ data: data
473
+ });
474
+ }
475
+ return data;
476
+ }
477
+ module.exports = useFragmentInternal;