react-relay 17.0.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) 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 +5 -5
  12. package/hooks.js +1 -1
  13. package/index.js +1 -1
  14. package/legacy.js +1 -1
  15. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  16. package/lib/relay-hooks/loadQuery.js +2 -14
  17. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  18. package/lib/relay-hooks/useFragment.js +4 -7
  19. package/lib/relay-hooks/useFragmentInternal.js +6 -484
  20. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +483 -0
  21. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
  22. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  23. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  24. package/lib/relay-hooks/useQueryLoader.js +1 -3
  25. package/multi-actor/ActorChange.js.flow +1 -1
  26. package/package.json +3 -3
  27. package/react-relay-hooks.js +2 -2
  28. package/react-relay-hooks.min.js +2 -2
  29. package/react-relay-legacy.js +1 -1
  30. package/react-relay-legacy.min.js +1 -1
  31. package/react-relay.js +2 -2
  32. package/react-relay.min.js +2 -2
  33. package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
  34. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
  35. package/relay-hooks/MatchContainer.js.flow +1 -1
  36. package/relay-hooks/ProfilerContext.js.flow +1 -1
  37. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  38. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  39. package/relay-hooks/loadQuery.js.flow +4 -28
  40. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  41. package/relay-hooks/useEntryPointLoader.js.flow +3 -4
  42. package/relay-hooks/useFragment.js.flow +0 -5
  43. package/relay-hooks/useFragmentInternal.js.flow +19 -643
  44. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +669 -0
  45. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
  46. package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
  47. package/relay-hooks/usePaginationFragment.js.flow +1 -1
  48. package/relay-hooks/usePreloadedQuery.js.flow +0 -5
  49. package/relay-hooks/useQueryLoader.js.flow +1 -2
