react-relay 14.1.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) 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 +19 -5
  9. package/ReactRelayQueryRenderer.js.flow +32 -1
  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 +1 -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 +7 -5
  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 +2 -2
  47. package/lib/ReactRelayContext.js +3 -3
  48. package/lib/ReactRelayFragmentContainer.js +39 -66
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -3
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -30
  51. package/lib/ReactRelayPaginationContainer.js +66 -159
  52. package/lib/ReactRelayQueryFetcher.js +48 -74
  53. package/lib/ReactRelayQueryRenderer.js +62 -82
  54. package/lib/ReactRelayQueryRendererContext.js +2 -1
  55. package/lib/ReactRelayRefetchContainer.js +52 -99
  56. package/lib/ReactRelayTestMocker.js +32 -66
  57. package/lib/ReactRelayTypes.js +2 -0
  58. package/lib/RelayContext.js +4 -6
  59. package/lib/assertFragmentMap.js +3 -4
  60. package/lib/buildReactRelayContainer.js +10 -25
  61. package/lib/getRootVariablesForFragments.js +5 -8
  62. package/lib/hooks.js +5 -17
  63. package/lib/index.js +5 -24
  64. package/lib/isRelayEnvironment.js +5 -3
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -7
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
  74. package/lib/relay-hooks/FragmentResource.js +102 -196
  75. package/lib/relay-hooks/HooksImplementation.js +2 -5
  76. package/lib/relay-hooks/InternalLogger.js +2 -2
  77. package/lib/relay-hooks/LRUCache.js +2 -19
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
  79. package/lib/relay-hooks/MatchContainer.js +14 -22
  80. package/lib/relay-hooks/ProfilerContext.js +3 -2
  81. package/lib/relay-hooks/QueryResource.js +30 -99
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
  83. package/lib/relay-hooks/SuspenseResource.js +8 -31
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +41 -77
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
  99. package/lib/relay-hooks/useClientQuery.js +3 -6
  100. package/lib/relay-hooks/useEntryPointLoader.js +17 -36
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
  102. package/lib/relay-hooks/useFragment.js +8 -18
  103. package/lib/relay-hooks/useFragmentNode.js +20 -31
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -5
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
  109. package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
  111. package/lib/relay-hooks/useMemoVariables.js +15 -33
  112. package/lib/relay-hooks/useMutation.js +8 -25
  113. package/lib/relay-hooks/usePaginationFragment.js +61 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +12 -29
  115. package/lib/relay-hooks/useQueryLoader.js +23 -47
  116. package/lib/relay-hooks/useRefetchableFragment.js +8 -18
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -7
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
  121. package/lib/relay-hooks/useSubscription.js +5 -9
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +1 -1
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
  135. package/relay-hooks/FragmentResource.js.flow +34 -8
  136. package/relay-hooks/HooksImplementation.js.flow +1 -1
  137. package/relay-hooks/InternalLogger.js.flow +1 -1
  138. package/relay-hooks/LRUCache.js.flow +1 -1
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
  140. package/relay-hooks/MatchContainer.js.flow +1 -1
  141. package/relay-hooks/ProfilerContext.js.flow +1 -1
  142. package/relay-hooks/QueryResource.js.flow +25 -5
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  144. package/relay-hooks/SuspenseResource.js.flow +1 -1
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
  153. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
  169. package/relay-hooks/useClientQuery.js.flow +1 -1
  170. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  171. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  172. package/relay-hooks/useFragment.js.flow +2 -2
  173. package/relay-hooks/useFragmentNode.js.flow +5 -4
  174. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  179. package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  181. package/relay-hooks/useMemoVariables.js.flow +13 -29
  182. package/relay-hooks/useMutation.js.flow +4 -4
  183. package/relay-hooks/usePaginationFragment.js.flow +53 -46
  184. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  185. package/relay-hooks/useQueryLoader.js.flow +85 -22
  186. package/relay-hooks/useRefetchableFragment.js.flow +64 -33
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  191. package/relay-hooks/useSubscription.js.flow +1 -1
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -27
  194. package/readContext.js.flow +0 -29
