react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +2 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +10 -6
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,102 +1,71 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
16
-
17
5
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
18
-
19
6
  var _excluded = ["disableStoreUpdates", "enableStoreUpdates"];
20
-
21
7
  var useLoadMoreFunction = require('./useLoadMoreFunction');
22
-
23
8
  var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
24
-
25
9
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
26
-
27
10
  var invariant = require('invariant');
28
-
29
11
  var _require = require('react'),
30
- useCallback = _require.useCallback,
31
- useEffect = _require.useEffect,
32
- useRef = _require.useRef,
33
- useState = _require.useState;
34
-
12
+ useCallback = _require.useCallback,
13
+ useEffect = _require.useEffect,
14
+ useRef = _require.useRef,
15
+ useState = _require.useState;
35
16
  var _require2 = require('relay-runtime'),
36
- getFragment = _require2.getFragment,
37
- getFragmentIdentifier = _require2.getFragmentIdentifier,
38
- getPaginationMetadata = _require2.getPaginationMetadata;
39
-
17
+ getFragment = _require2.getFragment,
18
+ getFragmentIdentifier = _require2.getFragmentIdentifier,
19
+ getPaginationMetadata = _require2.getPaginationMetadata;
40
20
  function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
41
21
  var componentDisplayName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'useBlockingPaginationFragment()';
42
22
  var fragmentNode = getFragment(fragmentInput);
43
23
  useStaticFragmentNodeWarning(fragmentNode, "first argument of ".concat(componentDisplayName));
44
-
45
24
  var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
46
- connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
47
- identifierField = _getPaginationMetadat.identifierField,
48
- paginationRequest = _getPaginationMetadat.paginationRequest,
49
- paginationMetadata = _getPaginationMetadat.paginationMetadata,
50
- stream = _getPaginationMetadat.stream;
51
-
25
+ connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
26
+ paginationRequest = _getPaginationMetadat.paginationRequest,
27
+ paginationMetadata = _getPaginationMetadat.paginationMetadata,
28
+ stream = _getPaginationMetadat.stream;
52
29
  !(stream === false) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: @stream_connection is not compatible with `useBlockingPaginationFragment`. ' + 'Use `useStreamingPaginationFragment` instead.') : invariant(false) : void 0;
53
-
54
30
  var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
