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,9 +14,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
16
 
17
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
18
+
17
19
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
18
20
 
19
- var React = require('react');
21
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
22
 
21
23
  var ReactRelayContext = require('./ReactRelayContext');
22
24
 
@@ -26,7 +28,10 @@ var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext')
26
28
 
27
29
  var areEqual = require("fbjs/lib/areEqual");
28
30
 
31
+ var React = require('react');
32
+
29
33
  var _require = require('relay-runtime'),
34
+ RelayFeatureFlags = _require.RelayFeatureFlags,
30
35
  createOperationDescriptor = _require.createOperationDescriptor,
31
36
  deepFreeze = _require.deepFreeze,
32
37
  getRequest = _require.getRequest;
@@ -64,6 +69,29 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
64
69
  // that reason, we define them as null initially and fill them in after
65
70
  // mounting to avoid leaking memory.
66
71
 
72
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleDataChange", function (params) {
73
+ var error = params.error == null ? null : params.error;
74
+ var snapshot = params.snapshot == null ? null : params.snapshot;
75
+
76
+ _this.setState(function (prevState) {
77
+ var prevRequestCacheKey = prevState.requestCacheKey;
78
+
79
+ if (prevRequestCacheKey) {
80
+ delete requestCache[prevRequestCacheKey];
81
+ } // Don't update state if nothing has changed.
82
+
83
+
84
+ if (snapshot === prevState.snapshot && error === prevState.error) {
85
+ return null;
86
+ }
87
+
88
+ return {
89
+ renderProps: getRenderProps(error, snapshot, prevState.queryFetcher, prevState.retryCallbacks),
90
+ snapshot: snapshot,
91
+ requestCacheKey: null
92
+ };
93
+ });
94
+ });
67
95
  var retryCallbacks = {
68
96
  handleDataChange: null,
69
97
  handleRetryAfterError: null
@@ -80,6 +108,7 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
80
108
  queryFetcher = new ReactRelayQueryFetcher();
81
109
  }
82
110
 
