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,102 +1,71 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
16
|
-
|
17
5
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
18
|
-
|
19
6
|
var _excluded = ["disableStoreUpdates", "enableStoreUpdates"];
|
20
|
-
|
21
7
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
22
|
-
|
23
8
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
24
|
-
|
25
9
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
26
|
-
|
27
10
|
var invariant = require('invariant');
|
28
|
-
|
29
11
|
var _require = require('react'),
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
12
|
+
useCallback = _require.useCallback,
|
13
|
+
useEffect = _require.useEffect,
|
14
|
+
useRef = _require.useRef,
|
15
|
+
useState = _require.useState;
|
35
16
|
var _require2 = require('relay-runtime'),
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
17
|
+
getFragment = _require2.getFragment,
|
18
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
19
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
40
20
|
function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
41
21
|
var componentDisplayName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'useBlockingPaginationFragment()';
|
42
22
|
var fragmentNode = getFragment(fragmentInput);
|
43
23
|
useStaticFragmentNodeWarning(fragmentNode, "first argument of ".concat(componentDisplayName));
|
44
|
-
|
45
24
|
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
stream = _getPaginationMetadat.stream;
|
51
|
-
|
25
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
26
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
27
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata,
|
28
|
+
stream = _getPaginationMetadat.stream;
|
52
29
|
!(stream === false) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: @stream_connection is not compatible with `useBlockingPaginationFragment`. ' + 'Use `useStreamingPaginationFragment` instead.') : invariant(false) : void 0;
|
53
|
-
|
54
30
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Backward pagination
|
62
|
-
|
31
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
32
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
33
|
+
refetch = _useRefetchableFragme.refetch,
|
34
|
+
disableStoreUpdates = _useRefetchableFragme.disableStoreUpdates,
|
35
|
+
enableStoreUpdates = _useRefetchableFragme.enableStoreUpdates;
|
36
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
63
37
|
var _useLoadMore = useLoadMore({
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
disposeFetchPrevious = _useLoadMore[2]; // Forward pagination
|
80
|
-
|
81
|
-
|
38
|
+
componentDisplayName: componentDisplayName,
|
39
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
40
|
+
direction: 'backward',
|
41
|
+
disableStoreUpdates: disableStoreUpdates,
|
42
|
+
enableStoreUpdates: enableStoreUpdates,
|
43
|
+
fragmentData: fragmentData,
|
44
|
+
fragmentIdentifier: fragmentIdentifier,
|
45
|
+
fragmentNode: fragmentNode,
|
46
|
+
fragmentRef: fragmentRef,
|
47
|
+
paginationMetadata: paginationMetadata,
|
48
|
+
paginationRequest: paginationRequest
|
49
|
+
}),
|
50
|
+
loadPrevious = _useLoadMore[0],
|
51
|
+
hasPrevious = _useLoadMore[1],
|
52
|
+
disposeFetchPrevious = _useLoadMore[2];
|
82
53
|
var _useLoadMore2 = useLoadMore({
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
disposeFetchNext = _useLoadMore2[2];
|
99
|
-
|
54
|
+
componentDisplayName: componentDisplayName,
|
55
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
56
|
+
direction: 'forward',
|
57
|
+
disableStoreUpdates: disableStoreUpdates,
|
58
|
+
enableStoreUpdates: enableStoreUpdates,
|
59
|
+
fragmentData: fragmentData,
|
60
|
+
fragmentIdentifier: fragmentIdentifier,
|
61
|
+
fragmentNode: fragmentNode,
|
62
|
+
fragmentRef: fragmentRef,
|
63
|
+
paginationMetadata: paginationMetadata,
|
64
|
+
paginationRequest: paginationRequest
|
65
|
+
}),
|
66
|
+
loadNext = _useLoadMore2[0],
|
67
|
+
hasNext = _useLoadMore2[1],
|
68
|
+
disposeFetchNext = _useLoadMore2[2];
|
100
69
|
var refetchPagination = useCallback(function (variables, options) {
|
101
70
|
disposeFetchNext();
|
102
71
|
disposeFetchPrevious();
|
@@ -113,39 +82,27 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
|
113
82
|
refetch: refetchPagination
|
114
83
|
};
|
115
84
|
}
|
116
|
-
|
117
85
|
function useLoadMore(args) {
|
118
86
|
var disableStoreUpdates = args.disableStoreUpdates,
|
119
|
-
|
120
|
-
|
121
|
-
|
87
|
+
enableStoreUpdates = args.enableStoreUpdates,
|
88
|
+
loadMoreArgs = (0, _objectWithoutPropertiesLoose2["default"])(args, _excluded);
|
122
89
|
var _useState = useState(null),
|
123
|
-
|
124
|
-
|
125
|
-
|
90
|
+
requestPromise = _useState[0],
|
91
|
+
setRequestPromise = _useState[1];
|
126
92
|
var requestPromiseRef = useRef(null);
|
127
93
|
var promiseResolveRef = useRef(null);
|
128
|
-
|
129
94
|
var promiseResolve = function promiseResolve() {
|
130
95
|
if (promiseResolveRef.current != null) {
|
131
96
|
promiseResolveRef.current();
|
132
97
|
promiseResolveRef.current = null;
|
133
98
|
}
|
134
99
|
};
|
135
|
-
|
136
100
|
var handleReset = function handleReset() {
|
137
101
|
promiseResolve();
|
138
102
|
};
|
139
|
-
|
140
103
|
var observer = {
|
141
104
|
complete: promiseResolve,
|
142
|
-
// NOTE: loadMore is a no-op if a request is already in flight, so we
|
143
|
-
// can safely assume that `start` will only be called once while a
|
144
|
-
// request is in flight.
|
145
105
|
start: function start() {
|
146
|
-
// NOTE: We disable store updates when we suspend to ensure
|
147
|
-
// that higher-pri updates from the Relay store don't disrupt
|
148
|
-
// any Suspense timeouts passed via withSuspenseConfig.
|
149
106
|
disableStoreUpdates();
|
150
107
|
var promise = new Promise(function (resolve) {
|
151
108
|
promiseResolveRef.current = function () {
|
@@ -156,44 +113,24 @@ function useLoadMore(args) {
|
|
156
113
|
requestPromiseRef.current = promise;
|
157
114
|
setRequestPromise(promise);
|
158
115
|
},
|
159
|
-
// NOTE: Since streaming is disallowed with this hook, this means that the
|
160
|
-
// first payload will always contain the entire next page of items,
|
161
|
-
// while subsequent paylaods will contain @defer'd payloads.
|
162
|
-
// This allows us to unsuspend here, on the first payload, and allow
|
163
|
-
// descendant components to suspend on their respective @defer payloads
|
164
116
|
next: promiseResolve,
|
165
|
-
// TODO: Handle error; we probably don't want to throw an error
|
166
|
-
// and blow away the whole list of items.
|
167
117
|
error: promiseResolve
|
168
118
|
};
|
169
|
-
|
170
119
|
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, loadMoreArgs), {}, {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
// state is the same as the promise on the ref, which ensures that we
|
178
|
-
// wont incorrectly suspend on other higher-pri updates before the update
|
179
|
-
// to suspend has committed.
|
180
|
-
|
181
|
-
|
120
|
+
observer: observer,
|
121
|
+
onReset: handleReset
|
122
|
+
})),
|
123
|
+
loadMore = _useLoadMoreFunction[0],
|
124
|
+
hasMore = _useLoadMoreFunction[1],
|
125
|
+
disposeFetch = _useLoadMoreFunction[2];
|
182
126
|
if (requestPromise != null && requestPromise === requestPromiseRef.current) {
|
183
127
|
throw requestPromise;
|
184
128
|
}
|
185
|
-
|
186
129
|
useEffect(function () {
|
187
130
|
if (requestPromise !== requestPromiseRef.current) {
|
188
|
-
// NOTE: After suspense pagination has resolved, we re-enable store updates
|
189
|
-
// for this fragment. This may cause the component to re-render if
|
190
|
-
// we missed any updates to the fragment data other than the pagination update.
|
191
131
|
enableStoreUpdates();
|
192
|
-
}
|
193
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
194
|
-
|
132
|
+
}
|
195
133
|
}, [requestPromise]);
|
196
134
|
return [loadMore, hasMore, disposeFetch];
|
197
135
|
}
|
198
|
-
|
199
136
|
module.exports = useBlockingPaginationFragment;
|
@@ -1,33 +1,12 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
5
|
var useLazyLoadQuery = require('./useLazyLoadQuery');
|
18
|
-
/**
|
19
|
-
* This hook can be used to render client-only queries.
|
20
|
-
* These queries are consist of queries for client-only data,
|
21
|
-
* schematized via local schema extensions and/or Relay resolvers.
|
22
|
-
*/
|
23
|
-
|
24
|
-
|
25
6
|
function useClientQuery(gqlQuery, variables, options) {
|
26
|
-
// $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
|
27
7
|
var query = gqlQuery;
|
28
8
|
return useLazyLoadQuery(query, variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
29
9
|
fetchPolicy: 'store-only'
|
30
10
|
}));
|
31
11
|
}
|
32
|
-
|
33
12
|
module.exports = useClientQuery;
|
@@ -1,72 +1,32 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
16
|
-
|
17
5
|
var loadEntryPoint = require('./loadEntryPoint');
|
18
|
-
|
19
6
|
var _require = require('./loadQuery'),
|
20
|
-
|
21
|
-
|
7
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
22
8
|
var useIsMountedRef = require('./useIsMountedRef');
|
23
|
-
|
24
9
|
var _require2 = require('react'),
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
10
|
+
useCallback = _require2.useCallback,
|
11
|
+
useEffect = _require2.useEffect,
|
12
|
+
useRef = _require2.useRef,
|
13
|
+
useState = _require2.useState;
|
30
14
|
var initialNullEntryPointReferenceState = {
|
31
15
|
kind: 'NullEntryPointReference'
|
32
16
|
};
|
33
|
-
|
34
17
|
function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
35
18
|
var _options$TEST_ONLY__i, _options$TEST_ONLY__i2, _options$TEST_ONLY__i3, _options$TEST_ONLY__i4;
|
36
|
-
|
37
|
-
/**
|
38
|
-
* We want to always call `entryPointReference.dispose()` for every call to
|
39
|
-
* `setEntryPointReference(loadEntryPoint(...))` so that no leaks of data in Relay
|
40
|
-
* stores will occur.
|
41
|
-
*
|
42
|
-
* However, a call to `setState(newState)` is not always followed by a commit where
|
43
|
-
* this value is reflected in the state. Thus, we cannot reliably clean up each ref
|
44
|
-
* with `useEffect(() => () => entryPointReference.dispose(), [entryPointReference])`.
|
45
|
-
*
|
46
|
-
* Instead, we keep track of each call to `loadEntryPoint` in a ref.
|
47
|
-
* Relying on the fact that if a state change commits, no state changes that were
|
48
|
-
* initiated prior to the currently committing state change will ever subsequently
|
49
|
-
* commit, we can safely dispose of all preloaded entry point references
|
50
|
-
* associated with state changes initiated prior to the currently committing state
|
51
|
-
* change.
|
52
|
-
*
|
53
|
-
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
54
|
-
* entry point references.
|
55
|
-
*/
|
56
19
|
useTrackLoadQueryInRender();
|
57
20
|
var initialEntryPointReferenceInternal = (_options$TEST_ONLY__i = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i2 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i2 === void 0 ? void 0 : _options$TEST_ONLY__i2.entryPointReference) !== null && _options$TEST_ONLY__i !== void 0 ? _options$TEST_ONLY__i : initialNullEntryPointReferenceState;
|
58
21
|
var initialEntryPointParamsInternal = (_options$TEST_ONLY__i3 = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i4 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i4 === void 0 ? void 0 : _options$TEST_ONLY__i4.entryPointParams) !== null && _options$TEST_ONLY__i3 !== void 0 ? _options$TEST_ONLY__i3 : null;
|
59
22
|
var isMountedRef = useIsMountedRef();
|
60
23
|
var undisposedEntryPointReferencesRef = useRef(new Set([initialEntryPointReferenceInternal]));
|
61
|
-
|
62
24
|
var _useState = useState(initialEntryPointReferenceInternal),
|
63
|
-
|
64
|
-
|
65
|
-
|
25
|
+
entryPointReference = _useState[0],
|
26
|
+
setEntryPointReference = _useState[1];
|
66
27
|
var _useState2 = useState(initialEntryPointParamsInternal),
|
67
|
-
|
68
|
-
|
69
|
-
|
28
|
+
entryPointParams = _useState2[0],
|
29
|
+
setEntryPointParams = _useState2[1];
|
70
30
|
var disposeEntryPoint = useCallback(function () {
|
71
31
|
if (isMountedRef.current) {
|
72
32
|
var nullEntryPointReference = {
|
@@ -87,71 +47,28 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
87
47
|
var maybeHiddenOrFastRefresh = useRef(false);
|
88
48
|
useEffect(function () {
|
89
49
|
return function () {
|
90
|
-
// Attempt to detect if the component was
|
91
|
-
// hidden (by Offscreen API), or fast refresh occured;
|
92
|
-
// Only in these situations would the effect cleanup
|
93
|
-
// for "unmounting" run multiple times, so if
|
94
|
-
// we are ever able to read this ref with a value
|
95
|
-
// of true, it means that one of these cases
|
96
|
-
// has happened.
|
97
50
|
maybeHiddenOrFastRefresh.current = true;
|
98
51
|
};
|
99
52
|
}, []);
|
100
53
|
useEffect(function () {
|
101
54
|
if (maybeHiddenOrFastRefresh.current === true) {
|
102
|
-
// This block only runs if the component has previously "unmounted"
|
103
|
-
// due to it being hidden by the Offscreen API, or during fast refresh.
|
104
|
-
// At this point, the current entryPointReference will have been disposed
|
105
|
-
// by the previous cleanup, so instead of attempting to
|
106
|
-
// do our regular commit setup, which would incorrectly leave our
|
107
|
-
// current entryPointReference disposed, we need to load the entryPoint again
|
108
|
-
// and force a re-render by calling entryPointLoaderCallback again,
|
109
|
-
// so that the entryPointReference's queries are correctly re-retained, and
|
110
|
-
// potentially refetched if necessary.
|
111
55
|
maybeHiddenOrFastRefresh.current = false;
|
112
|
-
|
113
56
|
if (entryPointReference.kind !== 'NullEntryPointReference' && entryPointParams != null) {
|
114
57
|
entryPointLoaderCallback(entryPointParams);
|
115
58
|
}
|
116
|
-
|
117
59
|
return;
|
118
|
-
}
|
119
|
-
// entrypoint refs in undisposedEntryPointReferences and dispose all of
|
120
|
-
// the refs that aren't the currently committed one. This ensures
|
121
|
-
// that we don't leave any dangling entrypoint references for the
|
122
|
-
// case that loadEntryPoint is called multiple times before commit; when
|
123
|
-
// this happens, multiple state updates will be scheduled, but only one
|
124
|
-
// will commit, meaning that we need to keep track of and dispose any
|
125
|
-
// query references that don't end up committing.
|
126
|
-
// - We are relying on the fact that sets iterate in insertion order, and we
|
127
|
-
// can remove items from a set as we iterate over it (i.e. no iterator
|
128
|
-
// invalidation issues.) Thus, it is safe to loop through
|
129
|
-
// undisposedEntryPointReferences until we find entryPointReference, and
|
130
|
-
// remove and dispose all previous references.
|
131
|
-
// - We are guaranteed to find entryPointReference in the set, because if a
|
132
|
-
// state change results in a commit, no state changes initiated prior to that
|
133
|
-
// one will be committed, and we are disposing and removing references
|
134
|
-
// associated with commits that were initiated prior to the currently
|
135
|
-
// committing state change. (A useEffect callback is called during the commit
|
136
|
-
// phase.)
|
137
|
-
|
138
|
-
|
60
|
+
}
|
139
61
|
var undisposedEntryPointReferences = undisposedEntryPointReferencesRef.current;
|
140
|
-
|
141
62
|
if (isMountedRef.current) {
|
142
63
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferences),
|
143
|
-
|
144
|
-
|
64
|
+
_step;
|
145
65
|
try {
|
146
66
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
147
67
|
var undisposedEntryPointReference = _step.value;
|
148
|
-
|
149
68
|
if (undisposedEntryPointReference === entryPointReference) {
|
150
69
|
break;
|
151
70
|
}
|
152
|
-
|
153
71
|
undisposedEntryPointReferences["delete"](undisposedEntryPointReference);
|
154
|
-
|
155
72
|
if (undisposedEntryPointReference.kind !== 'NullEntryPointReference') {
|
156
73
|
undisposedEntryPointReference.dispose();
|
157
74
|
}
|
@@ -165,15 +82,11 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
165
82
|
}, [entryPointReference, entryPointParams, entryPointLoaderCallback, isMountedRef]);
|
166
83
|
useEffect(function () {
|
167
84
|
return function disposeAllRemainingEntryPointReferences() {
|
168
|
-
// undisposedEntryPointReferences.current is never reassigned
|
169
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
170
85
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferencesRef.current),
|
171
|
-
|
172
|
-
|
86
|
+
_step2;
|
173
87
|
try {
|
174
88
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
175
89
|
var unhandledStateChange = _step2.value;
|
176
|
-
|
177
90
|
if (unhandledStateChange.kind !== 'NullEntryPointReference') {
|
178
91
|
unhandledStateChange.dispose();
|
179
92
|
}
|
@@ -187,5 +100,4 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
187
100
|
}, []);
|
188
101
|
return [entryPointReference.kind === 'NullEntryPointReference' ? null : entryPointReference, entryPointLoaderCallback, disposeEntryPoint];
|
189
102
|
}
|
190
|
-
|
191
103
|
module.exports = useLoadEntryPoint;
|
@@ -1,42 +1,17 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
3
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
13
4
|
var _require = require('react'),
|
14
|
-
|
15
|
-
|
16
|
-
useRef = _require.useRef;
|
17
|
-
/**
|
18
|
-
* This hook returns a mutable React ref that holds the value of whether a
|
19
|
-
* fetch request is in flight. The reason this is a mutable ref instead of
|
20
|
-
* state is because we don't actually want to trigger an update when this
|
21
|
-
* changes, but instead synchronously keep track of whether the network request
|
22
|
-
* is in flight, for example in order to bail out of a request if one is
|
23
|
-
* already in flight. If this was state, due to the nature of concurrent
|
24
|
-
* updates, this value wouldn't be in sync with when the request is actually
|
25
|
-
* in flight.
|
26
|
-
* The additional functions returned by this Hook can be used to mutate
|
27
|
-
* the ref.
|
28
|
-
*/
|
29
|
-
|
30
|
-
|
5
|
+
useCallback = _require.useCallback,
|
6
|
+
useEffect = _require.useEffect;
|
31
7
|
function useFetchTrackingRef() {
|
32
|
-
var subscriptionRef =
|
33
|
-
var isFetchingRef =
|
8
|
+
var subscriptionRef = useUnsafeRef_DEPRECATED(null);
|
9
|
+
var isFetchingRef = useUnsafeRef_DEPRECATED(false);
|
34
10
|
var disposeFetch = useCallback(function () {
|
35
11
|
if (subscriptionRef.current != null) {
|
36
12
|
subscriptionRef.current.unsubscribe();
|
37
13
|
subscriptionRef.current = null;
|
38
14
|
}
|
39
|
-
|
40
15
|
isFetchingRef.current = false;
|
41
16
|
}, []);
|
42
17
|
var startFetch = useCallback(function (subscription) {
|
@@ -46,8 +21,7 @@ function useFetchTrackingRef() {
|
|
46
21
|
var completeFetch = useCallback(function () {
|
47
22
|
subscriptionRef.current = null;
|
48
23
|
isFetchingRef.current = false;
|
49
|
-
}, []);
|
50
|
-
|
24
|
+
}, []);
|
51
25
|
useEffect(function () {
|
52
26
|
return disposeFetch;
|
53
27
|
}, [disposeFetch]);
|
@@ -58,5 +32,4 @@ function useFetchTrackingRef() {
|
|
58
32
|
completeFetch: completeFetch
|
59
33
|
};
|
60
34
|
}
|
61
|
-
|
62
35
|
module.exports = useFetchTrackingRef;
|
@@ -1,61 +1,34 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
3
|
var HooksImplementation = require('./HooksImplementation');
|
14
|
-
|
15
4
|
var _require = require('./loadQuery'),
|
16
|
-
|
17
|
-
|
5
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
18
6
|
var useFragmentNode = require('./useFragmentNode');
|
19
|
-
|
20
7
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
21
|
-
|
22
8
|
var _require2 = require('react'),
|
23
|
-
|
24
|
-
|
9
|
+
useDebugValue = _require2.useDebugValue;
|
25
10
|
var _require3 = require('relay-runtime'),
|
26
|
-
|
27
|
-
|
11
|
+
getFragment = _require3.getFragment;
|
28
12
|
function useFragment_LEGACY(fragment, key) {
|
29
|
-
// We need to use this hook in order to be able to track if
|
30
|
-
// loadQuery was called during render
|
31
13
|
useTrackLoadQueryInRender();
|
32
14
|
var fragmentNode = getFragment(fragment);
|
33
15
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
34
|
-
|
35
16
|
var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
|
36
|
-
|
37
|
-
|
17
|
+
data = _useFragmentNode.data;
|
38
18
|
if (process.env.NODE_ENV !== "production") {
|
39
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
40
19
|
useDebugValue({
|
41
20
|
fragment: fragmentNode.name,
|
42
21
|
data: data
|
43
22
|
});
|
44
23
|
}
|
45
|
-
|
46
24
|
return data;
|
47
25
|
}
|
48
|
-
|
49
26
|
function useFragment(fragment, key) {
|
50
27
|
var impl = HooksImplementation.get();
|
51
|
-
|
52
28
|
if (impl) {
|
53
|
-
|
54
|
-
return impl.useFragment(fragment, key); // (i.e. type declared above, but not the supertype used in this function definition)
|
29
|
+
return impl.useFragment(fragment, key);
|
55
30
|
} else {
|
56
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
57
31
|
return useFragment_LEGACY(fragment, key);
|
58
32
|
}
|
59
33
|
}
|
60
|
-
|
61
34
|
module.exports = useFragment;
|