55
- fragmentData = _useRefetchableFragme.fragmentData,
56
- fragmentRef = _useRefetchableFragme.fragmentRef,
57
- refetch = _useRefetchableFragme.refetch,
58
- disableStoreUpdates = _useRefetchableFragme.disableStoreUpdates,
59
- enableStoreUpdates = _useRefetchableFragme.enableStoreUpdates;
60
-
61
- var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Backward pagination
62
-
31
+ fragmentData = _useRefetchableFragme.fragmentData,
32
+ fragmentRef = _useRefetchableFragme.fragmentRef,
33
+ refetch = _useRefetchableFragme.refetch,
34
+ disableStoreUpdates = _useRefetchableFragme.disableStoreUpdates,
35
+ enableStoreUpdates = _useRefetchableFragme.enableStoreUpdates;
36
+ var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
63
37
  var _useLoadMore = useLoadMore({
64
- componentDisplayName: componentDisplayName,
65
- connectionPathInFragmentData: connectionPathInFragmentData,
66
- direction: 'backward',
67
- disableStoreUpdates: disableStoreUpdates,
68
- enableStoreUpdates: enableStoreUpdates,
69
- fragmentData: fragmentData,
70
- fragmentIdentifier: fragmentIdentifier,
71
- fragmentNode: fragmentNode,
72
- fragmentRef: fragmentRef,
73
- identifierField: identifierField,
74
- paginationMetadata: paginationMetadata,
75
- paginationRequest: paginationRequest
76
- }),
77
- loadPrevious = _useLoadMore[0],
78
- hasPrevious = _useLoadMore[1],
79
- disposeFetchPrevious = _useLoadMore[2]; // Forward pagination
80
-
81
-
38
+ componentDisplayName: componentDisplayName,
39
+ connectionPathInFragmentData: connectionPathInFragmentData,
40
+ direction: 'backward',
41
+ disableStoreUpdates: disableStoreUpdates,
42
+ enableStoreUpdates: enableStoreUpdates,
43
+ fragmentData: fragmentData,
44
+ fragmentIdentifier: fragmentIdentifier,
45
+ fragmentNode: fragmentNode,
46
+ fragmentRef: fragmentRef,
47
+ paginationMetadata: paginationMetadata,
48
+ paginationRequest: paginationRequest
49
+ }),
50
+ loadPrevious = _useLoadMore[0],
51
+ hasPrevious = _useLoadMore[1],
52
+ disposeFetchPrevious = _useLoadMore[2];
82
53
  var _useLoadMore2 = useLoadMore({
83
- componentDisplayName: componentDisplayName,
84
- connectionPathInFragmentData: connectionPathInFragmentData,
85
- direction: 'forward',
86
- disableStoreUpdates: disableStoreUpdates,
87
- enableStoreUpdates: enableStoreUpdates,
88
- fragmentData: fragmentData,
89
- fragmentIdentifier: fragmentIdentifier,
90
- fragmentNode: fragmentNode,
91
- fragmentRef: fragmentRef,
92
- identifierField: identifierField,
93
- paginationMetadata: paginationMetadata,
94
- paginationRequest: paginationRequest
95
- }),
96
- loadNext = _useLoadMore2[0],
97
- hasNext = _useLoadMore2[1],
98
- disposeFetchNext = _useLoadMore2[2];
99
-
54
+ componentDisplayName: componentDisplayName,
55
+ connectionPathInFragmentData: connectionPathInFragmentData,
56
+ direction: 'forward',
57
+ disableStoreUpdates: disableStoreUpdates,
58
+ enableStoreUpdates: enableStoreUpdates,
59
+ fragmentData: fragmentData,
60
+ fragmentIdentifier: fragmentIdentifier,
61
+ fragmentNode: fragmentNode,
62
+ fragmentRef: fragmentRef,
63
+ paginationMetadata: paginationMetadata,
64
+ paginationRequest: paginationRequest
65
+ }),
66
+ loadNext = _useLoadMore2[0],
67
+ hasNext = _useLoadMore2[1],
68
+ disposeFetchNext = _useLoadMore2[2];
100
69
  var refetchPagination = useCallback(function (variables, options) {
101
70
  disposeFetchNext();
102
71
  disposeFetchPrevious();
@@ -113,39 +82,27 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
113
82
  refetch: refetchPagination
114
83
  };
115
84
  }