111
+ _this._maybeHiddenOrFastRefresh = false;
83
112
  _this.state = (0, _objectSpread2["default"])({
84
113
  prevPropsEnvironment: props.environment,
85
114
  prevPropsVariables: props.variables,
@@ -92,27 +121,7 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
92
121
 
93
122
  ReactRelayQueryRenderer.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
94
123
  if (prevState.prevQuery !== nextProps.query || prevState.prevPropsEnvironment !== nextProps.environment || !areEqual(prevState.prevPropsVariables, nextProps.variables)) {
95
- var query = nextProps.query;
96
- var prevSelectionReferences = prevState.queryFetcher.getSelectionReferences();
97
- prevState.queryFetcher.disposeRequest();
98
- var queryFetcher;
99
-
100
- if (query) {
101
- var request = getRequest(query);
102
- var requestCacheKey = getRequestCacheKey(request.params, nextProps.variables);
103
- queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new ReactRelayQueryFetcher(prevSelectionReferences);
104
- } else {
105
- queryFetcher = new ReactRelayQueryFetcher(prevSelectionReferences);
106
- }
107
-
108
- return (0, _objectSpread2["default"])({
109
- prevQuery: nextProps.query,
110
- prevPropsEnvironment: nextProps.environment,
111
- prevPropsVariables: nextProps.variables,
112
- queryFetcher: queryFetcher
113
- }, fetchQueryAndComputeStateFromProps(nextProps, queryFetcher, prevState.retryCallbacks // passing no requestCacheKey will cause it to be recalculated internally
114
- // and we want the updated requestCacheKey, since variables may have changed
115
- ));
124
+ return resetQueryStateForUpdate(nextProps, prevState);
116
125
  }
117
126
 
118
127
  return null;
@@ -123,38 +132,31 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
123
132
  _proto.componentDidMount = function componentDidMount() {
124
133
  var _this2 = this;
125
134
 
135
+ if (RelayFeatureFlags.ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT === true && this._maybeHiddenOrFastRefresh === true) {
136
+ // This block only runs if the component has previously "unmounted"
137
+ // due to it being hidden by the Offscreen API, or during fast refresh.
138
+ // At this point, the current cached resource will have been disposed
139
+ // by the previous cleanup, so instead of attempting to
140
+ // do our regular commit setup, so that the query is re-evaluated
141
+ // (and potentially cause a refetch).
142
+ this._maybeHiddenOrFastRefresh = false; // eslint-disable-next-line react/no-did-mount-set-state
143
+
144
+ this.setState(function (prevState) {
145
+ return resetQueryStateForUpdate(_this2.props, prevState);
146
+ });
147
+ return;
148
+ }
149
+
126
150
  var _this$state = this.state,
127
151
  retryCallbacks = _this$state.retryCallbacks,
128
152
  queryFetcher = _this$state.queryFetcher,
129
- requestCacheKey = _this$state.requestCacheKey;
153
+ requestCacheKey = _this$state.requestCacheKey; // We don't need to cache the request after the component commits
130
154
 
131
155
  if (requestCacheKey) {
132
156
  delete requestCache[requestCacheKey];
133
157
  }
134
158
 
135
- retryCallbacks.handleDataChange = function (params) {
136
- var error = params.error == null ? null : params.error;
137
- var snapshot = params.snapshot == null ? null : params.snapshot;
138
-
139
- _this2.setState(function (prevState) {
140
- var prevRequestCacheKey = prevState.requestCacheKey;
141
-
142
- if (prevRequestCacheKey) {
143
- delete requestCache[prevRequestCacheKey];
144
- } // Don't update state if nothing has changed.
145
-
146
-
147
- if (snapshot === prevState.snapshot && error === prevState.error) {
148
- return null;
149
- }
150
-
151
- return {
152
- renderProps: getRenderProps(error, snapshot, prevState.queryFetcher, prevState.retryCallbacks),
153
- snapshot: snapshot,
154
- requestCacheKey: null
155
- };
156
- });
157
- };
159
+ retryCallbacks.handleDataChange = this._handleDataChange;
158
160
 
159
161
  retryCallbacks.handleRetryAfterError = function (error) {
160
162
  return _this2.setState(function (prevState) {
@@ -174,23 +176,30 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
174
176
 
175
177
 
176
178
  if (this.props.query) {
177
- queryFetcher.setOnDataChange(retryCallbacks.handleDataChange);
179
+ queryFetcher.setOnDataChange(this._handleDataChange);
178
180
  }
179
181
  };
180
182
 
181
- _proto.componentDidUpdate = function componentDidUpdate() {
183
+ _proto.componentDidUpdate = function componentDidUpdate(_prevProps, prevState) {
182
184
  // We don't need to cache the request after the component commits
183
- var requestCacheKey = this.state.requestCacheKey;
185
+ var _this$state2 = this.state,
186
+ queryFetcher = _this$state2.queryFetcher,
187
+ requestCacheKey = _this$state2.requestCacheKey;
184
188
 
185
189
  if (requestCacheKey) {
186
190
  delete requestCache[requestCacheKey]; // HACK
187
191
 
188
192
  delete this.state.requestCacheKey;
189
193
  }
194
+
195
+ if (this.props.query && queryFetcher !== prevState.queryFetcher) {
196
+ queryFetcher.setOnDataChange(this._handleDataChange);
197
+ }
190
198
  };
191
199
 
192
200
  _proto.componentWillUnmount = function componentWillUnmount() {
193
201
  this.state.queryFetcher.dispose();
202
+ this._maybeHiddenOrFastRefresh = true;
194
203
  };
195
204
 
196
205
  _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
@@ -198,9 +207,9 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
198
207
  };
199
208
 
200
209
  _proto.render = function render() {
201
- var _this$state2 = this.state,
202
- renderProps = _this$state2.renderProps,
203
- relayContext = _this$state2.relayContext; // Note that the root fragment results in `renderProps.props` is already
210
+ var _this$state3 = this.state,
211
+ renderProps = _this$state3.renderProps,
212
+ relayContext = _this$state3.relayContext; // Note that the root fragment results in `renderProps.props` is already
204
213
  // frozen by the store; this call is to freeze the renderProps object and
205
214
  // error property if set.
206
215
 
@@ -263,6 +272,30 @@ function getRequestCacheKey(request, variables) {
263
272
  });
264
273
  }
265
274
 
275
+ function resetQueryStateForUpdate(props, prevState) {
276
+ var query = props.query;
277
+ var prevSelectionReferences = prevState.queryFetcher.getSelectionReferences();
278
+ prevState.queryFetcher.disposeRequest();
279
+ var queryFetcher;
280
+
281
+ if (query) {
282
+ var request = getRequest(query);
283
+ var requestCacheKey = getRequestCacheKey(request.params, props.variables);
284
+ queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new ReactRelayQueryFetcher(prevSelectionReferences);
285
+ } else {
286
+ queryFetcher = new ReactRelayQueryFetcher(prevSelectionReferences);
287
+ }
288
+
289
+ return (0, _objectSpread2["default"])({
290
+ prevQuery: props.query,
291
+ prevPropsEnvironment: props.environment,
292
+ prevPropsVariables: props.variables,
293
+ queryFetcher: queryFetcher
294
+ }, fetchQueryAndComputeStateFromProps(props, queryFetcher, prevState.retryCallbacks // passing no requestCacheKey will cause it to be recalculated internally
295
+ // and we want the updated requestCacheKey, since variables may have changed
296
+ ));
297
+ }
298
+
266
299
  function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks, requestCacheKey) {
267
300
  var environment = props.environment,
268
301
  query = props.query,
@@ -306,7 +339,7 @@ function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks,
306
339
  var storeSnapshot = queryFetcher.lookupInStore(genericEnvironment, operation, props.fetchPolicy);
307
340
  var querySnapshot = queryFetcher.fetch({
308
341
  environment: genericEnvironment,
309
- onDataChange: retryCallbacks.handleDataChange,
342
+ onDataChange: null,
310
343
  operation: operation
311
344
  }); // Use network data first, since it may be fresher
312
345
 
@@ -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.
@@ -24,36 +24,35 @@ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inh
24
24
 
25
25
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
26
26
 
27
- var React = require('react');
28
-
29
- var ReactRelayContext = require('./ReactRelayContext');
30
-
31
- var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
32
-
33
- var areEqual = require("fbjs/lib/areEqual");
34
-
35
27
  var buildReactRelayContainer = require('./buildReactRelayContainer');
36
28
 
37
29
  var getRootVariablesForFragments = require('./getRootVariablesForFragments');
38
30
 
39
- var warning = require("fbjs/lib/warning");
40
-
41
31
  var _require = require('./ReactRelayContainerUtils'),
42
32
  getContainerName = _require.getContainerName;
43
33
 
34
+ var ReactRelayContext = require('./ReactRelayContext');
35
+
36
+ var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
37
+
44
38
  var _require2 = require('./RelayContext'),
45
39
  assertRelayContext = _require2.assertRelayContext;
46
40
 
41
+ var areEqual = require("fbjs/lib/areEqual");
42
+
43
+ var React = require('react');
44
+
47
45
  var _require3 = require('relay-runtime'),
48
46
  Observable = _require3.Observable,
49
47
  createFragmentSpecResolver = _require3.createFragmentSpecResolver,
50
48
  createOperationDescriptor = _require3.createOperationDescriptor,
51
49
  getDataIDsFromObject = _require3.getDataIDsFromObject,
52
50
  getRequest = _require3.getRequest,
53
- getSelector = _require3.getSelector,
54
51
  getVariablesFromObject = _require3.getVariablesFromObject,
55
52
  isScalarAndEqual = _require3.isScalarAndEqual;
56
53
 
54
+ var warning = require("fbjs/lib/warning");
55
+
57
56
  /**
58
57
  * Composes a React component class, returning a new class that intercepts
59
58
  * props, resolving them with the provided fragments and subscribing for
@@ -94,11 +93,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
94
93
  environment = _assertRelayContext.environment;
95
94
 
96
95
  var rootVariables = getRootVariablesForFragments(fragments, _this.props);
97
- var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables; // $FlowFixMe[cannot-spread-interface]
98
-
96
+ var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables;
99
97
  fetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fetchVariables);
100
- var fragmentVariables = renderVariables ? // $FlowFixMe[cannot-spread-interface]
101
- (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, fetchVariables), renderVariables) : fetchVariables;
98
+ var fragmentVariables = renderVariables ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, fetchVariables), renderVariables) : fetchVariables;
102
99
  var cacheConfig = options ? {
103
100
  force: !!options.force
104
101
  } : undefined;
@@ -215,7 +212,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
215
212
  _proto.componentDidMount = function componentDidMount() {
216
213
  this._isUnmounted = false;
217
214
 
218
- this._subscribeToNewResolver();
215
+ this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
219
216
  };
220
217
 
221
218
  _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
@@ -229,7 +226,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
229
226
  this._queryFetcher && this._queryFetcher.dispose();
230
227
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
231
228
 
232
- this._subscribeToNewResolver();
229
+ this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
230
+ } else {
231
+ this._rerenderIfStoreHasChanged();
233
232
  }
234
233
  }
235
234
  /**
@@ -321,17 +320,31 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
321
320
  return false;
322
321
  };
323
322
 
324
- _proto._subscribeToNewResolver = function _subscribeToNewResolver() {
323
+ _proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
325
324
  var _this$state = this.state,
326
325
  data = _this$state.data,
327
- resolver = _this$state.resolver; // Event listeners are only safe to add during the commit phase,
328
- // So they won't leak if render is interrupted or errors.
329
-
330
- resolver.setCallback(this._handleFragmentDataUpdate); // External values could change between render and commit.
326
+ resolver = _this$state.resolver; // External values could change between render and commit.
331
327
  // Check for this case, even though it requires an extra store read.
332
328
 
333
329
  var maybeNewData = resolver.resolve();
334
330
 
331
+ if (data !== maybeNewData) {
332
+ this.setState({
333
+ data: maybeNewData
334
+ });
335
+ }
336
+ };
337
+
338
+ _proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
339
+ var _this$state2 = this.state,
340
+ data = _this$state2.data,
341
+ resolver = _this$state2.resolver;
342
+ var maybeNewData = resolver.resolve(); // Event listeners are only safe to add during the commit phase,
343
+ // So they won't leak if render is interrupted or errors.
344
+
345
+ resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
346
+ // Check for this case, even though it requires an extra store read.
347
+
335
348
  if (data !== maybeNewData) {
336
349
  this.setState({
337
350
  data: maybeNewData
@@ -361,9 +374,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
361
374
  __relayContext = _this$props.__relayContext,
362
375
  __rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
363
376
  props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, ["componentRef", "__relayContext", "__rootIsQueryRenderer"]);
364
- var _this$state2 = this.state,
365
- relayProp = _this$state2.relayProp,
366
- contextForChildren = _this$state2.contextForChildren;
377
+ var _this$state3 = this.state,
378
+ relayProp = _this$state3.relayProp,
379
+ contextForChildren = _this$state3.contextForChildren;
367
380
  return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
368
381
  value: contextForChildren
369
382
  }, /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
@@ -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.
@@ -20,12 +20,12 @@ var areEqual = require("fbjs/lib/areEqual");
20
20
 
21
21
  var invariant = require('invariant');
22
22
 
23
- var warning = require("fbjs/lib/warning");
24
-
25
23
  var _require = require('relay-runtime'),
24
+ Network = _require.Network,
26
25
  createOperationDescriptor = _require.createOperationDescriptor,
27
- isRelayModernEnvironment = _require.isRelayModernEnvironment,
28
- Network = _require.Network;
26
+ isRelayModernEnvironment = _require.isRelayModernEnvironment;
27
+
28
+ var warning = require("fbjs/lib/warning");
29
29
 
30
30
  /**
31
31
  * The next id to return from `generateId()`.
@@ -83,10 +83,8 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
83
83
  ;
84
84
 
85
85
  ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
86
- // $FlowFixMe[prop-missing]
87
86
  if (variables.input) {
88
- var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId']; // $FlowFixMe[cannot-spread-interface]
89
-
87
+ var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId'];
90
88
  var strippedVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, variables), {}, {
91
89
  input: (0, _objectSpread2["default"])({}, variables.input)
92
90
  });
@@ -258,7 +256,8 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
258
256
 
259
257
  var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
260
258
  !toResolve ? process.env.NODE_ENV !== "production" ? invariant(false, 'You are attempting to resolve a query that has not been fetched ' + '(%s%s).\n\tPlease ensure you passed the correct variables, or use ' + '`writeDirect` instead.', ident, varMessage) : invariant(false) : void 0;
261
- var realPayload = typeof payload === 'function' ? payload(toResolve.variables) : payload; // if there are errors, reject the query
259
+ var realPayload = // $FlowFixMe[incompatible-call]
260
+ typeof payload === 'function' ? payload(toResolve.variables) : payload; // if there are errors, reject the query
262
261
 
263
262
  if (realPayload.errors != null && realPayload.errors.length > 0) {
264
263
  this._environment.mock.rejectQuery(toResolve, {
@@ -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,14 +10,15 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var invariant = require('invariant');
14
-
15
13
  var isRelayEnvironment = require('./isRelayEnvironment');
16
14
 
15
+ var invariant = require('invariant');
17
16
  /**
18
17
  * Asserts that the input is a matches the `RelayContext` type defined in
19
18
  * `RelayEnvironmentTypes` and returns it as that type.
20
19
  */
20
+
21
+
21
22
  function assertRelayContext(relay) {
22
23
  !isRelayContext(relay) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayContext: Expected `context.relay` to be an object conforming to ' + 'the `RelayContext` interface, got `%s`.', relay) : invariant(false) : void 0;
23
24
  return relay;
@@ -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,11 @@
11
11
  'use strict';
12
12
 
13
13
  var invariant = require('invariant');
14
-
15
14
  /**
16
15
  * Fail fast if the user supplies invalid fragments as input.
17
16
  */
17
+
18
+
18
19
  function assertFragmentMap(componentName, fragmentSpec) {
19
20
  !(fragmentSpec && typeof fragmentSpec === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Could not create Relay Container for `%s`. ' + 'Expected a set of GraphQL fragments, got `%s` instead.', componentName, fragmentSpec) : invariant(false) : void 0;
20
21
 
@@ -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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
16
16
 
17
- var React = require('react');
17
+ var assertFragmentMap = require('./assertFragmentMap');
18
+
19
+ var _require = require('./ReactRelayContainerUtils'),
20
+ getComponentName = _require.getComponentName,
21
+ getContainerName = _require.getContainerName;
18
22
 
19
23
  var ReactRelayContext = require('./ReactRelayContext');
20
24
 
21
25
  var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
22
26
 
23
- var assertFragmentMap = require('./assertFragmentMap');
27
+ var readContext = require('./readContext');
24
28
 
25
29
  var invariant = require('invariant');
26
30
 
27
- var readContext = require('./readContext');
28
-
29
- var _require = require('./ReactRelayContainerUtils'),
30
- getComponentName = _require.getComponentName,
31
- getContainerName = _require.getContainerName;
31
+ var React = require('react');
32
32
 
33
33
  var _require2 = require('relay-runtime'),
34
34
  getFragment = _require2.getFragment;
@@ -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.
@@ -28,8 +28,7 @@ function getRootVariablesForFragments(fragments, props) {
28
28
  var fragmentNode = fragments[key];
29
29
  var fragmentRef = props[key];
30
30
  var selector = getSelector(fragmentNode, fragmentRef);
31
- var fragmentOwnerVariables = selector != null && selector.kind === 'PluralReaderSelector' ? (_selector$selectors$ = (_selector$selectors$2 = selector.selectors[0]) === null || _selector$selectors$2 === void 0 ? void 0 : _selector$selectors$2.owner.variables) !== null && _selector$selectors$ !== void 0 ? _selector$selectors$ : {} : (_selector$owner$varia = selector === null || selector === void 0 ? void 0 : selector.owner.variables) !== null && _selector$owner$varia !== void 0 ? _selector$owner$varia : {}; // $FlowFixMe[cannot-spread-interface]
32
-
31
+ var fragmentOwnerVariables = selector != null && selector.kind === 'PluralReaderSelector' ? (_selector$selectors$ = (_selector$selectors$2 = selector.selectors[0]) === null || _selector$selectors$2 === void 0 ? void 0 : _selector$selectors$2.owner.variables) !== null && _selector$selectors$ !== void 0 ? _selector$selectors$ : {} : (_selector$owner$varia = selector === null || selector === void 0 ? void 0 : selector.owner.variables) !== null && _selector$owner$varia !== void 0 ? _selector$owner$varia : {};
33
32
  rootVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fragmentOwnerVariables);
34
33
  });
35
34
  return rootVariables;
package/lib/hooks.js CHANGED
@@ -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.
@@ -12,11 +12,12 @@
12
12
 
13
13
  var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
14
14
 
15
- var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
15
+ var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
16
16
 
17
- var RelayRuntime = require('relay-runtime');
17
+ var _require = require('./relay-hooks/loadQuery'),
18
+ loadQuery = _require.loadQuery;
18
19
 
19
- var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
20
+ var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
20
21
 
21
22
  var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
22
23
 
@@ -40,8 +41,7 @@ var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInval
40
41
 
41
42
  var useSubscription = require('./relay-hooks/useSubscription');
42
43
 
43
- var _require = require('./relay-hooks/loadQuery'),
44
- loadQuery = _require.loadQuery;
44
+ var RelayRuntime = require('relay-runtime');
45
45
 
46
46
  /**
47
47
  * The public interface for Relay Hooks.
package/lib/index.js CHANGED
@@ -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,8 +10,6 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
14
-
15
13
  var ReactRelayContext = require('./ReactRelayContext');
16
14
 
17
15
  var ReactRelayFragmentContainer = require('./ReactRelayFragmentContainer');
@@ -24,12 +22,15 @@ var ReactRelayQueryRenderer = require('./ReactRelayQueryRenderer');
24
22
 
25
23
  var ReactRelayRefetchContainer = require('./ReactRelayRefetchContainer');
26
24
 
27
- var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
28
-
29
- var RelayRuntime = require('relay-runtime');
25
+ var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
30
26
 
31
27
  var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
32
28
 
29
+ var _require = require('./relay-hooks/loadQuery'),
30
+ loadQuery = _require.loadQuery;
31
+
32
+ var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
33
+
33
34
  var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
34
35
 
35
36
  var useFragment = require('./relay-hooks/useFragment');
@@ -52,8 +53,7 @@ var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInval
52
53
 
53
54
  var useSubscription = require('./relay-hooks/useSubscription');
54
55
 
55
- var _require = require('./relay-hooks/loadQuery'),
56
- loadQuery = _require.loadQuery;
56
+ var RelayRuntime = require('relay-runtime');
57
57
 
58
58
  /**
59
59
  * The public interface to react-relay.
@@ -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.