react-relay 11.0.2 → 13.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/README.md +47 -0
  2. package/ReactRelayContainerUtils.js.flow +1 -1
  3. package/ReactRelayContext.js +1 -1
  4. package/ReactRelayContext.js.flow +3 -4
  5. package/ReactRelayFragmentContainer.js.flow +25 -25
  6. package/ReactRelayFragmentMockRenderer.js.flow +2 -2
  7. package/ReactRelayLocalQueryRenderer.js.flow +7 -8
  8. package/ReactRelayPaginationContainer.js.flow +112 -59
  9. package/ReactRelayQueryFetcher.js.flow +10 -11
  10. package/ReactRelayQueryRenderer.js.flow +116 -82
  11. package/ReactRelayQueryRendererContext.js.flow +1 -1
  12. package/ReactRelayRefetchContainer.js.flow +42 -39
  13. package/ReactRelayTestMocker.js.flow +17 -15
  14. package/ReactRelayTypes.js.flow +11 -11
  15. package/RelayContext.js.flow +4 -4
  16. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
  17. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
  18. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
  19. package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
  20. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
  21. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
  22. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
  23. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
  25. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
  27. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
  29. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
  30. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
  31. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
  32. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
  33. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
  34. package/assertFragmentMap.js.flow +3 -3
  35. package/buildReactRelayContainer.js.flow +12 -11
  36. package/getRootVariablesForFragments.js.flow +3 -5
  37. package/hooks.js +1 -1
  38. package/hooks.js.flow +6 -7
  39. package/index.js +1 -1
  40. package/index.js.flow +7 -8
  41. package/isRelayEnvironment.js.flow +1 -1
  42. package/jest-react/enqueueTask.js.flow +56 -0
  43. package/jest-react/index.js.flow +12 -0
  44. package/jest-react/internalAct.js.flow +138 -0
  45. package/legacy.js +1 -1
  46. package/legacy.js.flow +1 -1
  47. package/lib/ReactRelayContainerUtils.js +1 -1
  48. package/lib/ReactRelayContext.js +1 -1
  49. package/lib/ReactRelayFragmentContainer.js +22 -16
  50. package/lib/ReactRelayFragmentMockRenderer.js +3 -3
  51. package/lib/ReactRelayLocalQueryRenderer.js +8 -9
  52. package/lib/ReactRelayPaginationContainer.js +97 -39
  53. package/lib/ReactRelayQueryFetcher.js +3 -3
  54. package/lib/ReactRelayQueryRenderer.js +87 -54
  55. package/lib/ReactRelayQueryRendererContext.js +1 -1
  56. package/lib/ReactRelayRefetchContainer.js +39 -26
  57. package/lib/ReactRelayTestMocker.js +8 -9
  58. package/lib/ReactRelayTypes.js +1 -1
  59. package/lib/RelayContext.js +4 -3
  60. package/lib/assertFragmentMap.js +3 -2
  61. package/lib/buildReactRelayContainer.js +8 -8
  62. package/lib/getRootVariablesForFragments.js +2 -3
  63. package/lib/hooks.js +6 -6
  64. package/lib/index.js +8 -8
  65. package/lib/isRelayEnvironment.js +1 -1
  66. package/lib/jest-react/enqueueTask.js +53 -0
  67. package/lib/jest-react/index.js +13 -0
  68. package/lib/jest-react/internalAct.js +115 -0
  69. package/lib/legacy.js +1 -1
  70. package/lib/multi-actor/ActorChange.js +30 -0
  71. package/lib/multi-actor/index.js +11 -0
  72. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  73. package/lib/readContext.js +1 -1
  74. package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
  75. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
  76. package/lib/relay-hooks/FragmentResource.js +342 -89
  77. package/lib/relay-hooks/InternalLogger.js +1 -1
  78. package/lib/relay-hooks/LRUCache.js +1 -1
  79. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
  80. package/lib/relay-hooks/MatchContainer.js +2 -2
  81. package/lib/relay-hooks/ProfilerContext.js +1 -1
  82. package/lib/relay-hooks/QueryResource.js +172 -29
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
  84. package/lib/relay-hooks/SuspenseResource.js +130 -0
  85. package/lib/relay-hooks/loadEntryPoint.js +1 -1
  86. package/lib/relay-hooks/loadQuery.js +42 -20
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
  89. package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
  90. package/lib/relay-hooks/useEntryPointLoader.js +3 -3
  91. package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
  92. package/lib/relay-hooks/useFragment.js +7 -7
  93. package/lib/relay-hooks/useFragmentNode.js +5 -5
  94. package/lib/relay-hooks/useIsMountedRef.js +1 -1
  95. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  96. package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
  97. package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
  98. package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
  99. package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
  100. package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
  101. package/lib/relay-hooks/useMemoVariables.js +3 -3
  102. package/lib/relay-hooks/useMutation.js +18 -7
  103. package/lib/relay-hooks/usePaginationFragment.js +3 -4
  104. package/lib/relay-hooks/usePreloadedQuery.js +6 -6
  105. package/lib/relay-hooks/useQueryLoader.js +31 -11
  106. package/lib/relay-hooks/useRefetchableFragment.js +1 -1
  107. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
  108. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  109. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
  110. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
  111. package/lib/relay-hooks/useSubscription.js +11 -8
  112. package/multi-actor/ActorChange.js.flow +58 -0
  113. package/multi-actor/index.js.flow +14 -0
  114. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  115. package/package.json +3 -3
  116. package/react-relay-hooks.js +2 -2
  117. package/react-relay-hooks.min.js +2 -2
  118. package/react-relay-legacy.js +2 -2
  119. package/react-relay-legacy.min.js +2 -2
  120. package/react-relay.js +2 -2
  121. package/react-relay.min.js +2 -2
  122. package/readContext.js.flow +1 -1
  123. package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
  125. package/relay-hooks/FragmentResource.js.flow +359 -93
  126. package/relay-hooks/InternalLogger.js.flow +1 -1
  127. package/relay-hooks/LRUCache.js.flow +1 -1
  128. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
  129. package/relay-hooks/MatchContainer.js.flow +4 -3
  130. package/relay-hooks/ProfilerContext.js.flow +1 -1
  131. package/relay-hooks/QueryResource.js.flow +217 -26
  132. package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
  133. package/relay-hooks/SuspenseResource.js.flow +115 -0
  134. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
  135. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  136. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
  138. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
  139. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
  140. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
  141. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
  142. package/relay-hooks/__flowtests__/utils.js.flow +21 -32
  143. package/relay-hooks/loadEntryPoint.js.flow +7 -13
  144. package/relay-hooks/loadQuery.js.flow +50 -32
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
  147. package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
  148. package/relay-hooks/useEntryPointLoader.js.flow +8 -11
  149. package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
  150. package/relay-hooks/useFragment.js.flow +31 -62
  151. package/relay-hooks/useFragmentNode.js.flow +6 -8
  152. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  153. package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
  154. package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
  155. package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
  156. package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
  157. package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
  158. package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
  159. package/relay-hooks/useMemoVariables.js.flow +7 -7
  160. package/relay-hooks/useMutation.js.flow +27 -27
  161. package/relay-hooks/usePaginationFragment.js.flow +39 -45
  162. package/relay-hooks/usePreloadedQuery.js.flow +14 -20
  163. package/relay-hooks/useQueryLoader.js.flow +42 -23
  164. package/relay-hooks/useRefetchableFragment.js.flow +8 -9
  165. package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
  166. package/relay-hooks/useRelayEnvironment.js.flow +3 -5
  167. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
  168. package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
  169. package/relay-hooks/useSubscription.js.flow +21 -11
  170. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  171. package/lib/relay-hooks/getPaginationVariables.js +0 -67
  172. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  173. package/lib/relay-hooks/getValueAtPath.js +0 -51
  174. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  175. package/relay-hooks/getPaginationVariables.js.flow +0 -110
  176. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  177. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -14,21 +14,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