116
-
117
85
  function useLoadMore(args) {
118
86
  var disableStoreUpdates = args.disableStoreUpdates,
119
- enableStoreUpdates = args.enableStoreUpdates,
120
- loadMoreArgs = (0, _objectWithoutPropertiesLoose2["default"])(args, _excluded);
121
-
87
+ enableStoreUpdates = args.enableStoreUpdates,
88
+ loadMoreArgs = (0, _objectWithoutPropertiesLoose2["default"])(args, _excluded);
122
89
  var _useState = useState(null),
123
- requestPromise = _useState[0],
124
- setRequestPromise = _useState[1];
125
-
90
+ requestPromise = _useState[0],
91
+ setRequestPromise = _useState[1];
126
92
  var requestPromiseRef = useRef(null);
127
93
  var promiseResolveRef = useRef(null);
128
-
129
94
  var promiseResolve = function promiseResolve() {
130
95
  if (promiseResolveRef.current != null) {
131
96
  promiseResolveRef.current();
132
97
  promiseResolveRef.current = null;
133
98
  }
134
99
  };
135
-
136
100
  var handleReset = function handleReset() {
137
101
  promiseResolve();
138
102
  };
139
-
140
103
  var observer = {
141
104
  complete: promiseResolve,
142
- // NOTE: loadMore is a no-op if a request is already in flight, so we
143
- // can safely assume that `start` will only be called once while a
144
- // request is in flight.
145
105
  start: function start() {
146
- // NOTE: We disable store updates when we suspend to ensure
147
- // that higher-pri updates from the Relay store don't disrupt
148
- // any Suspense timeouts passed via withSuspenseConfig.
149
106
  disableStoreUpdates();
150
107
  var promise = new Promise(function (resolve) {
151
108
  promiseResolveRef.current = function () {
@@ -156,44 +113,24 @@ function useLoadMore(args) {
156
113
  requestPromiseRef.current = promise;
157
114
  setRequestPromise(promise);
158
115
  },
159
- // NOTE: Since streaming is disallowed with this hook, this means that the
160
- // first payload will always contain the entire next page of items,
161
- // while subsequent paylaods will contain @defer'd payloads.
162
- // This allows us to unsuspend here, on the first payload, and allow
163
- // descendant components to suspend on their respective @defer payloads
164
116
  next: promiseResolve,
165
- // TODO: Handle error; we probably don't want to throw an error
166
- // and blow away the whole list of items.
167
117
  error: promiseResolve
168
118
  };
169
-
170
119
  var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, loadMoreArgs), {}, {
171
- observer: observer,
172
- onReset: handleReset
173
- })),
174
- loadMore = _useLoadMoreFunction[0],
175
- hasMore = _useLoadMoreFunction[1],
176
- disposeFetch = _useLoadMoreFunction[2]; // NOTE: To determine if we need to suspend, we check that the promise in
177
- // state is the same as the promise on the ref, which ensures that we
178
- // wont incorrectly suspend on other higher-pri updates before the update
179
- // to suspend has committed.
180
-
181
-
120
+ observer: observer,
121
+ onReset: handleReset
122
+ })),
123
+ loadMore = _useLoadMoreFunction[0],
124
+ hasMore = _useLoadMoreFunction[1],
125
+ disposeFetch = _useLoadMoreFunction[2];
182
126
  if (requestPromise != null && requestPromise === requestPromiseRef.current) {
183
127
  throw requestPromise;
184
128
  }
185
-
186
129
  useEffect(function () {
187
130
  if (requestPromise !== requestPromiseRef.current) {
188
- // NOTE: After suspense pagination has resolved, we re-enable store updates
189
- // for this fragment. This may cause the component to re-render if
190
- // we missed any updates to the fragment data other than the pagination update.
191
131
  enableStoreUpdates();
192
- } // NOTE: We know the identity of enableStoreUpdates wont change
193
- // eslint-disable-next-line react-hooks/exhaustive-deps
194
-
132
+ }
195
133
  }, [requestPromise]);
196
134
  return [loadMore, hasMore, disposeFetch];
197
135
  }
198
-
199
136
  module.exports = useBlockingPaginationFragment;
@@ -1,33 +1,12 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var useLazyLoadQuery = require('./useLazyLoadQuery');
18
- /**
19
- * This hook can be used to render client-only queries.
20
- * These queries are consist of queries for client-only data,
21
- * schematized via local schema extensions and/or Relay resolvers.
22
- */
23
-
24
-
25
6
  function useClientQuery(gqlQuery, variables, options) {
26
- // $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
27
7
  var query = gqlQuery;
28
8
  return useLazyLoadQuery(query, variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
29
9
  fetchPolicy: 'store-only'
30
10
  }));
31
11
  }
32
-
33
12
  module.exports = useClientQuery;
@@ -1,72 +1,32 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
16
-
17
5
  var loadEntryPoint = require('./loadEntryPoint');
18
-
19
6
  var _require = require('./loadQuery'),
20
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
21
-
7
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
22
8
  var useIsMountedRef = require('./useIsMountedRef');
23
-
24
9
  var _require2 = require('react'),
