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