16
 
17
- var React = require('react');
18
-
19
17
  var invariant = require('invariant');
20
18
 
21
- var warning = require("fbjs/lib/warning");
19
+ var React = require('react');
22
20
 
23
21
  var _require = require('relay-runtime'),
22
+ Observable = _require.Observable,
24
23
  PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
24
+ RelayFeatureFlags = _require.RelayFeatureFlags,
25
25
  ReplaySubject = _require.ReplaySubject,
26
+ fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
26
27
  createOperationDescriptor = _require.createOperationDescriptor,
27
28
  getRequest = _require.getRequest,
28
- getRequestIdentifier = _require.getRequestIdentifier,
29
- Observable = _require.Observable,
30
- RelayFeatureFlags = _require.RelayFeatureFlags,
31
- fetchQueryDeduped = _require.__internal.fetchQueryDeduped;
29
+ getRequestIdentifier = _require.getRequestIdentifier;
30
+
31
+ var warning = require("fbjs/lib/warning");
32
32
 
33
33
  var RenderDispatcher = null;
34
34
  var fetchKey = 100001;
@@ -252,10 +252,9 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
252
252
  // ast, and we know that if we don't have the query ast
253
253
  // available, then this query could've never been written to the
254
254
  // store in the first place, so it couldn't have been cached.