@@ -6,34 +6,27 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
-
16
16
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
17
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
19
-
20
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
-
22
19
  var ReactRelayContext = require('./ReactRelayContext');
23
-
24
20
  var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
25
-
26
21
  var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
27
-
28
22
  var areEqual = require("fbjs/lib/areEqual");
29
-
30
23
  var React = require('react');
31
-
32
24
  var _require = require('relay-runtime'),
33
- createOperationDescriptor = _require.createOperationDescriptor,
34
- deepFreeze = _require.deepFreeze,
35
- getRequest = _require.getRequest;
36
-
25
+ RelayFeatureFlags = _require.RelayFeatureFlags;
26
+ var _require2 = require('relay-runtime'),
27
+ createOperationDescriptor = _require2.createOperationDescriptor,
28
+ deepFreeze = _require2.deepFreeze,
29
+ getRequest = _require2.getRequest;
37
30
  /**
38
31
  * React may double-fire the constructor, and we call 'fetch' in the
39
32
  * constructor. If a request is already in flight from a previous call to the
@@ -43,7 +36,6 @@ var requestCache = {};
43
36
  var queryRendererContext = {
44
37
  rootIsQueryRenderer: true
45
38
  };
46
-
47
39
  /**
48
40
  * @public
49
41
  *
@@ -56,33 +48,29 @@ var queryRendererContext = {
56
48
  */
57
49
  var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
58
50
  (0, _inheritsLoose2["default"])(ReactRelayQueryRenderer, _React$Component);
59
-
60
51
  function ReactRelayQueryRenderer(props) {
61
52
  var _this;
53
+ _this = _React$Component.call(this, props) || this;
62
54
 
63
- _this = _React$Component.call(this, props) || this; // Callbacks are attached to the current instance and shared with static
55
+ // Callbacks are attached to the current instance and shared with static
64
56
  // lifecyles by bundling with state. This is okay to do because the
65
57
  // callbacks don't change in reaction to props. However we should not
66
58
  // "leak" them before mounting (since we would be unable to clean up). For
67
59
  // that reason, we define them as null initially and fill them in after
68
60
  // mounting to avoid leaking memory.
69
-
70
61
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleDataChange", function (params) {
71
62
  var error = params.error == null ? null : params.error;
72
63
  var snapshot = params.snapshot == null ? null : params.snapshot;
73
-
74
64
  _this.setState(function (prevState) {
75
65
  var prevRequestCacheKey = prevState.requestCacheKey;
76
-
77
66
  if (prevRequestCacheKey) {
78
67
  delete requestCache[prevRequestCacheKey];
79
- } // Don't update state if nothing has changed.
80
-
68
+ }
81
69
 
70
+ // Don't update state if nothing has changed.
82
71
  if (snapshot === prevState.snapshot && error === prevState.error) {
83
72
  return null;
84
73
  }
85
-
86
74
  return {
87
75
  renderProps: getRenderProps(error, snapshot, prevState.queryFetcher, prevState.retryCallbacks),
88
76
  snapshot: snapshot,
@@ -96,7 +84,6 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
96
84
  };
97
85
  var queryFetcher;
98
86
  var requestCacheKey;
99
-
100
87
  if (props.query) {
101
88
  var query = props.query;
102
89
  var request = getRequest(query);
@@ -105,7 +92,6 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
105
92
  } else {
106
93
  queryFetcher = new ReactRelayQueryFetcher();
107
94
  }
108
-
109
95
  _this._maybeHiddenOrFastRefresh = false;
110
96
  _this.state = (0, _objectSpread2["default"])({
111
97
  prevPropsEnvironment: props.environment,
@@ -116,20 +102,15 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
116
102
  }, fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks, requestCacheKey));
117
103
  return _this;
118
104
  }
119
-
120
105
  ReactRelayQueryRenderer.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
121
106
  if (prevState.prevQuery !== nextProps.query || prevState.prevPropsEnvironment !== nextProps.environment || !areEqual(prevState.prevPropsVariables, nextProps.variables)) {
122
107
  return resetQueryStateForUpdate(nextProps, prevState);
123
108
  }
124
-
125
109
  return null;
126
110
  };
