react-relay 18.0.0 → 18.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayFragmentContainer.js.flow +2 -5
  3. package/buildReactRelayContainer.js.flow +1 -0
  4. package/hooks.js +1 -1
  5. package/index.js +1 -1
  6. package/index.js.flow +3 -0
  7. package/legacy.js +1 -1
  8. package/lib/index.js +2 -0
  9. package/lib/relay-hooks/getConnectionState.js +47 -0
  10. package/lib/relay-hooks/legacy/FragmentResource.js +3 -8
  11. package/lib/relay-hooks/loadQuery.js +5 -14
  12. package/lib/relay-hooks/readFragmentInternal.js +2 -4
  13. package/lib/relay-hooks/useFragmentInternal.js +1 -1
  14. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +3 -10
  15. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +6 -28
  16. package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
  17. package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
  18. package/lib/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js +227 -0
  19. package/lib/relay-hooks/useQueryLoader.js +8 -0
  20. package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
  21. package/package.json +2 -2
  22. package/react-relay-hooks.js +2 -2
  23. package/react-relay-hooks.min.js +2 -2
  24. package/react-relay-legacy.js +1 -1
  25. package/react-relay-legacy.min.js +1 -1
  26. package/react-relay.js +2 -2
  27. package/react-relay.min.js +2 -2
  28. package/relay-hooks/EntryPointTypes.flow.js.flow +2 -2
  29. package/relay-hooks/MatchContainer.js.flow +1 -1
  30. package/relay-hooks/getConnectionState.js.flow +97 -0
  31. package/relay-hooks/legacy/FragmentResource.js.flow +4 -16
  32. package/relay-hooks/loadQuery.js.flow +30 -38
  33. package/relay-hooks/readFragmentInternal.js.flow +1 -10
  34. package/relay-hooks/useFragmentInternal.js.flow +1 -1
  35. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +7 -22
  36. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +8 -56
  37. package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
  38. package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
  39. package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +433 -0
  40. package/relay-hooks/useQueryLoader.js.flow +27 -3
  41. package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v18.0.0