255
- var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params);
255
+ var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
256
256
 
257
- var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad( // $FlowFixMe[incompatible-call]
258
- queryId, function (preloadedModule) {
257
+ var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad(queryId, function (preloadedModule) {
259
258
  cancelOnLoadCallback();
260
259
  var operation = createOperationDescriptor(preloadedModule, variables, networkCacheConfig);
261
260
  retainReference = environment.retain(operation);
@@ -278,6 +277,33 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
278
277
  }
279
278
 
280
279
  var isDisposed = false;
280
+ var isReleased = false;
281
+ var isNetworkRequestCancelled = false;
282
+
283
+ var releaseQuery = function releaseQuery() {
284
+ if (isReleased) {
285
+ return;
286
+ }
287
+
288
+ retainReference && retainReference.dispose();
289
+ isReleased = true;
290
+ };
291
+
292
+ var cancelNetworkRequest = function cancelNetworkRequest() {
293
+ if (isNetworkRequestCancelled) {
294
+ return;
295
+ }
296
+
297
+ if (didExecuteNetworkSource) {
298
+ unsubscribeFromExecution && unsubscribeFromExecution();
299
+ } else {
300
+ unsubscribeFromNetworkRequest && unsubscribeFromNetworkRequest();
301
+ }
302
+
303
+ cancelOnLoadCallback && cancelOnLoadCallback();
304
+ isNetworkRequestCancelled = true;
305
+ };
306
+
281
307
  return {
282
308
  kind: 'PreloadedQuery',
283
309
  environment: environment,
@@ -287,22 +313,18 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
287
313
  return;
288
314
  }
289
315
 
290
- if (didExecuteNetworkSource) {
291
- unsubscribeFromExecution && unsubscribeFromExecution();
292
- } else {
293
- unsubscribeFromNetworkRequest && unsubscribeFromNetworkRequest();
294
- }
295
-
296
- retainReference && retainReference.dispose();
297
- cancelOnLoadCallback && cancelOnLoadCallback();
316
+ releaseQuery();
317
+ cancelNetworkRequest();
298
318
  isDisposed = true;
299
319
  },
320
+ releaseQuery: releaseQuery,
321
+ cancelNetworkRequest: cancelNetworkRequest,
300
322
  fetchKey: fetchKey,
301
323
  id: queryId,
302
324
 
303
325
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
304
326
  get isDisposed() {
305
- return isDisposed;
327
+ return isDisposed || isReleased;
306
328
  },
307
329
 
308
330
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,18 +15,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
15
15
 
16
16
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
17
 
18
- var invariant = require('invariant');
19
-
20
18
  var _require = require('relay-runtime'),
21
- createOperationDescriptor = _require.createOperationDescriptor,
22
- Environment = _require.Environment,
23
- getRequest = _require.getRequest,
24
- getRequestIdentifier = _require.getRequestIdentifier,
25
19
  Observable = _require.Observable,
26
20
  PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
27
- ReplaySubject = _require.ReplaySubject;
21
+ RelayFeatureFlags = _require.RelayFeatureFlags,
22
+ ReplaySubject = _require.ReplaySubject,
23
+ createOperationDescriptor = _require.createOperationDescriptor,
24
+ getRequest = _require.getRequest,
25
+ getRequestIdentifier = _require.getRequestIdentifier; // Expire results by this delay after they resolve.
26
+
28
27
 
29
- // Expire results by this delay after they resolve.
30
28
  var DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
31
29
 
32
30
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
@@ -34,8 +32,6 @@ var STORE_OR_NETWORK_DEFAULT = 'store-or-network';
34
32
  var pendingQueriesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
35
33
 
36
34
  function preloadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
37
- !(environment instanceof Environment) ? process.env.NODE_ENV !== "production" ? invariant(false, 'preloadQuery(): Expected a RelayModernEnvironment') : invariant(false) : void 0;
38
-
39
35
  var _pendingQueries = pendingQueriesByEnvironment.get(environment);
40
36
 
41
37
  if (_pendingQueries == null) {
@@ -63,7 +59,22 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
63
59
  var _subscription;
64
60
 
65
61
  (_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.unsubscribe();
66
- cleanup(pendingQueries, queryEntry);
62
+
63
+ if (environment.isServer()) {
64
+ return;
65
+ }
66
+
67
+ if (RelayFeatureFlags.DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES === true) {
68
+ setTimeout(function () {
69
+ // Clear the cache entry after the default timeout
70
+ // null-check for Flow
71
+ if (queryEntry != null) {
72
+ cleanup(pendingQueries, queryEntry);
73
+ }
74
+ }, DEFAULT_PREFETCH_TIMEOUT);
75
+ } else {
76
+ cleanup(pendingQueries, queryEntry);
77
+ }
67
78
  };
68
79
  }) : null;
69
80
  return {
@@ -178,11 +189,9 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
178
189
  };
179
190
  } else {
180
191
  nextQueryEntry = prevQueryEntry;
181
- } // $FlowFixMe[incompatible-call]
182
-
183
-
184
- pendingQueries.set(cacheKey, nextQueryEntry); // $FlowFixMe[incompatible-return]
192
+ }
185
193
 