@@ -0,0 +1,520 @@
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
+ var _state$snapshot$selec, _state$snapshot$selec2;
120
+ handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors, state.snapshot.errorResponseFields, (_state$snapshot$selec = (_state$snapshot$selec2 = state.snapshot.selector.node.metadata) === null || _state$snapshot$selec2 === void 0 ? void 0 : _state$snapshot$selec2.throwOnFieldError) !== null && _state$snapshot$selec !== void 0 ? _state$snapshot$selec : false);
121
+ } else if (state.kind === 'plural') {
122
+ var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
123
+ _step5;
124
+ try {
125
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
126
+ var _snapshot$selector$no, _snapshot$selector$no2;
127
+ var snapshot = _step5.value;
128
+ handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields, (_snapshot$selector$no = (_snapshot$selector$no2 = snapshot.selector.node.metadata) === null || _snapshot$selector$no2 === void 0 ? void 0 : _snapshot$selector$no2.throwOnFieldError) !== null && _snapshot$selector$no !== void 0 ? _snapshot$selector$no : false);
129
+ }
130
+ } catch (err) {
131
+ _iterator5.e(err);
132
+ } finally {
133
+ _iterator5.f();
134
+ }
135
+ }
136
+ }
137
+ function handleMissedUpdates(environment, state) {
138
+ if (state.kind === 'bailout') {
139
+ return null;
140
+ }
141
+ var currentEpoch = environment.getStore().getEpoch();
142
+ if (currentEpoch === state.epoch) {
143
+ return null;
144
+ }
145
+ if (state.kind === 'singular') {
146
+ var currentSnapshot = environment.lookup(state.snapshot.selector);
147
+ var updatedData = recycleNodesInto(state.snapshot.data, currentSnapshot.data);
148
+ var updatedCurrentSnapshot = {
149
+ data: updatedData,
150
+ isMissingData: currentSnapshot.isMissingData,
151
+ missingClientEdges: currentSnapshot.missingClientEdges,
152
+ missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
153
+ seenRecords: currentSnapshot.seenRecords,
154
+ selector: currentSnapshot.selector,
155
+ missingRequiredFields: currentSnapshot.missingRequiredFields,
156
+ relayResolverErrors: currentSnapshot.relayResolverErrors,
157
+ errorResponseFields: currentSnapshot.errorResponseFields
158
+ };
159
+ return [updatedData !== state.snapshot.data, {
160
+ kind: 'singular',
161
+ snapshot: updatedCurrentSnapshot,
162
+ epoch: currentEpoch,
163
+ selector: state.selector,
164
+ environment: state.environment
165
+ }];
166
+ } else {
167
+ var didMissUpdates = false;
168
+ var currentSnapshots = [];
169
+ for (var index = 0; index < state.snapshots.length; index++) {
170
+ var snapshot = state.snapshots[index];
171
+ var _currentSnapshot = environment.lookup(snapshot.selector);
172
+ var _updatedData = recycleNodesInto(snapshot.data, _currentSnapshot.data);
173
+ var _updatedCurrentSnapshot = {
174
+ data: _updatedData,
175
+ isMissingData: _currentSnapshot.isMissingData,
176
+ missingClientEdges: _currentSnapshot.missingClientEdges,
177
+ missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
178
+ seenRecords: _currentSnapshot.seenRecords,
179
+ selector: _currentSnapshot.selector,
180
+ missingRequiredFields: _currentSnapshot.missingRequiredFields,
181
+ relayResolverErrors: _currentSnapshot.relayResolverErrors,
182
+ errorResponseFields: _currentSnapshot.errorResponseFields
183
+ };
184
+ if (_updatedData !== snapshot.data) {
185
+ didMissUpdates = true;
186
+ }
187
+ currentSnapshots.push(_updatedCurrentSnapshot);
188
+ }
189
+ !(currentSnapshots.length === state.snapshots.length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected same number of snapshots') : invariant(false) : void 0;
190
+ return [didMissUpdates, {
191
+ kind: 'plural',
192
+ snapshots: currentSnapshots,
193
+ epoch: currentEpoch,
194
+ selector: state.selector,
195
+ environment: state.environment
196
+ }];
197
+ }
198
+ }
199
+ function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
200
+ var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
201
+ var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
202
+ id: missingClientEdgeRequestInfo.clientEdgeDestinationID
203
+ });
204
+ var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
205
+ var QueryResource = getQueryResourceForEnvironment(environment);
206
+ var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
207
+ return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
208
+ }
209
+ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
210
+ if (state.kind === 'bailout') {
211
+ return function () {};
212
+ } else if (state.kind === 'singular') {
213
+ var disposable = environment.subscribe(state.snapshot, function (latestSnapshot) {
214
+ setState(function (prevState) {
215
+ var nextState = null;
216
+ if (prevState.kind !== 'singular' || prevState.snapshot.selector !== latestSnapshot.selector || prevState.environment !== environment) {
217
+ var updates = handleMissedUpdates(prevState.environment, prevState);
218
+ if (updates != null) {
219
+ var dataChanged = updates[0],
220
+ updatedState = updates[1];
221
+ environment.__log({
222
+ name: 'useFragment.subscription.missedUpdates',
223
+ hasDataChanges: dataChanged
224
+ });
225
+ nextState = dataChanged ? updatedState : prevState;
226
+ } else {
227
+ nextState = prevState;
228
+ }
229
+ } else {
230
+ nextState = {
231
+ kind: 'singular',
232
+ snapshot: latestSnapshot,
233
+ epoch: environment.getStore().getEpoch(),
234
+ selector: state.selector,
235
+ environment: state.environment
236
+ };
237
+ }
238
+ pendingStateRef.current = nextState.kind === 'singular' ? nextState.epoch : null;
239
+ return nextState;
240
+ });
241
+ });
242
+ return function () {
243
+ disposable.dispose();
244
+ };
245
+ } else {
246
+ var disposables = state.snapshots.map(function (snapshot, index) {
247
+ return environment.subscribe(snapshot, function (latestSnapshot) {
248
+ setState(function (prevState) {
249
+ var _prevState$snapshots$;
250
+ var nextState = null;
251
+ if (prevState.kind !== 'plural' || ((_prevState$snapshots$ = prevState.snapshots[index]) === null || _prevState$snapshots$ === void 0 ? void 0 : _prevState$snapshots$.selector) !== latestSnapshot.selector || prevState.environment !== environment) {
252
+ var updates = handleMissedUpdates(prevState.environment, prevState);
253
+ if (updates != null) {
254
+ var dataChanged = updates[0],
255
+ updatedState = updates[1];
256
+ environment.__log({
257
+ name: 'useFragment.subscription.missedUpdates',
258
+ hasDataChanges: dataChanged
259
+ });
260
+ nextState = dataChanged ? updatedState : prevState;
261
+ } else {
262
+ nextState = prevState;
263
+ }
264
+ } else {
265
+ var updated = (0, _toConsumableArray2["default"])(prevState.snapshots);
266
+ updated[index] = latestSnapshot;
267
+ nextState = {
268
+ kind: 'plural',
269
+ snapshots: updated,
270
+ epoch: environment.getStore().getEpoch(),
271
+ selector: state.selector,
272
+ environment: state.environment
273
+ };
274
+ }
275
+ pendingStateRef.current = nextState.kind === 'plural' ? nextState.epoch : null;
276
+ return nextState;
277
+ });
278
+ });
279
+ });
280
+ return function () {
281
+ var _iterator6 = (0, _createForOfIteratorHelper2["default"])(disposables),
282
+ _step6;
283
+ try {
284
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
285
+ var d = _step6.value;
286
+ d.dispose();
287
+ }
288
+ } catch (err) {
289
+ _iterator6.e(err);
290
+ } finally {
291
+ _iterator6.f();
292
+ }
293
+ };
294
+ }
295
+ }
296
+ function getFragmentState(environment, fragmentSelector) {
297
+ if (fragmentSelector == null) {
298
+ return {
299
+ kind: 'bailout',
300
+ environment: environment
301
+ };
302
+ } else if (fragmentSelector.kind === 'PluralReaderSelector') {
303
+ return {
304
+ kind: 'plural',
305
+ snapshots: fragmentSelector.selectors.map(function (s) {
306
+ return environment.lookup(s);
307
+ }),
308
+ epoch: environment.getStore().getEpoch(),
309
+ selector: fragmentSelector,
310
+ environment: environment
311
+ };
312
+ } else {
313
+ return {
314
+ kind: 'singular',
315
+ snapshot: environment.lookup(fragmentSelector),
316
+ epoch: environment.getStore().getEpoch(),
317
+ selector: fragmentSelector,
318
+ environment: environment
319
+ };
320
+ }
321
+ }
322
+ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
323
+ var _fragmentNode$metadat, _fragmentNode$metadat2;
324
+ var fragmentSelector = useMemo(function () {
325
+ return getSelector(fragmentNode, fragmentRef);
326
+ }, [fragmentNode, fragmentRef]);
327
+ var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
328
+ if (isPlural) {
329
+ !(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;
330
+ } else {
331
+ !!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;
332
+ }
333
+ !(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;
334
+ var environment = useRelayEnvironment();
335
+ var _useState = useState(function () {
336
+ return getFragmentState(environment, fragmentSelector);
337
+ }),
338
+ _state = _useState[0],
339
+ setState = _useState[1];
340
+ var state = _state;
341
+ var previousEnvironment = state.environment;
342
+ if (!areEqualSelectors(fragmentSelector, state.selector) || environment !== state.environment) {
343
+ var newState = getFragmentState(environment, fragmentSelector);
344
+ setState(newState);
345
+ state = newState;
346
+ }
347
+ var committedFragmentSelectorRef = useRef(false);
348
+ useEffect(function () {
349
+ committedFragmentSelectorRef.current = fragmentSelector;
350
+ }, [fragmentSelector]);
351
+ if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
352
+ var _useMemo = useMemo(function () {
353
+ var missingClientEdges = getMissingClientEdges(state);
354
+ var clientEdgeQueries;
355
+ var activeRequestPromises = [];
356
+ if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
357
+ clientEdgeQueries = [];
358
+ var _iterator7 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
359
+ _step7;
360
+ try {
361
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
362
+ var edge = _step7.value;
363
+ var _handleMissingClientE = handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions),
364
+ queryResult = _handleMissingClientE[0],
365
+ requestPromise = _handleMissingClientE[1];
366
+ clientEdgeQueries.push(queryResult);
367
+ if (requestPromise != null) {
368
+ activeRequestPromises.push(requestPromise);
369
+ }
370
+ }
371
+ } catch (err) {
372
+ _iterator7.e(err);
373
+ } finally {
374
+ _iterator7.f();
375
+ }
376
+ }
377
+ return [clientEdgeQueries, activeRequestPromises];
378
+ }, [state, environment, fragmentNode, fragmentRef, queryOptions]),
379
+ clientEdgeQueries = _useMemo[0],
380
+ activeRequestPromises = _useMemo[1];
381
+ if (activeRequestPromises.length) {
382
+ throw Promise.all(activeRequestPromises);
383
+ }
384
+ useEffect(function () {
385
+ var QueryResource = getQueryResourceForEnvironment(environment);
386
+ if (clientEdgeQueries !== null && clientEdgeQueries !== void 0 && clientEdgeQueries.length) {
387
+ var disposables = [];
388
+ var _iterator8 = (0, _createForOfIteratorHelper2["default"])(clientEdgeQueries),
389
+ _step8;
390
+ try {
391
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
392
+ var query = _step8.value;
393
+ disposables.push(QueryResource.retain(query));
394
+ }
395
+ } catch (err) {
396
+ _iterator8.e(err);
397
+ } finally {
398
+ _iterator8.f();
399
+ }
400
+ return function () {
401
+ for (var _i = 0, _disposables = disposables; _i < _disposables.length; _i++) {
402
+ var disposable = _disposables[_i];
403
+ disposable.dispose();
404
+ }
405
+ };
406
+ }
407
+ }, [environment, clientEdgeQueries]);
408
+ }
409
+ if (isMissingData(state)) {
410
+ var suspendingLiveResolvers = getSuspendingLiveResolver(state);
411
+ if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
412
+ throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
413
+ var liveStateID = _ref.liveStateID;
414
+ return environment.getStore().getLiveResolverPromise(liveStateID);
415
+ }));
416
+ }
417
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
418
+ !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
419
+ var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
420
+ var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
421
+ if (pendingOperationsResult) {
422
+ throw pendingOperationsResult.promise;
423
+ }
424
+ }
425
+ }
426
+ handlePotentialSnapshotErrorsForState(environment, state);
427
+ var pendingStateEpochRef = useRef(null);
428
+ var storeSubscriptionRef = useRef(null);
429
+ useEffect(function () {
430
+ var storeSubscription = storeSubscriptionRef.current;
431
+ if (storeSubscription != null) {
432
+ if (state.environment === storeSubscription.environment && state.selector === storeSubscription.selector) {
433
+ return;
434
+ } else {
435
+ storeSubscription.dispose();
436
+ }
437
+ }
438
+ if (state.kind === 'bailout') {
439
+ return;
440
+ }
441
+ var stateForSubscription = state;
442
+ var updates = handleMissedUpdates(state.environment, state);
443
+ if (updates !== null) {
444
+ var didMissUpdates = updates[0],
445
+ updatedState = updates[1];
446
+ if (didMissUpdates) {
447
+ setState(updatedState);
448
+ return;
449
+ }
450
+ stateForSubscription = updatedState;
451
+ }
452
+ var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState, pendingStateEpochRef);
453
+ storeSubscriptionRef.current = {
454
+ dispose: dispose,
455
+ selector: state.selector,
456
+ environment: state.environment
457
+ };
458
+ }, [state]);
459
+ useEffect(function () {
460
+ if (storeSubscriptionRef.current == null && state.kind !== 'bailout') {
461
+ var dispose = subscribeToSnapshot(state.environment, state, setState, pendingStateEpochRef);
462
+ storeSubscriptionRef.current = {
463
+ dispose: dispose,
464
+ selector: state.selector,
465
+ environment: state.environment
466
+ };
467
+ }
468
+ return function () {
469
+ var _storeSubscriptionRef;
470
+ (_storeSubscriptionRef = storeSubscriptionRef.current) === null || _storeSubscriptionRef === void 0 ? void 0 : _storeSubscriptionRef.dispose();
471
+ storeSubscriptionRef.current = null;
472
+ };
473
+ }, []);
474
+ if (pendingStateEpochRef.current !== null && pendingStateEpochRef.current !== state.epoch) {
475
+ var updates = handleMissedUpdates(environment, state);
476
+ if (updates != null) {
477
+ var hasStateUpdates = updates[0],
478
+ updatedState = updates[1];
479
+ if (hasStateUpdates) {
480
+ setState(updatedState);
481
+ state = updatedState;
482
+ }
483
+ }
484
+ }
485
+ pendingStateEpochRef.current = null;
486
+ var data;
487
+ if (isPlural) {
488
+ var fragmentRefIsNullish = fragmentRef == null;
489
+ data = useMemo(function () {
490
+ if (state.kind === 'bailout') {
491
+ return fragmentRefIsNullish ? null : [];
492
+ } else {
493
+ !(state.kind === 'plural') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be plural because fragment is plural') : invariant(false) : void 0;
494
+ return state.snapshots.map(function (s) {
495
+ return s.data;
496
+ });
497
+ }
498
+ }, [state, fragmentRefIsNullish]);
499
+ } else if (state.kind === 'bailout') {
500
+ data = null;
501
+ } else {
502
+ !(state.kind === 'singular') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be singular because fragment is singular') : invariant(false) : void 0;
503
+ data = state.snapshot.data;
504
+ }
505
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
506
+ if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
507
+ return d === undefined;
508
+ }))) {
509
+ 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;
510
+ }
511
+ }
512
+ if (process.env.NODE_ENV !== "production") {
513
+ useDebugValue({
514
+ fragment: fragmentNode.name,
515
+ data: data
516
+ });
517
+ }
518
+ return data;
519
+ }
520
+ module.exports = useFragmentInternal_EXPERIMENTAL;
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var _require = require('./loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
3
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
6
4
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
7
5
  var useRelayEnvironment = require('./useRelayEnvironment');
8
- var _require2 = require('relay-runtime'),
9
- fetchQuery = _require2.__internal.fetchQuery;
6
+ var _require = require('relay-runtime'),
7
+ fetchQuery = _require.__internal.fetchQuery;
10
8
  function useLazyLoadQuery(gqlQuery, variables, options) {
11
- useTrackLoadQueryInRender();
12
9
  var environment = useRelayEnvironment();
13
10
  var query = useMemoOperationDescriptor(gqlQuery, variables, options && options.networkCacheConfig ? options.networkCacheConfig : {
14
11
  force: true
@@ -1,20 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var _require = require('./loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
3
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
6
4
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
7
5
  var useRelayEnvironment = require('./useRelayEnvironment');
8
6
  var invariant = require('invariant');
9
- var _require2 = require('react'),
10
- useDebugValue = _require2.useDebugValue;
11
- var _require3 = require('relay-runtime'),
12
- _require3$__internal = _require3.__internal,
13
- fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
14
- fetchQuery = _require3$__internal.fetchQuery;
7
+ var _require = require('react'),
8
+ useDebugValue = _require.useDebugValue;
9
+ var _require2 = require('relay-runtime'),
10
+ _require2$__internal = _require2.__internal,
11
+ fetchQueryDeduped = _require2$__internal.fetchQueryDeduped,
12
+ fetchQuery = _require2$__internal.fetchQuery;
15
13
  var warning = require("fbjs/lib/warning");
16
14
  function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
17
- useTrackLoadQueryInRender();
18
15
  var environment = useRelayEnvironment();
19
16
  var fetchKey = preloadedQuery.fetchKey,
20
17
  fetchPolicy = preloadedQuery.fetchPolicy,
@@ -3,8 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
4
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
5
5
  var _require = require('./loadQuery'),
6
- loadQuery = _require.loadQuery,
7
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
6
+ loadQuery = _require.loadQuery;
8
7
  var useIsMountedRef = require('./useIsMountedRef');
9
8
  var useRelayEnvironment = require('./useRelayEnvironment');
10
9
  var _require2 = require('react'),
@@ -27,7 +26,6 @@ function requestIsLiveQuery(preloadableRequest) {
27
26
  function useQueryLoader(preloadableRequest, initialQueryReference) {
28
27
  var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
29
28
  var environment = useRelayEnvironment();
30
- useTrackLoadQueryInRender();
31
29
  var isMountedRef = useIsMountedRef();
32
30
  var undisposedQueryReferencesRef = useRef(new Set([initialQueryReferenceInternal]));
33
31
  var _useState = useState(function () {
@@ -32,7 +32,7 @@ type ActorChangeProps<TFragmentRef> = {
32
32
 
33
33
  function ActorChange<TFragmentRef>(
34
34
  props: ActorChangeProps<TFragmentRef>,
35
- ): React.Element<typeof RelayEnvironmentProvider> {
35
+ ): React.MixedElement {
36
36
  const actorEnvironment = useRelayActorEnvironment(
37
37
  props.actorChangePoint.__viewer,
38
38
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-relay",
3
3
  "description": "A framework for building GraphQL-driven React applications.",
4
- "version": "17.0.0",
4
+ "version": "18.0.0",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay",
@@ -16,11 +16,11 @@
16
16
  "directory": "packages/react-relay"
17
17
  },
18
18
  "dependencies": {
19
- "@babel/runtime": "^7.0.0",
19
+ "@babel/runtime": "^7.25.0",
20
20
  "fbjs": "^3.0.2",
21
21
  "invariant": "^2.2.4",
22
22
  "nullthrows": "^1.1.1",
23
- "relay-runtime": "17.0.0"
23
+ "relay-runtime": "18.0.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.9.0 || ^17 || ^18"