2
+ * Relay v18.2.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -270,14 +270,11 @@ function getRelayProp(environment: IEnvironment) {
270
270
  function createContainer<
271
271
  Props: {...},
272
272
  Instance,
273
- TComponent: React.AbstractComponent<Props, Instance>,
273
+ TComponent: component(ref: React.RefSetter<Instance>, ...Props),
274
274
  >(
275
275
  Component: TComponent,
276
276
  fragmentSpec: GeneratedNodeMap,
277
- ): React.AbstractComponent<
278
- $RelayProps<React.ElementConfig<TComponent>, RelayProp>,
279
- Instance,
280
- > {
277
+ ): component(ref: React.RefSetter<Instance>, ...$RelayProps<Props, RelayProp>) {
281
278
  // $FlowFixMe[incompatible-return]
282
279
  return buildReactRelayContainer(
283
280
  Component,
@@ -82,6 +82,7 @@ function buildReactRelayContainer<TBase: React.ComponentType<any>>(
82
82
  );
83
83
  }
84
84
  ForwardRef.displayName = containerName;
85
+ // $FlowFixMe[incompatible-call]
85
86
  const ForwardContainer = React.forwardRef(ForwardRef);
86
87
 
87
88
  if (__DEV__) {
package/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v18.0.0
2
+ * Relay v18.2.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v18.0.0
2
+ * Relay v18.2.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/index.js.flow CHANGED
@@ -28,6 +28,7 @@ const useFragment = require('./relay-hooks/useFragment');
28
28
  const useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
29
29
  const useMutation = require('./relay-hooks/useMutation');
30
30
  const usePaginationFragment = require('./relay-hooks/usePaginationFragment');
31
+ const usePrefetchableForwardPaginationFragment_EXPERIMENTAL = require('./relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL');
31
32
  const usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
32
33
  const useQueryLoader = require('./relay-hooks/useQueryLoader');
33
34
  const useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
@@ -125,6 +126,8 @@ module.exports = {
125
126
  usePaginationFragment: usePaginationFragment,
126
127
  usePreloadedQuery: usePreloadedQuery,
127
128
  useRefetchableFragment: useRefetchableFragment,
129
+ usePrefetchableForwardPaginationFragment_EXPERIMENTAL:
130
+ usePrefetchableForwardPaginationFragment_EXPERIMENTAL,
128
131
  useRelayEnvironment: useRelayEnvironment,
129
132
  useSubscribeToInvalidationState: useSubscribeToInvalidationState,
130
133
  useSubscription: useSubscription,
package/legacy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v18.0.0
2
+ * Relay v18.2.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ var useFragment = require('./relay-hooks/useFragment');
18
18
  var useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
19
19
  var useMutation = require('./relay-hooks/useMutation');
20
20
  var usePaginationFragment = require('./relay-hooks/usePaginationFragment');
21
+ var usePrefetchableForwardPaginationFragment_EXPERIMENTAL = require('./relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL');
21
22
  var usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
22
23
  var useQueryLoader = require('./relay-hooks/useQueryLoader');
23
24
  var useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
@@ -57,6 +58,7 @@ module.exports = {
57
58
  usePaginationFragment: usePaginationFragment,
58
59
  usePreloadedQuery: usePreloadedQuery,
59
60
  useRefetchableFragment: useRefetchableFragment,
61
+ usePrefetchableForwardPaginationFragment_EXPERIMENTAL: usePrefetchableForwardPaginationFragment_EXPERIMENTAL,
60
62
  useRelayEnvironment: useRelayEnvironment,
61
63
  useSubscribeToInvalidationState: useSubscribeToInvalidationState,
62
64
  useSubscription: useSubscription
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var invariant = require('invariant');
4
+ var _require = require('relay-runtime'),
5
+ ConnectionInterface = _require.ConnectionInterface,
6
+ getValueAtPath = _require.getValueAtPath;
7
+ function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
8
+ var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
9
+ var _ConnectionInterface$ = ConnectionInterface.get(),
10
+ EDGES = _ConnectionInterface$.EDGES,
11
+ PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
12
+ HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
13
+ HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
14
+ END_CURSOR = _ConnectionInterface$.END_CURSOR,
15
+ START_CURSOR = _ConnectionInterface$.START_CURSOR;
16
+ var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
17
+ if (connection == null) {
18
+ return {
19
+ cursor: null,
20
+ hasMore: false
21
+ };
22
+ }
23
+ !(typeof connection === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have been `null`, or ' + 'a plain object with %s and %s properties. Instead got `%s`.', fragmentNode.name, EDGES, PAGE_INFO, connection) : invariant(false) : void 0;
24
+ var edges = connection[EDGES];
25
+ var pageInfo = connection[PAGE_INFO];
26
+ if (edges == null || pageInfo == null) {
27
+ return {
28
+ cursor: null,
29
+ hasMore: false
30
+ };
31
+ }
32
+ !Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a plural `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, EDGES, edges) : invariant(false) : void 0;
33
+ !(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, PAGE_INFO, pageInfo) : invariant(false) : void 0;
34
+ var cursor = direction === 'forward' ? (_pageInfo$END_CURSOR = pageInfo[END_CURSOR]) !== null && _pageInfo$END_CURSOR !== void 0 ? _pageInfo$END_CURSOR : null : (_pageInfo$START_CURSO = pageInfo[START_CURSOR]) !== null && _pageInfo$START_CURSO !== void 0 ? _pageInfo$START_CURSO : null;
35
+ !(cursor === null || typeof cursor === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected page info for connection in fragment `%s` to have a ' + 'valid `%s`. Instead got `%s`.', fragmentNode.name, START_CURSOR, cursor) : invariant(false) : void 0;
36
+ var hasMore;
37
+ if (direction === 'forward') {
38
+ hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
39
+ } else {
40
+ hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
41
+ }
42
+ return {
43
+ cursor: cursor,
44
+ hasMore: hasMore
45
+ };
46
+ }
47
+ module.exports = getConnectionState;
@@ -243,8 +243,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
243
243
  var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
244
244
  var parentQueryPromiseResult = this._getAndSavePromiseForFragmentRequestInFlight(fragmentIdentifier, fragmentNode, fragmentOwner, fragmentResult);
245
245
  var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise;
246
- var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (_ref2) {
247
- var liveStateID = _ref2.liveStateID;
246
+ var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (liveStateID) {
248
247
  var store = environment.getStore();
249
248
  return store.getLiveResolverPromise(liveStateID);
250
249
  })) !== null && _missingLiveResolverF2 !== void 0 ? _missingLiveResolverF2 : [];
@@ -309,12 +308,10 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
309
308
  var _this4 = this;
310
309
  if (Array.isArray(snapshot)) {
311
310
  snapshot.forEach(function (s) {
312
- var _s$selector$node$meta, _s$selector$node$meta2;
313
- handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors, s.errorResponseFields, (_s$selector$node$meta = (_s$selector$node$meta2 = s.selector.node.metadata) === null || _s$selector$node$meta2 === void 0 ? void 0 : _s$selector$node$meta2.throwOnFieldError) !== null && _s$selector$node$meta !== void 0 ? _s$selector$node$meta : false);
311
+ handlePotentialSnapshotErrors(_this4._environment, s.errorResponseFields);
314
312
  });
315
313
  } else {
316
- var _snapshot$selector$no, _snapshot$selector$no2;
317
- handlePotentialSnapshotErrors(this._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);
314
+ handlePotentialSnapshotErrors(this._environment, snapshot.errorResponseFields);
318
315
  }
319
316
  };
320
317
  _proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
@@ -456,8 +453,6 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
456
453
  missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
457
454
  seenRecords: currentSnapshot.seenRecords,
458
455
  selector: currentSnapshot.selector,
459
- missingRequiredFields: currentSnapshot.missingRequiredFields,
460
- relayResolverErrors: currentSnapshot.relayResolverErrors,
461
456
  errorResponseFields: currentSnapshot.errorResponseFields
462
457
  };
463
458
  if (updatedData !== renderData) {
@@ -7,7 +7,6 @@ var _require = require('relay-runtime'),
7
7
  fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
8
8
  Observable = _require.Observable,
9
9
  PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
10
- RelayFeatureFlags = _require.RelayFeatureFlags,
11
10
  ReplaySubject = _require.ReplaySubject,
12
11
  createOperationDescriptor = _require.createOperationDescriptor,
13
12
  getRequest = _require.getRequest,
@@ -38,18 +37,12 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
38
37
  var didMakeNetworkRequest = false;
39
38
  var makeNetworkRequest = function makeNetworkRequest(params) {
40
39
  didMakeNetworkRequest = true;
41
- var observable;
42
40
  var subject = new ReplaySubject();
43
- if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
44
- var identifier = 'raw-network-request-' + getRequestIdentifier(params, variables);
45
- observable = fetchQueryDeduped(environment, identifier, function () {
46
- var network = environment.getNetwork();
47
- return network.execute(params, variables, networkCacheConfig);
48
- });
49
- } else {
41
+ var identifier = 'raw-network-request-' + getRequestIdentifier(params, variables);
42
+ var observable = fetchQueryDeduped(environment, identifier, function () {
50
43
  var network = environment.getNetwork();
51
- observable = network.execute(params, variables, networkCacheConfig);
52
- }
44
+ return network.execute(params, variables, networkCacheConfig);
45
+ });
53
46
  var _observable$subscribe = observable.subscribe({
54
47
  error: function error(err) {
55
48
  networkError = err;
@@ -74,9 +67,7 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
74
67
  };
75
68
  var unsubscribeFromExecution;
76
69
  var executeDeduped = function executeDeduped(operation, fetchFn) {
77
- if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
78
- didMakeNetworkRequest = true;
79
- }
70
+ didMakeNetworkRequest = true;
80
71
  var _fetchQueryDeduped$su = fetchQueryDeduped(environment, operation.request.identifier, fetchFn).subscribe({
81
72
  error: function error(err) {
82
73
  executionSubject.error(err);
@@ -66,16 +66,14 @@ function getMissingClientEdges(state) {
66
66
  }
67
67
  function handlePotentialSnapshotErrorsForState(environment, state) {
68
68
  if (state.kind === 'singular') {
69
- var _state$snapshot$selec, _state$snapshot$selec2;
70
- 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);
69
+ handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
71
70
  } else if (state.kind === 'plural') {
72
71
  var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
73
72
  _step3;
74
73
  try {
75
74
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
76
- var _snapshot$selector$no, _snapshot$selector$no2;
77
75
  var snapshot = _step3.value;
78
- 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);
76
+ handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
79
77
  }
80
78
  } catch (err) {
81
79
  _iterator3.e(err);
@@ -5,7 +5,7 @@ var _useFragmentInternal_CURRENT = _interopRequireDefault(require("./useFragment
5
5
  var _useFragmentInternal_EXPERIMENTAL = _interopRequireDefault(require("./useFragmentInternal_EXPERIMENTAL"));
6
6
  var _relayRuntime = require("relay-runtime");
7
7
  function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
8
- if (_relayRuntime.RelayFeatureFlags.ENABLE_USE_FRAGMENT_EXPERIMENTAL) {
8
+ if (_relayRuntime.RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
9
9
  return (0, _useFragmentInternal_EXPERIMENTAL["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
10
10
  }
11
11
  return (0, _useFragmentInternal_CURRENT["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
@@ -116,16 +116,14 @@ function getSuspendingLiveResolver(state) {
116
116
  }
117
117
  function handlePotentialSnapshotErrorsForState(environment, state) {
118
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);
119
+ handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
121
120
  } else if (state.kind === 'plural') {
122
121
  var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
123
122
  _step5;
124
123
  try {
125
124
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
126
- var _snapshot$selector$no, _snapshot$selector$no2;
127
125
  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);
126
+ handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
129
127
  }
130
128
  } catch (err) {
131
129
  _iterator5.e(err);
@@ -152,8 +150,6 @@ function handleMissedUpdates(environment, state) {
152
150
  missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
153
151
  seenRecords: currentSnapshot.seenRecords,
154
152
  selector: currentSnapshot.selector,
155
- missingRequiredFields: currentSnapshot.missingRequiredFields,
156
- relayResolverErrors: currentSnapshot.relayResolverErrors,
157
153
  errorResponseFields: currentSnapshot.errorResponseFields
158
154
  };
159
155
  return [updatedData !== state.snapshot.data, {
@@ -175,8 +171,6 @@ function handleMissedUpdates(environment, state) {
175
171
  missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
176
172
  seenRecords: _currentSnapshot.seenRecords,
177
173
  selector: _currentSnapshot.selector,
178
- missingRequiredFields: _currentSnapshot.missingRequiredFields,
179
- relayResolverErrors: _currentSnapshot.relayResolverErrors,
180
174
  errorResponseFields: _currentSnapshot.errorResponseFields
181
175
  };
182
176
  if (_updatedData !== snapshot.data) {
@@ -405,8 +399,7 @@ function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOp
405
399
  if (isMissingData(state)) {
406
400
  var suspendingLiveResolvers = getSuspendingLiveResolver(state);
407
401
  if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
408
- throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
409
- var liveStateID = _ref.liveStateID;
402
+ throw Promise.all(suspendingLiveResolvers.map(function (liveStateID) {
410
403
  return environment.getStore().getLiveResolverPromise(liveStateID);
411
404
  }));
412
405
  }
@@ -116,16 +116,14 @@ function getSuspendingLiveResolver(state) {
116
116
  }
117
117
  function handlePotentialSnapshotErrorsForState(environment, state) {
118
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);
119
+ handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
121
120
  } else if (state.kind === 'plural') {
122
121
  var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
123
122
  _step5;
124
123
  try {
125
124
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
126
- var _snapshot$selector$no, _snapshot$selector$no2;
127
125
  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);
126
+ handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
129
127
  }
130
128
  } catch (err) {
131
129
  _iterator5.e(err);
@@ -152,8 +150,6 @@ function handleMissedUpdates(environment, state) {
152
150
  missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
153
151
  seenRecords: currentSnapshot.seenRecords,
154
152
  selector: currentSnapshot.selector,
155
- missingRequiredFields: currentSnapshot.missingRequiredFields,
156
- relayResolverErrors: currentSnapshot.relayResolverErrors,
157
153
  errorResponseFields: currentSnapshot.errorResponseFields
158
154
  };
159
155
  return [updatedData !== state.snapshot.data, {
@@ -177,8 +173,6 @@ function handleMissedUpdates(environment, state) {
177
173
  missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
178
174
  seenRecords: _currentSnapshot.seenRecords,
179
175
  selector: _currentSnapshot.selector,
180
- missingRequiredFields: _currentSnapshot.missingRequiredFields,
181
- relayResolverErrors: _currentSnapshot.relayResolverErrors,
182
176
  errorResponseFields: _currentSnapshot.errorResponseFields
183
177
  };
184
178
  if (_updatedData !== snapshot.data) {
@@ -206,7 +200,7 @@ function handleMissingClientEdge(environment, parentFragmentNode, parentFragment
206
200
  var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
207
201
  return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
208
202
  }
209
- function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
203
+ function subscribeToSnapshot(environment, state, setState) {
210
204
  if (state.kind === 'bailout') {
211
205
  return function () {};
212
206
  } else if (state.kind === 'singular') {
@@ -235,7 +229,6 @@ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
235
229
  environment: state.environment
236
230
  };
237
231
  }
238
- pendingStateRef.current = nextState.kind === 'singular' ? nextState.epoch : null;
239
232
  return nextState;
240
233
  });
241
234
  });
@@ -272,7 +265,6 @@ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
272
265
  environment: state.environment
273
266
  };
274
267
  }
275
- pendingStateRef.current = nextState.kind === 'plural' ? nextState.epoch : null;
276
268
  return nextState;
277
269
  });
278
270
  });
@@ -409,8 +401,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
409
401
  if (isMissingData(state)) {
410
402
  var suspendingLiveResolvers = getSuspendingLiveResolver(state);
411
403
  if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
412
- throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
413
- var liveStateID = _ref.liveStateID;
404
+ throw Promise.all(suspendingLiveResolvers.map(function (liveStateID) {
414
405
  return environment.getStore().getLiveResolverPromise(liveStateID);
415
406
  }));
416
407
  }
@@ -424,7 +415,6 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
424
415
  }
425
416
  }
426
417
  handlePotentialSnapshotErrorsForState(environment, state);
427
- var pendingStateEpochRef = useRef(null);
428
418
  var storeSubscriptionRef = useRef(null);
429
419
  useEffect(function () {
430
420
  var storeSubscription = storeSubscriptionRef.current;
@@ -449,7 +439,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
449
439
  }
450
440
  stateForSubscription = updatedState;
451
441
  }
452
- var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState, pendingStateEpochRef);
442
+ var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState);
453
443
  storeSubscriptionRef.current = {
454
444
  dispose: dispose,
455
445
  selector: state.selector,
@@ -458,7 +448,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
458
448
  }, [state]);
459
449
  useEffect(function () {
460
450
  if (storeSubscriptionRef.current == null && state.kind !== 'bailout') {
461
- var dispose = subscribeToSnapshot(state.environment, state, setState, pendingStateEpochRef);
451
+ var dispose = subscribeToSnapshot(state.environment, state, setState);
462
452
  storeSubscriptionRef.current = {
463
453
  dispose: dispose,
464
454
  selector: state.selector,
@@ -471,18 +461,6 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
471
461
  storeSubscriptionRef.current = null;
472
462
  };
473
463
  }, []);
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
464
  var data;
487
465
  if (isPlural) {
488
466
  var fragmentRefIsNullish = fragmentRef == null;
@@ -2,9 +2,11 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
+ var getConnectionState = require('./getConnectionState');
5
6
  var useFetchTrackingRef = require('./useFetchTrackingRef');
6
7
  var useIsMountedRef = require('./useIsMountedRef');
7
8
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
9
+ var useLoadMoreFunction_EXPERIMENTAL = require('./useLoadMoreFunction_EXPERIMENTAL');
8
10
  var useRelayEnvironment = require('./useRelayEnvironment');
9
11
  var invariant = require('invariant');
10
12
  var _require = require('react'),
@@ -13,14 +15,19 @@ var _require = require('react'),
13
15
  useState = _require.useState;
14
16
  var _require2 = require('relay-runtime'),
15
17
  fetchQuery = _require2.__internal.fetchQuery,
16
- ConnectionInterface = _require2.ConnectionInterface,
18
+ RelayFeatureFlags = _require2.RelayFeatureFlags,
17
19
  createOperationDescriptor = _require2.createOperationDescriptor,
18
20
  getPaginationVariables = _require2.getPaginationVariables,
19
21
  getRefetchMetadata = _require2.getRefetchMetadata,
20
- getSelector = _require2.getSelector,
21
- getValueAtPath = _require2.getValueAtPath;
22
+ getSelector = _require2.getSelector;
22
23
  var warning = require("fbjs/lib/warning");
23
24
  function useLoadMoreFunction(args) {
25
+ if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
26
+ return useLoadMoreFunction_EXPERIMENTAL(args);
27
+ }
28
+ return useLoadMoreFunction_CURRENT(args);
29
+ }
30
+ function useLoadMoreFunction_CURRENT(args) {
24
31
  var direction = args.direction,
25
32
  fragmentNode = args.fragmentNode,
26
33
  fragmentRef = args.fragmentRef,
@@ -121,44 +128,4 @@ function useLoadMoreFunction(args) {
121
128
  }, [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
122
129
  return [loadMore, hasMore, disposeFetch];
123
130
  }
124
- function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
125
- var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
126
- var _ConnectionInterface$ = ConnectionInterface.get(),
127
- EDGES = _ConnectionInterface$.EDGES,
128
- PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
129
- HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
130
- HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
131
- END_CURSOR = _ConnectionInterface$.END_CURSOR,
132
- START_CURSOR = _ConnectionInterface$.START_CURSOR;
133
- var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
134
- if (connection == null) {
135
- return {
136
- cursor: null,
137
- hasMore: false
138
- };
139
- }
140
- !(typeof connection === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have been `null`, or ' + 'a plain object with %s and %s properties. Instead got `%s`.', fragmentNode.name, EDGES, PAGE_INFO, connection) : invariant(false) : void 0;
141
- var edges = connection[EDGES];
142
- var pageInfo = connection[PAGE_INFO];
143
- if (edges == null || pageInfo == null) {
144
- return {
145
- cursor: null,
146
- hasMore: false
147
- };
148
- }
149
- !Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a plural `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, EDGES, edges) : invariant(false) : void 0;
150
- !(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, PAGE_INFO, pageInfo) : invariant(false) : void 0;
151
- var cursor = direction === 'forward' ? (_pageInfo$END_CURSOR = pageInfo[END_CURSOR]) !== null && _pageInfo$END_CURSOR !== void 0 ? _pageInfo$END_CURSOR : null : (_pageInfo$START_CURSO = pageInfo[START_CURSOR]) !== null && _pageInfo$START_CURSO !== void 0 ? _pageInfo$START_CURSO : null;
152
- !(cursor === null || typeof cursor === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected page info for connection in fragment `%s` to have a ' + 'valid `%s`. Instead got `%s`.', fragmentNode.name, START_CURSOR, cursor) : invariant(false) : void 0;
153
- var hasMore;
154
- if (direction === 'forward') {
155
- hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
156
- } else {
157
- hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
158
- }
159
- return {
160
- cursor: cursor,
161
- hasMore: hasMore
162
- };
163
- }
164
131
  module.exports = useLoadMoreFunction;
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
+ var getConnectionState = require('./getConnectionState');
6
+ var useIsMountedRef = require('./useIsMountedRef');
7
+ var useIsOperationNodeActive = require('./useIsOperationNodeActive');
8
+ var useRelayEnvironment = require('./useRelayEnvironment');
9
+ var invariant = require('invariant');
10
+ var _require = require('react'),
11
+ useCallback = _require.useCallback,
12
+ useRef = _require.useRef,
13
+ useState = _require.useState;
14
+ var _require2 = require('relay-runtime'),
15
+ fetchQuery = _require2.__internal.fetchQuery,
16
+ createOperationDescriptor = _require2.createOperationDescriptor,
17
+ getPaginationVariables = _require2.getPaginationVariables,
18
+ getRefetchMetadata = _require2.getRefetchMetadata,
19
+ getSelector = _require2.getSelector;
20
+ var warning = require("fbjs/lib/warning");
21
+ function useLoadMoreFunction_EXPERIMENTAL(args) {
22
+ var direction = args.direction,
23
+ fragmentNode = args.fragmentNode,
24
+ fragmentRef = args.fragmentRef,
25
+ fragmentIdentifier = args.fragmentIdentifier,
26
+ fragmentData = args.fragmentData,
27
+ connectionPathInFragmentData = args.connectionPathInFragmentData,
28
+ paginationRequest = args.paginationRequest,
29
+ paginationMetadata = args.paginationMetadata,
30
+ componentDisplayName = args.componentDisplayName,
31
+ observer = args.observer,
32
+ onReset = args.onReset;
33
+ var environment = useRelayEnvironment();
34
+ var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
35
+ identifierInfo = _getRefetchMetadata.identifierInfo;
36
+ var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
37
+ var fetchStatusRef = useRef({
38
+ kind: 'none'
39
+ });
40
+ var _useState = useState(environment),
41
+ mirroredEnvironment = _useState[0],
42
+ setMirroredEnvironment = _useState[1];
43
+ var _useState2 = useState(fragmentIdentifier),
44
+ mirroredFragmentIdentifier = _useState2[0],
45
+ setMirroredFragmentIdentifier = _useState2[1];
46
+ var isParentQueryActive = useIsOperationNodeActive(fragmentNode, fragmentRef);
47
+ var forceDisposeFn = useCallback(function () {
48
+ if (fetchStatusRef.current.kind === 'fetching') {
49
+ fetchStatusRef.current.subscription.unsubscribe();
50
+ }
51
+ fetchStatusRef.current = {
52
+ kind: 'none'
53
+ };
54
+ }, []);
55
+ var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
56
+ if (shouldReset) {
57
+ forceDisposeFn();
58
+ onReset();
59
+ setMirroredEnvironment(environment);
60
+ setMirroredFragmentIdentifier(fragmentIdentifier);
61
+ }
62
+ var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
63
+ cursor = _getConnectionState.cursor,
64
+ hasMore = _getConnectionState.hasMore;
65
+ var isMountedRef = useIsMountedRef();
66
+ var loadMore = useCallback(function (count, options) {
67
+ var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
68
+ if (isMountedRef.current !== true) {
69
+ process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
70
+ return {
71
+ dispose: function dispose() {}
72
+ };
73
+ }
74
+ var fragmentSelector = getSelector(fragmentNode, fragmentRef);
75
+ if (fetchStatusRef.current.kind === 'fetching' || fragmentData == null || isParentQueryActive) {
76
+ if (fragmentSelector == null) {
77
+ process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch while using a null fragment ref ' + 'for fragment `%s` in `%s`. When fetching more items, we expect ' + "initial fragment data to be non-null. Please make sure you're " + 'passing a valid fragment ref to `%s` before paginating.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
78
+ }
79
+ if (onComplete) {
80
+ onComplete(null);
81
+ }
82
+ return {
83
+ dispose: function dispose() {}
84
+ };
85
+ }
86
+ !(fragmentSelector != null && fragmentSelector.kind !== 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to be able to find a non-plural fragment owner for ' + "fragment `%s` when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
87
+ var parentVariables = fragmentSelector.owner.variables;
88
+ var fragmentVariables = fragmentSelector.variables;
89
+ var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
90
+ var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
91
+ var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
92
+ if (identifierInfo != null) {
93
+ if (typeof identifierValue !== 'string') {
94
+ process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
95
+ }
96
+ paginationVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
97
+ }
98
+ var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
99
+ force: true
100
+ });
101
+ fetchQuery(environment, paginationQuery).subscribe((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, observer), {}, {
102
+ start: function start(subscription) {
103
+ fetchStatusRef.current = {
104
+ kind: 'fetching',
105
+ subscription: subscription
106
+ };
107
+ observer.start && observer.start(subscription);
108
+ },
109
+ complete: function complete() {
110
+ fetchStatusRef.current = {
111
+ kind: 'none'
112
+ };
113
+ observer.complete && observer.complete();
114
+ onComplete && onComplete(null);
115
+ },
116
+ error: function error(_error) {
117
+ fetchStatusRef.current = {
118
+ kind: 'none'
119
+ };
120
+ observer.complete && observer.complete();
121
+ onComplete && onComplete(_error);
122
+ }
123
+ }));
124
+ return {
125
+ dispose: function dispose() {}
126
+ };
127
+ }, [environment, identifierValue, direction, cursor, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
128
+ return [loadMore, hasMore, forceDisposeFn];
129
+ }
130
+ module.exports = useLoadMoreFunction_EXPERIMENTAL;