194
+ pendingQueries.set(cacheKey, nextQueryEntry);
186
195
  return nextQueryEntry;
187
196
  }
188
197
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -17,16 +17,14 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
17
17
 
18
18
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
19
19
 
20
- var getPaginationMetadata = require('./getPaginationMetadata');
21
-
22
- var invariant = require('invariant');
23
-
24
20
  var useLoadMoreFunction = require('./useLoadMoreFunction');
25
21
 
26
22
  var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
27
23
 
28
24
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
29
25
 
26
+ var invariant = require('invariant');
27
+
30
28
  var _require = require('react'),
31
29
  useCallback = _require.useCallback,
32
30
  useEffect = _require.useEffect,
@@ -35,7 +33,8 @@ var _require = require('react'),
35
33
 
36
34
  var _require2 = require('relay-runtime'),
37
35
  getFragment = _require2.getFragment,
38
- getFragmentIdentifier = _require2.getFragmentIdentifier;
36
+ getFragmentIdentifier = _require2.getFragmentIdentifier,
37
+ getPaginationMetadata = _require2.getPaginationMetadata;
39
38
 
40
39
  function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
41
40
  var componentDisplayName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'useBlockingPaginationFragment()';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -17,11 +17,11 @@ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime
17
17
 
18
18
  var loadEntryPoint = require('./loadEntryPoint');