25
- useCallback = _require2.useCallback,
26
- useEffect = _require2.useEffect,
27
- useRef = _require2.useRef,
28
- useState = _require2.useState;
29
-
10
+ useCallback = _require2.useCallback,
11
+ useEffect = _require2.useEffect,
12
+ useRef = _require2.useRef,
13
+ useState = _require2.useState;
30
14
  var initialNullEntryPointReferenceState = {
31
15
  kind: 'NullEntryPointReference'
32
16
  };
33
-
34
17
  function useLoadEntryPoint(environmentProvider, entryPoint, options) {
35
18
  var _options$TEST_ONLY__i, _options$TEST_ONLY__i2, _options$TEST_ONLY__i3, _options$TEST_ONLY__i4;
36
-
37
- /**
38
- * We want to always call `entryPointReference.dispose()` for every call to
39
- * `setEntryPointReference(loadEntryPoint(...))` so that no leaks of data in Relay
40
- * stores will occur.
41
- *
42
- * However, a call to `setState(newState)` is not always followed by a commit where
43
- * this value is reflected in the state. Thus, we cannot reliably clean up each ref
44
- * with `useEffect(() => () => entryPointReference.dispose(), [entryPointReference])`.
45
- *
46
- * Instead, we keep track of each call to `loadEntryPoint` in a ref.
47
- * Relying on the fact that if a state change commits, no state changes that were
48
- * initiated prior to the currently committing state change will ever subsequently
49
- * commit, we can safely dispose of all preloaded entry point references
50
- * associated with state changes initiated prior to the currently committing state
51
- * change.
52
- *
53
- * Finally, when the hook unmounts, we also dispose of all remaining uncommitted
54
- * entry point references.
55
- */
56
19
  useTrackLoadQueryInRender();
57
20
  var initialEntryPointReferenceInternal = (_options$TEST_ONLY__i = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i2 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i2 === void 0 ? void 0 : _options$TEST_ONLY__i2.entryPointReference) !== null && _options$TEST_ONLY__i !== void 0 ? _options$TEST_ONLY__i : initialNullEntryPointReferenceState;
58
21
  var initialEntryPointParamsInternal = (_options$TEST_ONLY__i3 = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i4 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i4 === void 0 ? void 0 : _options$TEST_ONLY__i4.entryPointParams) !== null && _options$TEST_ONLY__i3 !== void 0 ? _options$TEST_ONLY__i3 : null;
59
22
  var isMountedRef = useIsMountedRef();
60
23
  var undisposedEntryPointReferencesRef = useRef(new Set([initialEntryPointReferenceInternal]));
61
-
62
24
  var _useState = useState(initialEntryPointReferenceInternal),
63
- entryPointReference = _useState[0],
64
- setEntryPointReference = _useState[1];
65
-
25
+ entryPointReference = _useState[0],
26
+ setEntryPointReference = _useState[1];
66
27
  var _useState2 = useState(initialEntryPointParamsInternal),
67
- entryPointParams = _useState2[0],
68
- setEntryPointParams = _useState2[1];
69
-
28
+ entryPointParams = _useState2[0],
29
+ setEntryPointParams = _useState2[1];
70
30
  var disposeEntryPoint = useCallback(function () {
71
31
  if (isMountedRef.current) {
72
32
  var nullEntryPointReference = {
@@ -87,71 +47,28 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
87
47
  var maybeHiddenOrFastRefresh = useRef(false);
88
48
  useEffect(function () {
89
49
  return function () {
90
- // Attempt to detect if the component was
91
- // hidden (by Offscreen API), or fast refresh occured;
92
- // Only in these situations would the effect cleanup
93
- // for "unmounting" run multiple times, so if
94
- // we are ever able to read this ref with a value
95
- // of true, it means that one of these cases
96
- // has happened.
97
50
  maybeHiddenOrFastRefresh.current = true;
98
51
  };
99
52
  }, []);
100
53
  useEffect(function () {
101
54
  if (maybeHiddenOrFastRefresh.current === true) {
102
- // This block only runs if the component has previously "unmounted"
103
- // due to it being hidden by the Offscreen API, or during fast refresh.
104
- // At this point, the current entryPointReference will have been disposed
105
- // by the previous cleanup, so instead of attempting to
106
- // do our regular commit setup, which would incorrectly leave our
107
- // current entryPointReference disposed, we need to load the entryPoint again
108
- // and force a re-render by calling entryPointLoaderCallback again,
109
- // so that the entryPointReference's queries are correctly re-retained, and
110
- // potentially refetched if necessary.
111
55
  maybeHiddenOrFastRefresh.current = false;
112
-
113
56
  if (entryPointReference.kind !== 'NullEntryPointReference' && entryPointParams != null) {
114
57
  entryPointLoaderCallback(entryPointParams);
115
58
  }
116
-
117
59
  return;
118
- } // When a new entryPointReference is committed, we iterate over all
119
- // entrypoint refs in undisposedEntryPointReferences and dispose all of
120
- // the refs that aren't the currently committed one. This ensures
121
- // that we don't leave any dangling entrypoint references for the
122
- // case that loadEntryPoint is called multiple times before commit; when
123
- // this happens, multiple state updates will be scheduled, but only one
124
- // will commit, meaning that we need to keep track of and dispose any
125
- // query references that don't end up committing.
126
- // - We are relying on the fact that sets iterate in insertion order, and we
127
- // can remove items from a set as we iterate over it (i.e. no iterator
128
- // invalidation issues.) Thus, it is safe to loop through
129
- // undisposedEntryPointReferences until we find entryPointReference, and
130
- // remove and dispose all previous references.
131
- // - We are guaranteed to find entryPointReference in the set, because if a
132
- // state change results in a commit, no state changes initiated prior to that
133
- // one will be committed, and we are disposing and removing references
134
- // associated with commits that were initiated prior to the currently
135
- // committing state change. (A useEffect callback is called during the commit
136
- // phase.)
137
-
138
-
60
+ }
139
61
  var undisposedEntryPointReferences = undisposedEntryPointReferencesRef.current;
140
-
141
62
  if (isMountedRef.current) {
142
63
  var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferences),
143
- _step;
144
-
64
+ _step;
145
65
  try {
146
66
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
147
67
  var undisposedEntryPointReference = _step.value;
148
-
149
68
  if (undisposedEntryPointReference === entryPointReference) {
150
69
  break;
151
70
  }
152
-
153
71
  undisposedEntryPointReferences["delete"](undisposedEntryPointReference);
154
-
155
72
  if (undisposedEntryPointReference.kind !== 'NullEntryPointReference') {
156
73
  undisposedEntryPointReference.dispose();
157
74
  }
@@ -165,15 +82,11 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
165
82
  }, [entryPointReference, entryPointParams, entryPointLoaderCallback, isMountedRef]);
166
83
  useEffect(function () {
167
84
  return function disposeAllRemainingEntryPointReferences() {
168
- // undisposedEntryPointReferences.current is never reassigned
169
- // eslint-disable-next-line react-hooks/exhaustive-deps
170
85
  var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferencesRef.current),
171
- _step2;
172
-
86
+ _step2;
173
87
  try {
174
88
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
175
89
  var unhandledStateChange = _step2.value;
176
-
177
90
  if (unhandledStateChange.kind !== 'NullEntryPointReference') {
178
91
  unhandledStateChange.dispose();
179
92
  }
@@ -187,5 +100,4 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
187
100
  }, []);
188
101
  return [entryPointReference.kind === 'NullEntryPointReference' ? null : entryPointReference, entryPointLoaderCallback, disposeEntryPoint];
189
102
  }
190
-
191
103
  module.exports = useLoadEntryPoint;
@@ -1,42 +1,17 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
3
+ var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
13
4
  var _require = require('react'),
14
- useCallback = _require.useCallback,
15
- useEffect = _require.useEffect,
16
- useRef = _require.useRef;
17
- /**
18
- * This hook returns a mutable React ref that holds the value of whether a
19
- * fetch request is in flight. The reason this is a mutable ref instead of
20
- * state is because we don't actually want to trigger an update when this
21
- * changes, but instead synchronously keep track of whether the network request
22
- * is in flight, for example in order to bail out of a request if one is
23
- * already in flight. If this was state, due to the nature of concurrent
24
- * updates, this value wouldn't be in sync with when the request is actually
25
- * in flight.
26
- * The additional functions returned by this Hook can be used to mutate
27
- * the ref.
28
- */
29
-
30
-
5
+ useCallback = _require.useCallback,
6
+ useEffect = _require.useEffect;
31
7
  function useFetchTrackingRef() {
32
- var subscriptionRef = useRef(null);
33
- var isFetchingRef = useRef(false);
8
+ var subscriptionRef = useUnsafeRef_DEPRECATED(null);
9
+ var isFetchingRef = useUnsafeRef_DEPRECATED(false);
34
10
  var disposeFetch = useCallback(function () {
35
11
  if (subscriptionRef.current != null) {
36
12
  subscriptionRef.current.unsubscribe();
37
13
  subscriptionRef.current = null;
38
14
  }
39
-
40
15
  isFetchingRef.current = false;
41
16
  }, []);
42
17
  var startFetch = useCallback(function (subscription) {
@@ -46,8 +21,7 @@ function useFetchTrackingRef() {
46
21
  var completeFetch = useCallback(function () {
47
22
  subscriptionRef.current = null;
48
23
  isFetchingRef.current = false;
49
- }, []); // Dipose of ongoing fetch on unmount
50
-
24
+ }, []);
51
25
  useEffect(function () {
52
26
  return disposeFetch;
53
27
  }, [disposeFetch]);
@@ -58,5 +32,4 @@ function useFetchTrackingRef() {
58
32
  completeFetch: completeFetch
59
33
  };
60
34
  }
61
-
62
35
  module.exports = useFetchTrackingRef;
@@ -1,61 +1,34 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var HooksImplementation = require('./HooksImplementation');
14
-
15
4
  var _require = require('./loadQuery'),
16
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
17
-
5
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
18
6
  var useFragmentNode = require('./useFragmentNode');
19
-
20
7
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
21
-
22
8
  var _require2 = require('react'),
23
- useDebugValue = _require2.useDebugValue;
24
-
9
+ useDebugValue = _require2.useDebugValue;
25
10
  var _require3 = require('relay-runtime'),
26
- getFragment = _require3.getFragment;
27
-
11
+ getFragment = _require3.getFragment;
28
12
  function useFragment_LEGACY(fragment, key) {
29
- // We need to use this hook in order to be able to track if
30
- // loadQuery was called during render
31
13
  useTrackLoadQueryInRender();
32
14
  var fragmentNode = getFragment(fragment);
33
15
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
34
-
35
16
  var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
36
- data = _useFragmentNode.data;
37
-
17
+ data = _useFragmentNode.data;
38
18
  if (process.env.NODE_ENV !== "production") {
39
- // eslint-disable-next-line react-hooks/rules-of-hooks
40
19
  useDebugValue({
41
20
  fragment: fragmentNode.name,
42
21
  data: data
43
22
  });
44
23
  }
45
-
46
24
  return data;
47
25
  }
48
-
49
26
  function useFragment(fragment, key) {
50
27
  var impl = HooksImplementation.get();
51
-
52
28
  if (impl) {
53
- // $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
54
- return impl.useFragment(fragment, key); // (i.e. type declared above, but not the supertype used in this function definition)
29
+ return impl.useFragment(fragment, key);
55
30
  } else {
56
- // eslint-disable-next-line react-hooks/rules-of-hooks
57
31
  return useFragment_LEGACY(fragment, key);
58
32
  }
59
33
  }
60
-
61
34
  module.exports = useFragment;