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,98 +1,50 @@
|
|
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 _require = require('./loadQuery'),
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
loadQuery = _require.loadQuery,
|
7
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
21
8
|
var useIsMountedRef = require('./useIsMountedRef');
|
22
|
-
|
23
9
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
24
|
-
|
25
10
|
var _require2 = require('react'),
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
11
|
+
useCallback = _require2.useCallback,
|
12
|
+
useEffect = _require2.useEffect,
|
13
|
+
useRef = _require2.useRef,
|
14
|
+
useState = _require2.useState;
|
31
15
|
var _require3 = require('relay-runtime'),
|
32
|
-
|
33
|
-
|
16
|
+
getRequest = _require3.getRequest;
|
34
17
|
var initialNullQueryReferenceState = {
|
35
18
|
kind: 'NullQueryReference'
|
36
19
|
};
|
37
|
-
|
38
20
|
function requestIsLiveQuery(preloadableRequest) {
|
39
21
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
40
22
|
return preloadableRequest.params.metadata.live !== undefined;
|
41
23
|
}
|
42
|
-
|
43
24
|
var request = getRequest(preloadableRequest);
|
44
25
|
return request.params.metadata.live !== undefined;
|
45
26
|
}
|
46
|
-
|
47
27
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
48
|
-
/**
|
49
|
-
* We want to always call `queryReference.dispose()` for every call to
|
50
|
-
* `setQueryReference(loadQuery(...))` so that no leaks of data in Relay stores
|
51
|
-
* will occur.
|
52
|
-
*
|
53
|
-
* However, a call to `setState(newState)` is not always followed by a commit where
|
54
|
-
* this value is reflected in the state. Thus, we cannot reliably clean up each
|
55
|
-
* ref with `useEffect(() => () => queryReference.dispose(), [queryReference])`.
|
56
|
-
*
|
57
|
-
* Instead, we keep track of each call to `loadQuery` in a ref.
|
58
|
-
* Relying on the fact that if a state change commits, no state changes that were
|
59
|
-
* initiated prior to the currently committing state change will ever subsequently
|
60
|
-
* commit, we can safely dispose of all preloaded query references
|
61
|
-
* associated with state changes initiated prior to the currently committing state
|
62
|
-
* change.
|
63
|
-
*
|
64
|
-
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
65
|
-
* query references.
|
66
|
-
*/
|
67
28
|
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
68
29
|
var environment = useRelayEnvironment();
|
69
30
|
useTrackLoadQueryInRender();
|
70
31
|
var isMountedRef = useIsMountedRef();
|
71
32
|
var undisposedQueryReferencesRef = useRef(new Set([initialQueryReferenceInternal]));
|
72
|
-
|
73
33
|
var _useState = useState(function () {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
34
|
+
return initialQueryReferenceInternal;
|
35
|
+
}),
|
36
|
+
queryReference = _useState[0],
|
37
|
+
setQueryReference = _useState[1];
|
79
38
|
var _useState2 = useState(function () {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
39
|
+
return initialQueryReferenceInternal;
|
40
|
+
}),
|
41
|
+
previousInitialQueryReference = _useState2[0],
|
42
|
+
setPreviousInitialQueryReference = _useState2[1];
|
85
43
|
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
86
|
-
// Rendering the query reference makes it "managed" by this hook, so
|
87
|
-
// we start keeping track of it so we can dispose it when it is no longer
|
88
|
-
// necessary here
|
89
|
-
// TODO(T78446637): Handle disposal of managed query references in
|
90
|
-
// components that were never mounted after rendering
|
91
44
|
undisposedQueryReferencesRef.current.add(initialQueryReferenceInternal);
|
92
45
|
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
93
46
|
setQueryReference(initialQueryReferenceInternal);
|
94
47
|
}
|
95
|
-
|
96
48
|
var disposeQuery = useCallback(function () {
|
97
49
|
if (isMountedRef.current) {
|
98
50
|
undisposedQueryReferencesRef.current.add(initialNullQueryReferenceState);
|
@@ -105,10 +57,8 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
105
57
|
networkCacheConfig: options.networkCacheConfig,
|
106
58
|
__nameForWarning: options.__nameForWarning
|
107
59
|
} : options;
|
108
|
-
|
109
60
|
if (isMountedRef.current) {
|
110
61
|
var _options$__environmen;
|
111
|
-
|
112
62
|
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);
|
113
63
|
undisposedQueryReferencesRef.current.add(updatedQueryReference);
|
114
64
|
setQueryReference(updatedQueryReference);
|
@@ -117,74 +67,31 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
117
67
|
var maybeHiddenOrFastRefresh = useRef(false);
|
118
68
|
useEffect(function () {
|
119
69
|
return function () {
|
120
|
-
// Attempt to detect if the component was
|
121
|
-
// hidden (by Offscreen API), or fast refresh occured;
|
122
|
-
// Only in these situations would the effect cleanup
|
123
|
-
// for "unmounting" run multiple times, so if
|
124
|
-
// we are ever able to read this ref with a value
|
125
|
-
// of true, it means that one of these cases
|
126
|
-
// has happened.
|
127
70
|
maybeHiddenOrFastRefresh.current = true;
|
128
71
|
};
|
129
72
|
}, []);
|
130
73
|
useEffect(function () {
|
131
74
|
if (maybeHiddenOrFastRefresh.current === true) {
|
132
|
-
// This block only runs if the component has previously "unmounted"
|
133
|
-
// due to it being hidden by the Offscreen API, or during fast refresh.
|
134
|
-
// At this point, the current queryReference will have been disposed
|
135
|
-
// by the previous cleanup, so instead of attempting to
|
136
|
-
// do our regular commit setup, which would incorrectly leave our
|
137
|
-
// current queryReference disposed, we need to load the query again
|
138
|
-
// and force a re-render by calling queryLoaderCallback again,
|
139
|
-
// so that the queryReference is correctly re-retained, and
|
140
|
-
// potentially refetched if necessary.
|
141
75
|
maybeHiddenOrFastRefresh.current = false;
|
142
|
-
|
143
76
|
if (queryReference.kind !== 'NullQueryReference') {
|
144
77
|
queryLoaderCallback(queryReference.variables, {
|
145
78
|
fetchPolicy: queryReference.fetchPolicy,
|
146
79
|
networkCacheConfig: queryReference.networkCacheConfig
|
147
80
|
});
|
148
81
|
}
|
149
|
-
|
150
82
|
return;
|
151
|
-
}
|
152
|
-
// query references in undisposedQueryReferences and dispose all of
|
153
|
-
// the refs that aren't the currently committed one. This ensures
|
154
|
-
// that we don't leave any dangling query references for the
|
155
|
-
// case that loadQuery is called multiple times before commit; when
|
156
|
-
// this happens, multiple state updates will be scheduled, but only one
|
157
|
-
// will commit, meaning that we need to keep track of and dispose any
|
158
|
-
// query references that don't end up committing.
|
159
|
-
// - We are relying on the fact that sets iterate in insertion order, and we
|
160
|
-
// can remove items from a set as we iterate over it (i.e. no iterator
|
161
|
-
// invalidation issues.) Thus, it is safe to loop through
|
162
|
-
// undisposedQueryReferences until we find queryReference, and
|
163
|
-
// remove and dispose all previous references.
|
164
|
-
// - We are guaranteed to find queryReference in the set, because if a
|
165
|
-
// state update results in a commit, no state updates initiated prior to that
|
166
|
-
// one will be committed, and we are disposing and removing references
|
167
|
-
// associated with updates that were scheduled prior to the currently
|
168
|
-
// committing state change. (A useEffect callback is called during the commit
|
169
|
-
// phase.)
|
170
|
-
|
171
|
-
|
83
|
+
}
|
172
84
|
var undisposedQueryReferences = undisposedQueryReferencesRef.current;
|
173
|
-
|
174
85
|
if (isMountedRef.current) {
|
175
86
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
|
176
|
-
|
177
|
-
|
87
|
+
_step;
|
178
88
|
try {
|
179
89
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
180
90
|
var undisposedQueryReference = _step.value;
|
181
|
-
|
182
91
|
if (undisposedQueryReference === queryReference) {
|
183
92
|
break;
|
184
93
|
}
|
185
|
-
|
186
94
|
undisposedQueryReferences["delete"](undisposedQueryReference);
|
187
|
-
|
188
95
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
189
96
|
if (requestIsLiveQuery(preloadableRequest)) {
|
190
97
|
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
@@ -202,15 +109,11 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
202
109
|
}, [queryReference, isMountedRef, queryLoaderCallback, preloadableRequest]);
|
203
110
|
useEffect(function () {
|
204
111
|
return function disposeAllRemainingQueryReferences() {
|
205
|
-
// undisposedQueryReferences.current is never reassigned
|
206
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
207
112
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferencesRef.current),
|
208
|
-
|
209
|
-
|
113
|
+
_step2;
|
210
114
|
try {
|
211
115
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
212
116
|
var undisposedQueryReference = _step2.value;
|
213
|
-
|
214
117
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
215
118
|
if (requestIsLiveQuery(preloadableRequest)) {
|
216
119
|
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
@@ -228,5 +131,4 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
228
131
|
}, [preloadableRequest]);
|
229
132
|
return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
|
230
133
|
}
|
231
|
-
|
232
134
|
module.exports = useQueryLoader;
|
@@ -1,58 +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 HooksImplementation = require('./HooksImplementation');
|
14
|
-
|
15
4
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
16
|
-
|
17
5
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
18
|
-
|
19
6
|
var _require = require('react'),
|
20
|
-
|
21
|
-
|
7
|
+
useDebugValue = _require.useDebugValue;
|
22
8
|
var _require2 = require('relay-runtime'),
|
23
|
-
|
24
|
-
|
9
|
+
getFragment = _require2.getFragment;
|
25
10
|
function useRefetchableFragment_LEGACY(fragmentInput, fragmentRef) {
|
26
11
|
var fragmentNode = getFragment(fragmentInput);
|
27
12
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
28
|
-
|
29
13
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
15
|
+
refetch = _useRefetchableFragme.refetch;
|
33
16
|
if (process.env.NODE_ENV !== "production") {
|
34
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
35
17
|
useDebugValue({
|
36
18
|
fragment: fragmentNode.name,
|
37
19
|
data: fragmentData
|
38
20
|
});
|
39
21
|
}
|
40
|
-
/* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
|
41
|
-
* options */
|
42
|
-
|
43
|
-
|
44
22
|
return [fragmentData, refetch];
|
45
23
|
}
|
46
|
-
|
47
24
|
function useRefetchableFragment(fragmentInput, parentFragmentRef) {
|
48
25
|
var impl = HooksImplementation.get();
|
49
|
-
|
50
26
|
if (impl) {
|
51
27
|
return impl.useRefetchableFragment(fragmentInput, parentFragmentRef);
|
52
28
|
} else {
|
53
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
54
29
|
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
55
30
|
}
|
56
31
|
}
|
57
|
-
|
58
32
|
module.exports = useRefetchableFragment;
|