19
19
 
20
- var useIsMountedRef = require('./useIsMountedRef');
21
-
22
20
  var _require = require('./loadQuery'),
23
21
  useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
24
22
 
23
+ var useIsMountedRef = require('./useIsMountedRef');
24
+
25
25
  var _require2 = require('react'),
26
26
  useCallback = _require2.useCallback,
27
27
  useEffect = _require2.useEffect,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,7 +15,6 @@ var _require = require('react'),
15
15
  useCallback = _require.useCallback,
16
16
  useEffect = _require.useEffect,
17
17
  useRef = _require.useRef;
18
-
19
18
  /**
20
19
  * This hook returns a mutable React ref that holds the value of whether a
21
20
  * fetch request is in flight. The reason this is a mutable ref instead of
@@ -28,6 +27,8 @@ var _require = require('react'),
28
27
  * The additional functions returned by this Hook can be used to mutate
29
28
  * the ref.
30
29
  */
30
+
31
+
31
32
  function useFetchTrackingRef() {
32
33
  var subscriptionRef = useRef(null);
33
34
  var isFetchingRef = useRef(false);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,27 +11,27 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
+ var _require = require('./loadQuery'),
15
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
16
+
14
17
  var useFragmentNode = require('./useFragmentNode');
15
18
 
16
19
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
17
20
 
18
- var _require = require('./loadQuery'),
19
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
20
-
21
21
  var _require2 = require('react'),
22
22
  useDebugValue = _require2.useDebugValue;
23
23
 
24
24
  var _require3 = require('relay-runtime'),
25
25
  getFragment = _require3.getFragment;
26
26
 
27
- function useFragment(fragmentInput, fragmentRef) {
27
+ function useFragment(fragment, key) {
28
28
  // We need to use this hook in order to be able to track if
29
29
  // loadQuery was called during render
30
30
  useTrackLoadQueryInRender();
31
- var fragmentNode = getFragment(fragmentInput);
31
+ var fragmentNode = getFragment(fragment);
32
32
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
33
33
 
34
- var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, 'useFragment()'),
34
+ var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
35
35
  data = _useFragmentNode.data;
36
36
 
37
37
  if (process.env.NODE_ENV !== "production") {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,13 +11,11 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
- var useRelayEnvironment = require('./useRelayEnvironment');
15
-
16
- var warning = require("fbjs/lib/warning");
17
-
18
14
  var _require = require('./FragmentResource'),
19
15
  getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
20
16
 
17
+ var useRelayEnvironment = require('./useRelayEnvironment');
18
+
21
19
  var _require2 = require('react'),
22
20
  useEffect = _require2.useEffect,
23
21
  useRef = _require2.useRef,
@@ -26,6 +24,8 @@ var _require2 = require('react'),
26
24
  var _require3 = require('relay-runtime'),
27
25
  getFragmentIdentifier = _require3.getFragmentIdentifier;
28
26
 
27
+ var warning = require("fbjs/lib/warning");
28
+
29
29
  function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
30
30
  var environment = useRelayEnvironment();
31
31
  var FragmentResource = getFragmentResourceForEnvironment(environment);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -10,11 +10,11 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- var React = require('react');
13
+ var useRelayEnvironment = require('./useRelayEnvironment');
14
14
 
15
15
  var invariant = require('invariant');
16
16
 
17
- var useRelayEnvironment = require('./useRelayEnvironment');
17
+ var React = require('react');
18
18
 
19
19
  var _require = require('relay-runtime'),
20
20
  getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,15 +11,15 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
+ var _require = require('./loadQuery'),
15
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
16
+
14
17
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
15
18
 
16
19
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
17
20
 
18
21
  var useRelayEnvironment = require('./useRelayEnvironment');
19
22
 
20
- var _require = require('./loadQuery'),
21
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
22
-
23
23
  var _require2 = require('relay-runtime'),
24
24
  fetchQuery = _require2.__internal.fetchQuery;
25
25
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,7 +13,9 @@
13
13
 
14
14
  var ProfilerContext = require('./ProfilerContext');
15
15
 
16
- var React = require('react');
16
+ var _require = require('./QueryResource'),
17
+ getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
18
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
17
19
 
18
20
  var useFetchTrackingRef = require('./useFetchTrackingRef');
19
21
 
@@ -21,9 +23,7 @@ var useFragmentNode = require('./useFragmentNode');
21
23
 
22
24
  var useRelayEnvironment = require('./useRelayEnvironment');
23
25
 
24
- var _require = require('./QueryResource'),
25
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment,
26
- getQueryCacheIdentifier = _require.getQueryCacheIdentifier;
26
+ var React = require('react');
27
27
 
28
28
  var useContext = React.useContext,
29
29
  useEffect = React.useEffect,
@@ -96,6 +96,12 @@ function useLazyLoadQueryNode(_ref) {
96
96
  // the effect should be re-executed and the query re-retained.
97
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
98
  }, [environment, cacheIdentifier]);
99
+ useEffect(function () {
100
+ // Release any temporary retain that's not released. At this point, if the
101
+ // cacheIdentifier doesn't change, the query is still permanently retained,
102
+ // and the temporary retain is redundant.
103
+ QueryResource.releaseTemporaryRetain(preparedQueryResult); // This effect is intended to run on every commit, thus no dependency
104
+ });
99
105
  var fragmentNode = preparedQueryResult.fragmentNode,
100
106
  fragmentRef = preparedQueryResult.fragmentRef;
101
107
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,12 +15,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
15
15
 
16
16
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
17
 
18
- var getPaginationVariables = require('./getPaginationVariables');
19
-
20
- var getValueAtPath = require('./getValueAtPath');
21
-
22
- var invariant = require('invariant');
23
-
24
18
  var useFetchTrackingRef = require('./useFetchTrackingRef');
25
19
 
26
20
  var useIsMountedRef = require('./useIsMountedRef');
@@ -29,7 +23,7 @@ var useIsOperationNodeActive = require('./useIsOperationNodeActive');
29
23
 
30
24
  var useRelayEnvironment = require('./useRelayEnvironment');
31
25
 
32
- var warning = require("fbjs/lib/warning");
26
+ var invariant = require('invariant');
33
27
 
34
28
  var _require = require('react'),
35
29
  useCallback = _require.useCallback,
@@ -40,7 +34,11 @@ var _require2 = require('relay-runtime'),
40
34
  ConnectionInterface = _require2.ConnectionInterface,
41
35
  fetchQuery = _require2.__internal.fetchQuery,
42
36
  createOperationDescriptor = _require2.createOperationDescriptor,
43
- getSelector = _require2.getSelector;
37
+ getPaginationVariables = _require2.getPaginationVariables,
38
+ getSelector = _require2.getSelector,
39
+ getValueAtPath = _require2.getValueAtPath;
40
+
41
+ var warning = require("fbjs/lib/warning");
44
42
 
45
43
  function useLoadMoreFunction(args) {
46
44
  var direction = args.direction,
@@ -126,11 +124,9 @@ function useLoadMoreFunction(args) {
126
124
  !(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;
127
125
  var parentVariables = fragmentSelector.owner.variables;
128
126
  var fragmentVariables = fragmentSelector.variables;
129
- var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables; // $FlowFixMe[cannot-spread-interface]
130
-
127
+ var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
131
128
  var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
132
- var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, // $FlowFixMe[cannot-spread-interface]
133
- (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata); // If the query needs an identifier value ('id' or similar) and one
129
+ var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata); // If the query needs an identifier value ('id' or similar) and one
134
130
  // was not explicitly provided, read it from the fragment data.
135
131
 
136
132
  if (identifierField != null) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,10 +11,10 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
- var React = require('react');
15
-
16
14
  var useMemoVariables = require('./useMemoVariables');
17
15
 
16
+ var React = require('react');
17
+
18
18
  var _require = require('relay-runtime'),
19
19
  createOperationDescriptor = _require.createOperationDescriptor,
20
20
  getRequest = _require.getRequest;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,10 +11,10 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
- var React = require('react');
15
-
16
14
  var areEqual = require("fbjs/lib/areEqual");
17
15
 
16
+ var React = require('react');
17
+
18
18
  var useMemo = React.useMemo,
19
19
  useRef = React.useRef,
20
20
  useState = React.useState;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,10 +15,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
15
15
 
16
16
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
17
 
18
- var React = require('react');
18
+ var useIsMountedRef = require('./useIsMountedRef');
19
19
 
20
20
  var useRelayEnvironment = require('./useRelayEnvironment');
21
21
 
22
+ var React = require('react');
23
+
22
24
  var _require = require('relay-runtime'),
23
25
  defaultCommitMutation = _require.commitMutation;
24
26
 
@@ -27,8 +29,6 @@ var useState = React.useState,
27
29
  useRef = React.useRef,
28
30
  useCallback = React.useCallback;
29
31
 
30
- var useIsMountedRef = require('./useIsMountedRef');
31
-
32
32
  function useMutation(mutation) {
33
33
  var commitMutationFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCommitMutation;
34
34
  var environment = useRelayEnvironment();
@@ -66,16 +66,27 @@ function useMutation(mutation) {
66
66
  var disposable = commitMutationFn(environment, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, config), {}, {
67
67
  mutation: mutation,
68
68
  onCompleted: function onCompleted(response, errors) {
69
+ var _config$onCompleted;
70
+
69
71
  cleanup(disposable);
70
- config.onCompleted && config.onCompleted(response, errors);
72
+ (_config$onCompleted = config.onCompleted) === null || _config$onCompleted === void 0 ? void 0 : _config$onCompleted.call(config, response, errors);
71
73
  },
72
74
  onError: function onError(error) {
75
+ var _config$onError;
76
+
73
77
  cleanup(disposable);
74
- config.onError && config.onError(error);
78
+ (_config$onError = config.onError) === null || _config$onError === void 0 ? void 0 : _config$onError.call(config, error);
75
79
  },
76
80
  onUnsubscribe: function onUnsubscribe() {
81
+ var _config$onUnsubscribe;
82
+
77
83
  cleanup(disposable);
78
- config.onUnsubscribe && config.onUnsubscribe();
84
+ (_config$onUnsubscribe = config.onUnsubscribe) === null || _config$onUnsubscribe === void 0 ? void 0 : _config$onUnsubscribe.call(config);
85
+ },
86
+ onNext: function onNext() {
87
+ var _config$onNext;
88
+
89
+ (_config$onNext = config.onNext) === null || _config$onNext === void 0 ? void 0 : _config$onNext.call(config);
79
90
  }
80
91
  }));
81
92
  inFlightMutationsRef.current.add(disposable);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,8 +15,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
15
15
 
16
16
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
17
 
18
- var getPaginationMetadata = require('./getPaginationMetadata');
19
-
20
18
  var useLoadMoreFunction = require('./useLoadMoreFunction');
21
19
 
22
20
  var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
@@ -30,7 +28,8 @@ var _require = require('react'),
30
28
 
31
29
  var _require2 = require('relay-runtime'),
32
30
  getFragment = _require2.getFragment,
33
- getFragmentIdentifier = _require2.getFragmentIdentifier;
31
+ getFragmentIdentifier = _require2.getFragmentIdentifier,
32
+ getPaginationMetadata = _require2.getPaginationMetadata;
34
33
 
35
34
  function usePaginationFragment(fragmentInput, parentFragmentRef) {
36
35
  var fragmentNode = getFragment(fragmentInput);