127
-
128
111
  var _proto = ReactRelayQueryRenderer.prototype;
129
-
130
112
  _proto.componentDidMount = function componentDidMount() {
131
113
  var _this2 = this;
132
-
133
114
  if (this._maybeHiddenOrFastRefresh === true) {
134
115
  // This block only runs if the component has previously "unmounted"
135
116
  // due to it being hidden by the Offscreen API, or during fast refresh.
@@ -137,94 +118,104 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
137
118
  // by the previous cleanup, so instead of attempting to
138
119
  // do our regular commit setup, so that the query is re-evaluated
139
120
  // (and potentially cause a refetch).
140
- this._maybeHiddenOrFastRefresh = false; // eslint-disable-next-line react/no-did-mount-set-state
141
-
121
+ this._maybeHiddenOrFastRefresh = false;
122
+ // eslint-disable-next-line react/no-did-mount-set-state
142
123
  this.setState(function (prevState) {
143
- return resetQueryStateForUpdate(_this2.props, prevState);
124
+ var newState = resetQueryStateForUpdate(_this2.props, prevState);
125
+ var requestCacheKey = newState.requestCacheKey,
126
+ queryFetcher = newState.queryFetcher;
127
+ if (requestCacheKey != null && requestCache[requestCacheKey] != null) {
128
+ if (RelayFeatureFlags.ENABLE_QUERY_RENDERER_SET_STATE_PREVENTION) {
129
+ var fetchResult = queryFetcher.getFetchResult();
130
+ if (fetchResult != null) {
131
+ var _fetchResult$snapshot, _fetchResult$error;
132
+ var snapshot = (_fetchResult$snapshot = fetchResult.snapshot) !== null && _fetchResult$snapshot !== void 0 ? _fetchResult$snapshot : null;
133
+ var error = (_fetchResult$error = fetchResult.error) !== null && _fetchResult$error !== void 0 ? _fetchResult$error : null;
134
+ var prevRequestCacheKey = prevState.requestCacheKey;
135
+ if (prevRequestCacheKey != null) {
136
+ delete requestCache[prevRequestCacheKey];
137
+ }
138
+ newState.renderProps = getRenderProps(error, snapshot, queryFetcher, prevState.retryCallbacks);
139
+ newState.snapshot = snapshot;
140
+ newState.requestCacheKey = null;
141
+ } else {
142
+ queryFetcher.setOnDataChange(_this2._handleDataChange);
143
+ }
144
+ } else {
145
+ queryFetcher.setOnDataChange(_this2._handleDataChange);
146
+ }
147
+ }
148
+ return newState;
144
149
  });
145
150
  return;
146
151
  }
147
-
148
152
  var _this$state = this.state,
149
- retryCallbacks = _this$state.retryCallbacks,
150
- queryFetcher = _this$state.queryFetcher,
151
- requestCacheKey = _this$state.requestCacheKey; // We don't need to cache the request after the component commits
152
-
153
+ retryCallbacks = _this$state.retryCallbacks,
154
+ queryFetcher = _this$state.queryFetcher,
155
+ requestCacheKey = _this$state.requestCacheKey;
156
+ // We don't need to cache the request after the component commits
153
157
  if (requestCacheKey) {
154
158
  delete requestCache[requestCacheKey];
155
159
  }
156
-
157
160
  retryCallbacks.handleDataChange = this._handleDataChange;
158
-
159
161
  retryCallbacks.handleRetryAfterError = function (error) {
160
162
  return _this2.setState(function (prevState) {
161
163
  var prevRequestCacheKey = prevState.requestCacheKey;
162
-
163
164
  if (prevRequestCacheKey) {
164
165
  delete requestCache[prevRequestCacheKey];
165
166
  }
166
-
167
167
  return {
168
168
  renderProps: getLoadingRenderProps(),
169
169
  requestCacheKey: null
170
170
  };
171
171
  });
172
- }; // Re-initialize the ReactRelayQueryFetcher with callbacks.
173
- // If data has changed since constructions, this will re-render.
174
-
172
+ };
175
173
 
