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