react-relay 18.0.0 → 18.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +2 -5
- package/buildReactRelayContainer.js.flow +1 -0
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/index.js.flow +3 -0
- package/legacy.js +1 -1
- package/lib/index.js +2 -0
- package/lib/relay-hooks/getConnectionState.js +47 -0
- package/lib/relay-hooks/legacy/FragmentResource.js +3 -8
- package/lib/relay-hooks/loadQuery.js +5 -14
- package/lib/relay-hooks/readFragmentInternal.js +2 -4
- package/lib/relay-hooks/useFragmentInternal.js +1 -1
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +3 -10
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +6 -28
- package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
- package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
- package/lib/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js +227 -0
- package/lib/relay-hooks/useQueryLoader.js +8 -0
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
- 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 +1 -1
- package/react-relay-legacy.min.js +1 -1
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +2 -2
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/getConnectionState.js.flow +97 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +4 -16
- package/relay-hooks/loadQuery.js.flow +30 -38
- package/relay-hooks/readFragmentInternal.js.flow +1 -10
- package/relay-hooks/useFragmentInternal.js.flow +1 -1
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +7 -22
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +8 -56
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
- package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +433 -0
- package/relay-hooks/useQueryLoader.js.flow +27 -3
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
|
+
var useFragment = require('./useFragment');
|
6
|
+
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
7
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
|
8
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
|
+
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
10
|
+
var invariant = require('invariant');
|
11
|
+
var _require = require('react'),
|
12
|
+
useCallback = _require.useCallback,
|
13
|
+
useDebugValue = _require.useDebugValue,
|
14
|
+
useEffect = _require.useEffect,
|
15
|
+
useLayoutEffect = _require.useLayoutEffect,
|
16
|
+
useMemo = _require.useMemo,
|
17
|
+
useRef = _require.useRef,
|
18
|
+
useState = _require.useState;
|
19
|
+
var _require2 = require('relay-runtime'),
|
20
|
+
getFragment = _require2.getFragment,
|
21
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
22
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
23
|
+
var _require3 = require('relay-runtime'),
|
24
|
+
ConnectionInterface = _require3.ConnectionInterface,
|
25
|
+
getSelector = _require3.getSelector,
|
26
|
+
getValueAtPath = _require3.getValueAtPath;
|
27
|
+
function usePrefetchableForwardPaginationFragment_EXPERIMENTAL(fragmentInput, parentFragmentRef, bufferSize, initialSize, prefetchingLoadMoreOptions) {
|
28
|
+
var _fragmentInput$metada, _fragmentInput$metada2;
|
29
|
+
var minimalFetchSize = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
30
|
+
var fragmentNode = getFragment(fragmentInput);
|
31
|
+
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePrefetchableForwardPaginationFragment_EXPERIMENTAL()');
|
32
|
+
var componentDisplayName = 'usePrefetchableForwardPaginationFragment_EXPERIMENTAL()';
|
33
|
+
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
34
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
35
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
36
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata;
|
37
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
|
38
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
39
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
40
|
+
refetch = _useRefetchableFragme.refetch;
|
41
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
42
|
+
var edgeKeys = useMemo(function () {
|
43
|
+
var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
|
44
|
+
if (connection == null) {
|
45
|
+
return null;
|
46
|
+
}
|
47
|
+
var _ConnectionInterface$ = ConnectionInterface.get(),
|
48
|
+
EDGES = _ConnectionInterface$.EDGES;
|
49
|
+
return connection[EDGES];
|
50
|
+
}, [connectionPathInFragmentData, fragmentData]);
|
51
|
+
var sourceSize = edgeKeys == null ? -1 : edgeKeys.length;
|
52
|
+
var _useState = useState(initialSize != null ? initialSize : sourceSize),
|
53
|
+
_numInUse = _useState[0],
|
54
|
+
setNumInUse = _useState[1];
|
55
|
+
var numInUse = _numInUse;
|
56
|
+
if (_numInUse === -1 && sourceSize !== -1) {
|
57
|
+
numInUse = initialSize != null ? initialSize : sourceSize;
|
58
|
+
setNumInUse(numInUse);
|
59
|
+
}
|
60
|
+
var environment = useRelayEnvironment();
|
61
|
+
var _useState2 = useState(false),
|
62
|
+
isLoadingMore = _useState2[0],
|
63
|
+
reallySetIsLoadingMore = _useState2[1];
|
64
|
+
var _useState3 = useState(false),
|
65
|
+
isRefetching = _useState3[0],
|
66
|
+
setIsRefetching = _useState3[1];
|
67
|
+
var availableSizeRef = useRef(0);
|
68
|
+
var setIsLoadingMore = useCallback(function (value) {
|
69
|
+
var _environment$getSched;
|
70
|
+
var schedule = (_environment$getSched = environment.getScheduler()) === null || _environment$getSched === void 0 ? void 0 : _environment$getSched.schedule;
|
71
|
+
if (schedule) {
|
72
|
+
schedule(function () {
|
73
|
+
reallySetIsLoadingMore(value);
|
74
|
+
});
|
75
|
+
} else {
|
76
|
+
reallySetIsLoadingMore(value);
|
77
|
+
}
|
78
|
+
}, [environment]);
|
79
|
+
var isLoadingMoreRef = useRef(false);
|
80
|
+
var observer = useMemo(function () {
|
81
|
+
return {
|
82
|
+
start: function start() {
|
83
|
+
isLoadingMoreRef.current = true;
|
84
|
+
reallySetIsLoadingMore(true);
|
85
|
+
},
|
86
|
+
complete: function complete() {
|
87
|
+
isLoadingMoreRef.current = false;
|
88
|
+
setIsLoadingMore(false);
|
89
|
+
},
|
90
|
+
error: function error() {
|
91
|
+
isLoadingMoreRef.current = false;
|
92
|
+
setIsLoadingMore(false);
|
93
|
+
}
|
94
|
+
};
|
95
|
+
}, [setIsLoadingMore]);
|
96
|
+
var handleReset = useCallback(function () {
|
97
|
+
if (!isRefetching) {
|
98
|
+
var _environment$getSched2;
|
99
|
+
var schedule = (_environment$getSched2 = environment.getScheduler()) === null || _environment$getSched2 === void 0 ? void 0 : _environment$getSched2.schedule;
|
100
|
+
if (schedule) {
|
101
|
+
schedule(function () {
|
102
|
+
setNumInUse(-1);
|
103
|
+
});
|
104
|
+
} else {
|
105
|
+
setNumInUse(-1);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
isLoadingMoreRef.current = false;
|
109
|
+
setIsLoadingMore(false);
|
110
|
+
}, [environment, isRefetching, setIsLoadingMore]);
|
111
|
+
var _useLoadMoreFunction = useLoadMoreFunction({
|
112
|
+
componentDisplayName: componentDisplayName,
|
113
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
114
|
+
direction: 'forward',
|
115
|
+
fragmentData: fragmentData,
|
116
|
+
fragmentIdentifier: fragmentIdentifier,
|
117
|
+
fragmentNode: fragmentNode,
|
118
|
+
fragmentRef: fragmentRef,
|
119
|
+
paginationMetadata: paginationMetadata,
|
120
|
+
paginationRequest: paginationRequest,
|
121
|
+
observer: observer,
|
122
|
+
onReset: handleReset
|
123
|
+
}),
|
124
|
+
loadMore = _useLoadMoreFunction[0],
|
125
|
+
hasNext = _useLoadMoreFunction[1],
|
126
|
+
disposeFetchNext = _useLoadMoreFunction[2];
|
127
|
+
useLayoutEffect(function () {
|
128
|
+
availableSizeRef.current = sourceSize - numInUse;
|
129
|
+
}, [numInUse, sourceSize]);
|
130
|
+
var prefetchingUNSTABLE_extraVariables = prefetchingLoadMoreOptions === null || prefetchingLoadMoreOptions === void 0 ? void 0 : prefetchingLoadMoreOptions.UNSTABLE_extraVariables;
|
131
|
+
var prefetchingOnComplete = prefetchingLoadMoreOptions === null || prefetchingLoadMoreOptions === void 0 ? void 0 : prefetchingLoadMoreOptions.onComplete;
|
132
|
+
var showMore = useCallback(function (numToAdd, options) {
|
133
|
+
if (!isLoadingMoreRef.current || availableSizeRef.current >= 0) {
|
134
|
+
availableSizeRef.current -= numToAdd;
|
135
|
+
setNumInUse(function (lastNumInUse) {
|
136
|
+
return lastNumInUse + numToAdd;
|
137
|
+
});
|
138
|
+
if (!isLoadingMoreRef.current && availableSizeRef.current < 0) {
|
139
|
+
loadMore(Math.max(minimalFetchSize, Math.min(numToAdd, bufferSize - availableSizeRef.current)), options !== null && options !== void 0 ? options : {
|
140
|
+
onComplete: prefetchingOnComplete,
|
141
|
+
UNSTABLE_extraVariables: typeof prefetchingUNSTABLE_extraVariables === 'function' ? prefetchingUNSTABLE_extraVariables({
|
142
|
+
hasNext: hasNext,
|
143
|
+
data: fragmentData,
|
144
|
+
getServerEdges: function getServerEdges() {
|
145
|
+
var selector = getSelector(edgesFragment, edgeKeys);
|
146
|
+
if (selector == null) {
|
147
|
+
return [];
|
148
|
+
}
|
149
|
+
!(selector.kind === 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected a plural selector') : invariant(false) : void 0;
|
150
|
+
return selector.selectors.map(function (sel) {
|
151
|
+
return environment.lookup(sel).data;
|
152
|
+
});
|
153
|
+
}
|
154
|
+
}) : prefetchingUNSTABLE_extraVariables
|
155
|
+
});
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}, [bufferSize, loadMore, minimalFetchSize, edgeKeys, fragmentData, prefetchingUNSTABLE_extraVariables, prefetchingOnComplete]);
|
159
|
+
var edgesFragment = (_fragmentInput$metada = fragmentInput.metadata) === null || _fragmentInput$metada === void 0 ? void 0 : (_fragmentInput$metada2 = _fragmentInput$metada.refetch) === null || _fragmentInput$metada2 === void 0 ? void 0 : _fragmentInput$metada2.edgesFragment;
|
160
|
+
!(edgesFragment != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePrefetchableForwardPaginationFragment_EXPERIMENTAL: Expected the edge fragment to be defined, ' + 'please make sure you have added `prefetchable_pagination: true` to `@connection`') : invariant(false) : void 0;
|
161
|
+
useEffect(function () {
|
162
|
+
if (!isLoadingMoreRef.current && !isLoadingMore && !isRefetching && hasNext && (sourceSize - numInUse < bufferSize || numInUse > sourceSize)) {
|
163
|
+
var onComplete = prefetchingOnComplete;
|
164
|
+
loadMore(Math.max(bufferSize - Math.max(sourceSize - numInUse, 0), numInUse - sourceSize, minimalFetchSize), {
|
165
|
+
onComplete: onComplete,
|
166
|
+
UNSTABLE_extraVariables: typeof prefetchingUNSTABLE_extraVariables === 'function' ? prefetchingUNSTABLE_extraVariables({
|
167
|
+
hasNext: hasNext,
|
168
|
+
data: fragmentData,
|
169
|
+
getServerEdges: function getServerEdges() {
|
170
|
+
var selector = getSelector(edgesFragment, edgeKeys);
|
171
|
+
if (selector == null) {
|
172
|
+
return [];
|
173
|
+
}
|
174
|
+
!(selector.kind === 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected a plural selector') : invariant(false) : void 0;
|
175
|
+
return selector.selectors.map(function (sel) {
|
176
|
+
return environment.lookup(sel).data;
|
177
|
+
});
|
178
|
+
}
|
179
|
+
}) : prefetchingUNSTABLE_extraVariables
|
180
|
+
});
|
181
|
+
}
|
182
|
+
}, [hasNext, bufferSize, isRefetching, loadMore, numInUse, prefetchingUNSTABLE_extraVariables, prefetchingOnComplete, sourceSize, edgeKeys, isLoadingMore, minimalFetchSize, environment, edgesFragment]);
|
183
|
+
var realNumInUse = Math.min(numInUse, sourceSize);
|
184
|
+
var derivedEdgeKeys = useMemo(function () {
|
185
|
+
var _edgeKeys$slice;
|
186
|
+
return (_edgeKeys$slice = edgeKeys === null || edgeKeys === void 0 ? void 0 : edgeKeys.slice(0, realNumInUse)) !== null && _edgeKeys$slice !== void 0 ? _edgeKeys$slice : [];
|
187
|
+
}, [edgeKeys, realNumInUse]);
|
188
|
+
var edges = useFragment(edgesFragment, derivedEdgeKeys);
|
189
|
+
var refetchPagination = useCallback(function (variables, options) {
|
190
|
+
disposeFetchNext();
|
191
|
+
setIsRefetching(true);
|
192
|
+
return refetch(variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
193
|
+
onComplete: function onComplete(maybeError) {
|
194
|
+
var _environment$getSched3, _options$onComplete;
|
195
|
+
var schedule = (_environment$getSched3 = environment.getScheduler()) === null || _environment$getSched3 === void 0 ? void 0 : _environment$getSched3.schedule;
|
196
|
+
if (schedule) {
|
197
|
+
schedule(function () {
|
198
|
+
setIsRefetching(false);
|
199
|
+
setNumInUse(-1);
|
200
|
+
});
|
201
|
+
} else {
|
202
|
+
setIsRefetching(false);
|
203
|
+
setNumInUse(-1);
|
204
|
+
}
|
205
|
+
options === null || options === void 0 ? void 0 : (_options$onComplete = options.onComplete) === null || _options$onComplete === void 0 ? void 0 : _options$onComplete.call(options, maybeError);
|
206
|
+
},
|
207
|
+
__environment: undefined
|
208
|
+
}));
|
209
|
+
}, [disposeFetchNext, environment, refetch]);
|
210
|
+
if (process.env.NODE_ENV !== "production") {
|
211
|
+
useDebugValue({
|
212
|
+
fragment: fragmentNode.name,
|
213
|
+
data: fragmentData,
|
214
|
+
hasNext: hasNext,
|
215
|
+
isLoadingNext: isLoadingMore
|
216
|
+
});
|
217
|
+
}
|
218
|
+
return {
|
219
|
+
edges: edges,
|
220
|
+
data: fragmentData,
|
221
|
+
loadNext: showMore,
|
222
|
+
hasNext: hasNext || sourceSize > numInUse,
|
223
|
+
isLoadingNext: isLoadingMore && numInUse > sourceSize,
|
224
|
+
refetch: refetchPagination
|
225
|
+
};
|
226
|
+
}
|
227
|
+
module.exports = usePrefetchableForwardPaginationFragment_EXPERIMENTAL;
|
@@ -5,6 +5,7 @@ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime
|
|
5
5
|
var _require = require('./loadQuery'),
|
6
6
|
loadQuery = _require.loadQuery;
|
7
7
|
var useIsMountedRef = require('./useIsMountedRef');
|
8
|
+
var useQueryLoader_EXPERIMENTAL = require('./useQueryLoader_EXPERIMENTAL');
|
8
9
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
10
|
var _require2 = require('react'),
|
10
11
|
useCallback = _require2.useCallback,
|
@@ -12,6 +13,7 @@ var _require2 = require('react'),
|
|
12
13
|
useRef = _require2.useRef,
|
13
14
|
useState = _require2.useState;
|
14
15
|
var _require3 = require('relay-runtime'),
|
16
|
+
RelayFeatureFlags = _require3.RelayFeatureFlags,
|
15
17
|
getRequest = _require3.getRequest;
|
16
18
|
var initialNullQueryReferenceState = {
|
17
19
|
kind: 'NullQueryReference'
|
@@ -24,6 +26,12 @@ function requestIsLiveQuery(preloadableRequest) {
|
|
24
26
|
return request.params.metadata.live !== undefined;
|
25
27
|
}
|
26
28
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
29
|
+
if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
30
|
+
return useQueryLoader_EXPERIMENTAL(preloadableRequest, initialQueryReference);
|
31
|
+
}
|
32
|
+
return useQueryLoader_CURRENT(preloadableRequest, initialQueryReference);
|
33
|
+
}
|
34
|
+
function useQueryLoader_CURRENT(preloadableRequest, initialQueryReference) {
|
27
35
|
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
28
36
|
var environment = useRelayEnvironment();
|
29
37
|
var isMountedRef = useIsMountedRef();
|
@@ -0,0 +1,120 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
5
|
+
var _require = require('./loadQuery'),
|
6
|
+
loadQuery = _require.loadQuery;
|
7
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
8
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
|
+
var _require2 = require('react'),
|
10
|
+
useCallback = _require2.useCallback,
|
11
|
+
useEffect = _require2.useEffect,
|
12
|
+
useInsertionEffect = _require2.useInsertionEffect,
|
13
|
+
useRef = _require2.useRef,
|
14
|
+
useState = _require2.useState;
|
15
|
+
var _require3 = require('relay-runtime'),
|
16
|
+
getRequest = _require3.getRequest;
|
17
|
+
var initialNullQueryReferenceState = {
|
18
|
+
kind: 'NullQueryReference'
|
19
|
+
};
|
20
|
+
function requestIsLiveQuery(preloadableRequest) {
|
21
|
+
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
22
|
+
return preloadableRequest.params.metadata.live !== undefined;
|
23
|
+
}
|
24
|
+
var request = getRequest(preloadableRequest);
|
25
|
+
return request.params.metadata.live !== undefined;
|
26
|
+
}
|
27
|
+
var CLEANUP_TIMEOUT = 1000 * 60 * 5;
|
28
|
+
function useQueryLoader_EXPERIMENTAL(preloadableRequest, initialQueryReference) {
|
29
|
+
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
30
|
+
var environment = useRelayEnvironment();
|
31
|
+
var isMountedRef = useIsMountedRef();
|
32
|
+
var undisposedQueryReferencesRef = useRef(null);
|
33
|
+
if (undisposedQueryReferencesRef.current == null) {
|
34
|
+
undisposedQueryReferencesRef.current = new Set([initialQueryReferenceInternal]);
|
35
|
+
}
|
36
|
+
var _useState = useState(function () {
|
37
|
+
return initialQueryReferenceInternal;
|
38
|
+
}),
|
39
|
+
queryReference = _useState[0],
|
40
|
+
setQueryReference = _useState[1];
|
41
|
+
var _useState2 = useState(function () {
|
42
|
+
return initialQueryReferenceInternal;
|
43
|
+
}),
|
44
|
+
previousInitialQueryReference = _useState2[0],
|
45
|
+
setPreviousInitialQueryReference = _useState2[1];
|
46
|
+
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
47
|
+
var _undisposedQueryRefer;
|
48
|
+
(_undisposedQueryRefer = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer === void 0 ? void 0 : _undisposedQueryRefer.add(initialQueryReferenceInternal);
|
49
|
+
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
50
|
+
setQueryReference(initialQueryReferenceInternal);
|
51
|
+
}
|
52
|
+
var disposeQuery = useCallback(function () {
|
53
|
+
if (isMountedRef.current) {
|
54
|
+
var _undisposedQueryRefer2;
|
55
|
+
(_undisposedQueryRefer2 = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer2 === void 0 ? void 0 : _undisposedQueryRefer2.add(initialNullQueryReferenceState);
|
56
|
+
setQueryReference(initialNullQueryReferenceState);
|
57
|
+
}
|
58
|
+
}, [isMountedRef]);
|
59
|
+
var queryLoaderCallback = useCallback(function (variables, options) {
|
60
|
+
var _options$__environmen, _undisposedQueryRefer3;
|
61
|
+
if (!isMountedRef.current) {
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
var mergedOptions = options != null && options.hasOwnProperty('__environment') ? {
|
65
|
+
fetchPolicy: options.fetchPolicy,
|
66
|
+
networkCacheConfig: options.networkCacheConfig,
|
67
|
+
__nameForWarning: options.__nameForWarning
|
68
|
+
} : options;
|
69
|
+
var updatedQueryReference = loadQuery((_options$__environmen = options === null || options === void 0 ? void 0 : options.__environment) !== null && _options$__environmen !== void 0 ? _options$__environmen : environment, preloadableRequest, variables, mergedOptions);
|
70
|
+
(_undisposedQueryRefer3 = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer3 === void 0 ? void 0 : _undisposedQueryRefer3.add(updatedQueryReference);
|
71
|
+
setQueryReference(updatedQueryReference);
|
72
|
+
}, [environment, preloadableRequest, setQueryReference, isMountedRef]);
|
73
|
+
var disposeAllRemainingQueryReferences = useCallback(function disposeAllRemainingQueryReferences(preloadableRequest, currentQueryReference) {
|
74
|
+
var _undisposedQueryRefer4;
|
75
|
+
var undisposedQueryReferences = (_undisposedQueryRefer4 = undisposedQueryReferencesRef.current) !== null && _undisposedQueryRefer4 !== void 0 ? _undisposedQueryRefer4 : new Set();
|
76
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
|
77
|
+
_step;
|
78
|
+
try {
|
79
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
80
|
+
var undisposedQueryReference = _step.value;
|
81
|
+
if (undisposedQueryReference === currentQueryReference) {
|
82
|
+
continue;
|
83
|
+
}
|
84
|
+
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
85
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
86
|
+
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
87
|
+
} else {
|
88
|
+
undisposedQueryReference.releaseQuery && undisposedQueryReference.releaseQuery();
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
} catch (err) {
|
93
|
+
_iterator.e(err);
|
94
|
+
} finally {
|
95
|
+
_iterator.f();
|
96
|
+
}
|
97
|
+
}, []);
|
98
|
+
var cleanupTimerRef = useRef(null);
|
99
|
+
useEffect(function () {
|
100
|
+
disposeAllRemainingQueryReferences(preloadableRequest, queryReference);
|
101
|
+
if (cleanupTimerRef.current != null) {
|
102
|
+
clearTimeout(cleanupTimerRef.current);
|
103
|
+
cleanupTimerRef.current = null;
|
104
|
+
}
|
105
|
+
return function () {
|
106
|
+
cleanupTimerRef.current = setTimeout(function () {
|
107
|
+
disposeAllRemainingQueryReferences(preloadableRequest, null);
|
108
|
+
}, CLEANUP_TIMEOUT);
|
109
|
+
};
|
110
|
+
}, [preloadableRequest, queryReference]);
|
111
|
+
useInsertionEffect(function () {
|
112
|
+
return function () {
|
113
|
+
cleanupTimerRef.current && clearTimeout(cleanupTimerRef.current);
|
114
|
+
cleanupTimerRef.current = null;
|
115
|
+
disposeAllRemainingQueryReferences(preloadableRequest, null);
|
116
|
+
};
|
117
|
+
}, [preloadableRequest]);
|
118
|
+
return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
|
119
|
+
}
|
120
|
+
module.exports = useQueryLoader_EXPERIMENTAL;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-relay",
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
4
|
-
"version": "18.
|
4
|
+
"version": "18.2.0",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"fbjs": "^3.0.2",
|
21
21
|
"invariant": "^2.2.4",
|
22
22
|
"nullthrows": "^1.1.1",
|
23
|
-
"relay-runtime": "18.
|
23
|
+
"relay-runtime": "18.2.0"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"react": "^16.9.0 || ^17 || ^18"
|