174
+ // Re-initialize the ReactRelayQueryFetcher with callbacks.
175
+ // If data has changed since constructions, this will re-render.
176
176
  if (this.props.query) {
177
177
  queryFetcher.setOnDataChange(this._handleDataChange);
178
178
  }
179
179
  };
180
-
181
180
  _proto.componentDidUpdate = function componentDidUpdate(_prevProps, prevState) {
182
181
  // We don't need to cache the request after the component commits
183
182
  var _this$state2 = this.state,
184
- queryFetcher = _this$state2.queryFetcher,
185
- requestCacheKey = _this$state2.requestCacheKey;
186
-
183
+ queryFetcher = _this$state2.queryFetcher,
184
+ requestCacheKey = _this$state2.requestCacheKey;
187
185
  if (requestCacheKey) {
188
- delete requestCache[requestCacheKey]; // HACK
189
-
186
+ delete requestCache[requestCacheKey];
187
+ // HACK
190
188
  delete this.state.requestCacheKey;
191
189
  }
192
-
193
190
  if (this.props.query && queryFetcher !== prevState.queryFetcher) {
194
191
  queryFetcher.setOnDataChange(this._handleDataChange);
195
192
  }
196
193
  };
197
-
198
194
  _proto.componentWillUnmount = function componentWillUnmount() {
199
195
  this.state.queryFetcher.dispose();
200
196
  this._maybeHiddenOrFastRefresh = true;
201
197
  };
202
-
203
198
  _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
204
199
  return nextProps.render !== this.props.render || nextState.renderProps !== this.state.renderProps;
205
200
  };
206
-
207
201
  _proto.render = function render() {
208
202
  var _this$state3 = this.state,
209
- renderProps = _this$state3.renderProps,
210
- relayContext = _this$state3.relayContext; // Note that the root fragment results in `renderProps.props` is already
203
+ renderProps = _this$state3.renderProps,
204
+ relayContext = _this$state3.relayContext;
205
+ // Note that the root fragment results in `renderProps.props` is already
211
206
  // frozen by the store; this call is to freeze the renderProps object and
212
207
  // error property if set.
213
-
214
208
  if (process.env.NODE_ENV !== "production") {
215
209
  deepFreeze(renderProps);
216
210
  }
217
-
218
211
  return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
219
212
  value: relayContext
220
213
  }, /*#__PURE__*/React.createElement(ReactRelayQueryRendererContext.Provider, {
221
214
  value: queryRendererContext
222
215
  }, this.props.render(renderProps)));
223
216
  };
224
-
225
217
  return ReactRelayQueryRenderer;
226
218
  }(React.Component);
227
-
228
219
  function getLoadingRenderProps() {
229
220
  return {
230
221
  error: null,
@@ -233,7 +224,6 @@ function getLoadingRenderProps() {
233
224
  retry: null
234
225
  };
235
226
  }
236
-
237
227
  function getEmptyRenderProps() {
238
228
  return {
239
229
  error: null,
@@ -242,14 +232,12 @@ function getEmptyRenderProps() {
242
232
  retry: null
243
233
  };
244
234
  }
245
-
246
235
  function getRenderProps(error, snapshot, queryFetcher, retryCallbacks) {
247
236
  return {
248
237
  error: error ? error : null,
249
238
  props: snapshot ? snapshot.data : null,
250
239
  retry: function retry(cacheConfigOverride) {
251
240
  var syncSnapshot = queryFetcher.retry(cacheConfigOverride);
252
-
253
241
  if (syncSnapshot && typeof retryCallbacks.handleDataChange === 'function') {
254
242
  retryCallbacks.handleDataChange({
255
243
  snapshot: syncSnapshot
@@ -262,20 +250,17 @@ function getRenderProps(error, snapshot, queryFetcher, retryCallbacks) {
262
250
  }
263
251
  };
264
252
  }
265
-
266
253
  function getRequestCacheKey(request, variables) {
267
254
  return JSON.stringify({
268
255
  id: request.cacheID ? request.cacheID : request.id,
269
256
  variables: variables
270
257
  });
271
258
  }
272
-
273
259
  function resetQueryStateForUpdate(props, prevState) {
274
260
  var query = props.query;
275
261
  var prevSelectionReferences = prevState.queryFetcher.getSelectionReferences();
276
262
  prevState.queryFetcher.disposeRequest();
277
263
  var queryFetcher;
278
-
279
264
  if (query) {
280
265
  var request = getRequest(query);
281
266
  var requestCacheKey = getRequestCacheKey(request.params, props.variables);
@@ -283,35 +268,33 @@ function resetQueryStateForUpdate(props, prevState) {
283
268
  } else {
284
269
  queryFetcher = new ReactRelayQueryFetcher(prevSelectionReferences);
285
270
  }
286
-
287
271
  return (0, _objectSpread2["default"])({
288
272
  prevQuery: props.query,
289
273
  prevPropsEnvironment: props.environment,
290
274
  prevPropsVariables: props.variables,
291
275
  queryFetcher: queryFetcher
292
- }, fetchQueryAndComputeStateFromProps(props, queryFetcher, prevState.retryCallbacks // passing no requestCacheKey will cause it to be recalculated internally
276
+ }, fetchQueryAndComputeStateFromProps(props, queryFetcher, prevState.retryCallbacks
277
+ // passing no requestCacheKey will cause it to be recalculated internally
293
278
  // and we want the updated requestCacheKey, since variables may have changed
294
279
  ));
295
280
  }
296
281
 
297
282
  function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks, requestCacheKey) {
298
283
  var environment = props.environment,
299
- query = props.query,
300
- variables = props.variables,
301
- cacheConfig = props.cacheConfig;
284
+ query = props.query,
285
+ variables = props.variables,
286
+ cacheConfig = props.cacheConfig;
302
287
  var genericEnvironment = environment;
303
-
304
288
  if (query) {
305
289
  var request = getRequest(query);
306
290
  var operation = createOperationDescriptor(request, variables, cacheConfig);
307
291
  var relayContext = {
308
292
  environment: genericEnvironment
309
293
  };
310
-
311
294
  if (typeof requestCacheKey === 'string' && requestCache[requestCacheKey]) {
312
295
  // This same request is already in flight.
313
- var snapshot = requestCache[requestCacheKey].snapshot;
314
296
 
297
+ var snapshot = requestCache[requestCacheKey].snapshot;
315
298
  if (snapshot) {
316
299
  // Use the cached response
317
300
  return {
@@ -332,24 +315,23 @@ function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks,
332
315
  };
333
316
  }
334
317
  }
335
-
336
318
  try {
337
319
  var storeSnapshot = queryFetcher.lookupInStore(genericEnvironment, operation, props.fetchPolicy);
338
320
  var querySnapshot = queryFetcher.fetch({
339
321
  environment: genericEnvironment,
340
322
  onDataChange: null,
341
323
  operation: operation
342
- }); // Use network data first, since it may be fresher
343
-
344
- var _snapshot = querySnapshot || storeSnapshot; // cache the request to avoid duplicate requests
324
+ });
345
325
 
326
+ // Use network data first, since it may be fresher
327
+ var _snapshot = querySnapshot || storeSnapshot;
346
328
 
329
+ // cache the request to avoid duplicate requests
347
330
  requestCacheKey = requestCacheKey || getRequestCacheKey(request.params, props.variables);
348
331
  requestCache[requestCacheKey] = {
349
332
  queryFetcher: queryFetcher,
350
333
  snapshot: _snapshot
351
334
  };
352
-
353
335
  if (!_snapshot) {
354
336
  return {
355
337
  error: null,
@@ -359,7 +341,6 @@ function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks,
359
341
  requestCacheKey: requestCacheKey
360
342
  };
361
343
  }
362
-
363
344
  return {
364
345
  error: null,
365
346
  relayContext: relayContext,
@@ -386,7 +367,6 @@ function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks,
386
367
  relayContext: _relayContext,
387
368
  renderProps: getEmptyRenderProps(),
388
369
  requestCacheKey: null // if there is an error, don't cache request
389
-
390
370
  };
391
371
  }
392
372
  }
@@ -6,11 +6,12 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var React = require('react');
13
-
14
15
  module.exports = React.createContext({
15
16
  rootIsQueryRenderer: false
16
17
  });