react-relay 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +47 -0
- package/ReactRelayContainerUtils.js.flow +1 -1
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +3 -4
- package/ReactRelayFragmentContainer.js.flow +25 -25
- package/ReactRelayFragmentMockRenderer.js.flow +2 -2
- package/ReactRelayLocalQueryRenderer.js.flow +7 -8
- package/ReactRelayPaginationContainer.js.flow +112 -59
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +116 -82
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +42 -39
- package/ReactRelayTestMocker.js.flow +17 -15
- package/ReactRelayTypes.js.flow +11 -11
- package/RelayContext.js.flow +4 -4
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
- package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
- package/assertFragmentMap.js.flow +3 -3
- package/buildReactRelayContainer.js.flow +12 -11
- package/getRootVariablesForFragments.js.flow +3 -5
- package/hooks.js +1 -1
- package/hooks.js.flow +6 -7
- package/index.js +1 -1
- package/index.js.flow +7 -8
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/enqueueTask.js.flow +56 -0
- package/jest-react/index.js.flow +12 -0
- package/jest-react/internalAct.js.flow +138 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -1
- package/lib/ReactRelayContainerUtils.js +1 -1
- package/lib/ReactRelayContext.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +22 -16
- package/lib/ReactRelayFragmentMockRenderer.js +3 -3
- package/lib/ReactRelayLocalQueryRenderer.js +8 -9
- package/lib/ReactRelayPaginationContainer.js +97 -39
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +87 -54
- package/lib/ReactRelayQueryRendererContext.js +1 -1
- package/lib/ReactRelayRefetchContainer.js +39 -26
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +4 -3
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +8 -8
- package/lib/getRootVariablesForFragments.js +2 -3
- package/lib/hooks.js +6 -6
- package/lib/index.js +8 -8
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/jest-react/enqueueTask.js +53 -0
- package/lib/jest-react/index.js +13 -0
- package/lib/jest-react/internalAct.js +115 -0
- package/lib/legacy.js +1 -1
- package/lib/multi-actor/ActorChange.js +30 -0
- package/lib/multi-actor/index.js +11 -0
- package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
- package/lib/readContext.js +1 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
- package/lib/relay-hooks/FragmentResource.js +342 -89
- package/lib/relay-hooks/InternalLogger.js +1 -1
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +1 -1
- package/lib/relay-hooks/QueryResource.js +172 -29
- package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadEntryPoint.js +1 -1
- package/lib/relay-hooks/loadQuery.js +42 -20
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
- package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
- package/lib/relay-hooks/useEntryPointLoader.js +3 -3
- package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
- package/lib/relay-hooks/useFragment.js +7 -7
- package/lib/relay-hooks/useFragmentNode.js +5 -5
- package/lib/relay-hooks/useIsMountedRef.js +1 -1
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
- package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
- package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
- package/lib/relay-hooks/useMemoVariables.js +3 -3
- package/lib/relay-hooks/useMutation.js +18 -7
- package/lib/relay-hooks/usePaginationFragment.js +3 -4
- package/lib/relay-hooks/usePreloadedQuery.js +6 -6
- package/lib/relay-hooks/useQueryLoader.js +31 -11
- package/lib/relay-hooks/useRefetchableFragment.js +1 -1
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
- package/lib/relay-hooks/useSubscription.js +11 -8
- package/multi-actor/ActorChange.js.flow +58 -0
- package/multi-actor/index.js.flow +14 -0
- package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
- package/package.json +3 -3
- 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/readContext.js.flow +1 -1
- package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
- package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
- package/relay-hooks/FragmentResource.js.flow +359 -93
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
- package/relay-hooks/MatchContainer.js.flow +4 -3
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +217 -26
- package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/utils.js.flow +21 -32
- package/relay-hooks/loadEntryPoint.js.flow +7 -13
- package/relay-hooks/loadQuery.js.flow +50 -32
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
- package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
- package/relay-hooks/useEntryPointLoader.js.flow +8 -11
- package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
- package/relay-hooks/useFragment.js.flow +31 -62
- package/relay-hooks/useFragmentNode.js.flow +6 -8
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
- package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
- package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
- package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
- package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
- package/relay-hooks/useMemoVariables.js.flow +7 -7
- package/relay-hooks/useMutation.js.flow +27 -27
- package/relay-hooks/usePaginationFragment.js.flow +39 -45
- package/relay-hooks/usePreloadedQuery.js.flow +14 -20
- package/relay-hooks/useQueryLoader.js.flow +42 -23
- package/relay-hooks/useRefetchableFragment.js.flow +8 -9
- package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
- package/relay-hooks/useRelayEnvironment.js.flow +3 -5
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
- package/relay-hooks/useSubscription.js.flow +21 -11
- package/lib/relay-hooks/getPaginationMetadata.js +0 -41
- package/lib/relay-hooks/getPaginationVariables.js +0 -67
- package/lib/relay-hooks/getRefetchMetadata.js +0 -36
- package/lib/relay-hooks/getValueAtPath.js +0 -51
- package/relay-hooks/getPaginationMetadata.js.flow +0 -74
- package/relay-hooks/getPaginationVariables.js.flow +0 -110
- package/relay-hooks/getRefetchMetadata.js.flow +0 -80
- package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -0,0 +1,56 @@
|
|
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
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// This file is sync'd from https://github.com/facebook/react/tree/main/packages/jest-react
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
let didWarnAboutMessageChannel = false;
|
16
|
+
let enqueueTaskImpl = null;
|
17
|
+
|
18
|
+
function enqueueTask(task: () => void) {
|
19
|
+
if (enqueueTaskImpl === null) {
|
20
|
+
try {
|
21
|
+
// read require off the module object to get around the bundlers.
|
22
|
+
// we don't want them to detect a require and bundle a Node polyfill.
|
23
|
+
const requireString = ('require' + Math.random()).slice(0, 7);
|
24
|
+
const nodeRequire = module && module[requireString];
|
25
|
+
// assuming we're in node, let's try to get node's
|
26
|
+
// version of setImmediate, bypassing fake timers if any.
|
27
|
+
enqueueTaskImpl = nodeRequire.call(module, 'timers').setImmediate;
|
28
|
+
} catch {
|
29
|
+
// we're in a browser
|
30
|
+
// we can't use regular timers because they may still be faked
|
31
|
+
// so we try MessageChannel+postMessage instead
|
32
|
+
enqueueTaskImpl = function (callback: () => void) {
|
33
|
+
if (__DEV__) {
|
34
|
+
if (didWarnAboutMessageChannel === false) {
|
35
|
+
didWarnAboutMessageChannel = true;
|
36
|
+
if (typeof MessageChannel === 'undefined') {
|
37
|
+
console.error(
|
38
|
+
'This browser does not have a MessageChannel implementation, ' +
|
39
|
+
'so enqueuing tasks via await act(async () => ...) will fail. ' +
|
40
|
+
'Please file an issue at https://github.com/facebook/react/issues ' +
|
41
|
+
'if you encounter this warning.',
|
42
|
+
);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
/*global MessageChannel*/
|
47
|
+
const channel = new MessageChannel();
|
48
|
+
channel.port1.onmessage = callback;
|
49
|
+
channel.port2.postMessage(undefined);
|
50
|
+
};
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return enqueueTaskImpl(task);
|
54
|
+
}
|
55
|
+
|
56
|
+
module.exports = enqueueTask;
|
@@ -0,0 +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
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// This file is sync'd from https://github.com/facebook/react/tree/main/packages/jest-react
|
12
|
+
export {act} from './internalAct';
|
@@ -0,0 +1,138 @@
|
|
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
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* global jest */
|
12
|
+
|
13
|
+
// This file is sync'd from https://github.com/facebook/react/tree/main/packages/jest-react
|
14
|
+
|
15
|
+
// This version of `act` is only used by our tests. Unlike the public version
|
16
|
+
// of `act`, it's designed to work identically in both production and
|
17
|
+
// development. It may have slightly different behavior from the public
|
18
|
+
// version, too, since our constraints in our test suite are not the same as
|
19
|
+
// those of developers using React — we're testing React itself, as opposed to
|
20
|
+
// building an app with React.
|
21
|
+
|
22
|
+
'use strict';
|
23
|
+
|
24
|
+
const enqueueTask = require('./enqueueTask');
|
25
|
+
const Scheduler = require('scheduler/unstable_mock');
|
26
|
+
|
27
|
+
// The subset of a Promise that React APIs rely on. This resolves a value.
|
28
|
+
// This doesn't require a return value neither from the handler nor the
|
29
|
+
// then function.
|
30
|
+
interface Thenable<+R> {
|
31
|
+
then<U>(
|
32
|
+
onFulfill: (value: R) => void | Thenable<U> | U,
|
33
|
+
onReject: (error: mixed) => void | Thenable<U> | U,
|
34
|
+
): void | Thenable<U>;
|
35
|
+
}
|
36
|
+
|
37
|
+
let actingUpdatesScopeDepth = 0;
|
38
|
+
|
39
|
+
function act(scope: () => Thenable<mixed> | void) {
|
40
|
+
if (Scheduler.unstable_flushAllWithoutAsserting === undefined) {
|
41
|
+
throw Error(
|
42
|
+
'This version of `act` requires a special mock build of Scheduler.',
|
43
|
+
);
|
44
|
+
}
|
45
|
+
if (setTimeout._isMockFunction !== true) {
|
46
|
+
throw Error(
|
47
|
+
"This version of `act` requires Jest's timer mocks " +
|
48
|
+
'(i.e. jest.useFakeTimers).',
|
49
|
+
);
|
50
|
+
}
|
51
|
+
|
52
|
+
const previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
53
|
+
actingUpdatesScopeDepth++;
|
54
|
+
|
55
|
+
const unwind = () => {
|
56
|
+
actingUpdatesScopeDepth--;
|
57
|
+
|
58
|
+
if (__DEV__) {
|
59
|
+
if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
|
60
|
+
// if it's _less than_ previousActingUpdatesScopeDepth, then we can
|
61
|
+
// assume the 'other' one has warned
|
62
|
+
console.error(
|
63
|
+
'You seem to have overlapping act() calls, this is not supported. ' +
|
64
|
+
'Be sure to await previous act() calls before making a new one. ',
|
65
|
+
);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
// TODO: This would be way simpler if 1) we required a promise to be
|
71
|
+
// returned and 2) we could use async/await. Since it's only our used in
|
72
|
+
// our test suite, we should be able to.
|
73
|
+
try {
|
74
|
+
const thenable = scope();
|
75
|
+
if (
|
76
|
+
typeof thenable === 'object' &&
|
77
|
+
thenable !== null &&
|
78
|
+
typeof thenable.then === 'function'
|
79
|
+
) {
|
80
|
+
return {
|
81
|
+
then(resolve: () => void, reject: (error: mixed) => void) {
|
82
|
+
thenable.then(
|
83
|
+
() => {
|
84
|
+
flushActWork(
|
85
|
+
() => {
|
86
|
+
unwind();
|
87
|
+
resolve();
|
88
|
+
},
|
89
|
+
error => {
|
90
|
+
unwind();
|
91
|
+
reject(error);
|
92
|
+
},
|
93
|
+
);
|
94
|
+
},
|
95
|
+
error => {
|
96
|
+
unwind();
|
97
|
+
reject(error);
|
98
|
+
},
|
99
|
+
);
|
100
|
+
},
|
101
|
+
};
|
102
|
+
} else {
|
103
|
+
try {
|
104
|
+
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
105
|
+
// migrate existing tests.
|
106
|
+
let didFlushWork;
|
107
|
+
do {
|
108
|
+
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
109
|
+
} while (didFlushWork);
|
110
|
+
} finally {
|
111
|
+
unwind();
|
112
|
+
}
|
113
|
+
}
|
114
|
+
} catch (error) {
|
115
|
+
unwind();
|
116
|
+
throw error;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
function flushActWork(resolve, reject) {
|
121
|
+
// Flush suspended fallbacks
|
122
|
+
// $FlowFixMe: Flow doesn't know about global Jest object
|
123
|
+
jest.runOnlyPendingTimers();
|
124
|
+
enqueueTask(() => {
|
125
|
+
try {
|
126
|
+
const didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
127
|
+
if (didFlushWork) {
|
128
|
+
flushActWork(resolve, reject);
|
129
|
+
} else {
|
130
|
+
resolve();
|
131
|
+
}
|
132
|
+
} catch (error) {
|
133
|
+
reject(error);
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
|
138
|
+
exports.act = act;
|
package/legacy.js
CHANGED
package/legacy.js.flow
CHANGED
package/lib/ReactRelayContext.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -22,20 +22,18 @@ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inh
|
|
22
22
|
|
23
23
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
24
24
|
|
25
|
-
var React = require('react');
|
26
|
-
|
27
|
-
var areEqual = require("fbjs/lib/areEqual");
|
28
|
-
|
29
25
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
30
26
|
|
31
|
-
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
32
|
-
|
33
27
|
var _require = require('./ReactRelayContainerUtils'),
|
34
28
|
getContainerName = _require.getContainerName;
|
35
29
|
|
36
30
|
var _require2 = require('./RelayContext'),
|
37
31
|
assertRelayContext = _require2.assertRelayContext;
|
38
32
|
|
33
|
+
var areEqual = require("fbjs/lib/areEqual");
|
34
|
+
|
35
|
+
var React = require('react');
|
36
|
+
|
39
37
|
var _require3 = require('relay-runtime'),
|
40
38
|
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
41
39
|
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
@@ -142,19 +140,17 @@ function createContainerWithFragments(Component, fragments) {
|
|
142
140
|
var _proto = _class.prototype;
|
143
141
|
|
144
142
|
_proto.componentDidMount = function componentDidMount() {
|
145
|
-
this.
|
146
|
-
|
147
|
-
this._rerenderIfStoreHasChanged();
|
143
|
+
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
148
144
|
};
|
149
145
|
|
150
146
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
151
147
|
if (this.state.resolver !== prevState.resolver) {
|
152
148
|
prevState.resolver.dispose();
|
153
149
|
|
154
|
-
this.
|
150
|
+
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
151
|
+
} else {
|
152
|
+
this._rerenderIfStoreHasChanged();
|
155
153
|
}
|
156
|
-
|
157
|
-
this._rerenderIfStoreHasChanged();
|
158
154
|
};
|
159
155
|
|
160
156
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
@@ -207,11 +203,21 @@ function createContainerWithFragments(Component, fragments) {
|
|
207
203
|
}
|
208
204
|
};
|
209
205
|
|
210
|
-
_proto.
|
211
|
-
var
|
206
|
+
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
207
|
+
var _this$state2 = this.state,
|
208
|
+
data = _this$state2.data,
|
209
|
+
resolver = _this$state2.resolver;
|
210
|
+
var maybeNewData = resolver.resolve(); // Event listeners are only safe to add during the commit phase,
|
212
211
|
// So they won't leak if render is interrupted or errors.
|
213
212
|
|
214
|
-
resolver.setCallback(this._handleFragmentDataUpdate);
|
213
|
+
resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
|
214
|
+
// Check for this case, even though it requires an extra store read.
|
215
|
+
|
216
|
+
if (data !== maybeNewData) {
|
217
|
+
this.setState({
|
218
|
+
data: maybeNewData
|
219
|
+
});
|
220
|
+
}
|
215
221
|
};
|
216
222
|
|
217
223
|
_proto.render = function render() {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,10 +10,10 @@
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var React = require('react');
|
14
|
-
|
15
13
|
var ReactRelayContext = require('./ReactRelayContext');
|
16
14
|
|
15
|
+
var React = require('react');
|
16
|
+
|
17
17
|
function ReactRelayFragmentMockRenderer(props) {
|
18
18
|
return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
|
19
19
|
value: {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,24 +10,23 @@
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var React = require('react');
|
14
|
-
|
15
13
|
var ReactRelayContext = require('./ReactRelayContext');
|
16
14
|
|
17
15
|
var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
18
16
|
|
19
|
-
var
|
20
|
-
|
21
|
-
|
22
|
-
useMemo = React.useMemo;
|
17
|
+
var areEqual = require("fbjs/lib/areEqual");
|
18
|
+
|
19
|
+
var React = require('react');
|
23
20
|
|
24
21
|
var _require = require('relay-runtime'),
|
25
22
|
createOperationDescriptor = _require.createOperationDescriptor,
|
26
23
|
deepFreeze = _require.deepFreeze,
|
27
24
|
getRequest = _require.getRequest;
|
28
25
|
|
29
|
-
var
|
30
|
-
|
26
|
+
var useLayoutEffect = React.useLayoutEffect,
|
27
|
+
useState = React.useState,
|
28
|
+
useRef = React.useRef,
|
29
|
+
useMemo = React.useMemo;
|
31
30
|
var queryRendererContext = {
|
32
31
|
rootIsQueryRenderer: true
|
33
32
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -24,40 +24,40 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
24
24
|
|
25
25
|
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
26
26
|
|
27
|
-
var React = require('react');
|
28
|
-
|
29
|
-
var ReactRelayContext = require('./ReactRelayContext');
|
30
|
-
|
31
|
-
var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
32
|
-
|
33
|
-
var areEqual = require("fbjs/lib/areEqual");
|
34
|
-
|
35
27
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
36
28
|
|
37
29
|
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
38
30
|
|
39
|
-
var invariant = require('invariant');
|
40
|
-
|
41
|
-
var warning = require("fbjs/lib/warning");
|
42
|
-
|
43
31
|
var _require = require('./ReactRelayContainerUtils'),
|
44
32
|
getComponentName = _require.getComponentName,
|
45
33
|
getContainerName = _require.getContainerName;
|
46
34
|
|
35
|
+
var ReactRelayContext = require('./ReactRelayContext');
|
36
|
+
|
37
|
+
var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
38
|
+
|
47
39
|
var _require2 = require('./RelayContext'),
|
48
40
|
assertRelayContext = _require2.assertRelayContext;
|
49
41
|
|
42
|
+
var areEqual = require("fbjs/lib/areEqual");
|
43
|
+
|
44
|
+
var invariant = require('invariant');
|
45
|
+
|
46
|
+
var React = require('react');
|
47
|
+
|
50
48
|
var _require3 = require('relay-runtime'),
|
51
49
|
ConnectionInterface = _require3.ConnectionInterface,
|
52
50
|
Observable = _require3.Observable,
|
51
|
+
RelayFeatureFlags = _require3.RelayFeatureFlags,
|
53
52
|
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
54
53
|
createOperationDescriptor = _require3.createOperationDescriptor,
|
55
54
|
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
56
55
|
getRequest = _require3.getRequest,
|
57
|
-
getSelector = _require3.getSelector,
|
58
56
|
getVariablesFromObject = _require3.getVariablesFromObject,
|
59
57
|
isScalarAndEqual = _require3.isScalarAndEqual;
|
60
58
|
|
59
|
+
var warning = require("fbjs/lib/warning");
|
60
|
+
|
61
61
|
var FORWARD = 'forward';
|
62
62
|
|
63
63
|
/**
|
@@ -211,8 +211,7 @@ function createGetConnectionFromProps(metadata) {
|
|
211
211
|
|
212
212
|
function createGetFragmentVariables(metadata) {
|
213
213
|
var countVariable = metadata.count;
|
214
|
-
!countVariable ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getFragmentVariables function.') : invariant(false) : void 0;
|
215
|
-
|
214
|
+
!countVariable ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getFragmentVariables function.') : invariant(false) : void 0;
|
216
215
|
return function (prevVars, totalCount) {
|
217
216
|
return (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, prevVars), {}, (0, _defineProperty2["default"])({}, countVariable, totalCount));
|
218
217
|
};
|
@@ -354,12 +353,19 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
354
353
|
_this._isARequestInFlight = false;
|
355
354
|
_this._refetchSubscription = null;
|
356
355
|
_this._refetchVariables = null;
|
357
|
-
|
356
|
+
|
357
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
358
|
+
_this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
|
359
|
+
} else {
|
360
|
+
_this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer, _this._handleFragmentDataUpdate);
|
361
|
+
}
|
362
|
+
|
358
363
|
_this.state = {
|
359
364
|
data: _this._resolver.resolve(),
|
360
365
|
prevContext: relayContext,
|
361
366
|
contextForChildren: relayContext,
|
362
|
-
relayProp: _this._buildRelayProp(relayContext)
|
367
|
+
relayProp: _this._buildRelayProp(relayContext),
|
368
|
+
resolverGeneration: 0
|
363
369
|
};
|
364
370
|
_this._isUnmounted = false;
|
365
371
|
_this._hasFetched = false;
|
@@ -370,6 +376,20 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
370
376
|
|
371
377
|
_proto.componentDidMount = function componentDidMount() {
|
372
378
|
this._isUnmounted = false;
|
379
|
+
|
380
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
381
|
+
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
382
|
+
}
|
383
|
+
};
|
384
|
+
|
385
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
386
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
387
|
+
if (prevState.resolverGeneration !== this.state.resolverGeneration) {
|
388
|
+
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
389
|
+
} else {
|
390
|
+
this._rerenderIfStoreHasChanged();
|
391
|
+
}
|
392
|
+
}
|
373
393
|
}
|
374
394
|
/**
|
375
395
|
* When new props are received, read data for the new props and subscribe
|
@@ -379,6 +399,8 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
379
399
|
;
|
380
400
|
|
381
401
|
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
402
|
+
var _this2 = this;
|
403
|
+
|
382
404
|
var _nextProps$__rootIsQu;
|
383
405
|
|
384
406
|
var relayContext = assertRelayContext(nextProps.__relayContext);
|
@@ -396,11 +418,19 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
396
418
|
this._cleanup(); // Child containers rely on context.relay being mutated (for gDSFP).
|
397
419
|
|
398
420
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
421
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
422
|
+
this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer);
|
423
|
+
} else {
|
424
|
+
this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer, this._handleFragmentDataUpdate);
|
425
|
+
}
|
426
|
+
|
427
|
+
this.setState(function (prevState) {
|
428
|
+
return {
|
429
|
+
prevContext: relayContext,
|
430
|
+
contextForChildren: relayContext,
|
431
|
+
relayProp: _this2._buildRelayProp(relayContext),
|
432
|
+
resolverGeneration: prevState.resolverGeneration + 1
|
433
|
+
};
|
404
434
|
});
|
405
435
|
} else if (!this._hasFetched) {
|
406
436
|
this._resolver.setProps(nextProps);
|
@@ -423,7 +453,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
423
453
|
|
424
454
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
425
455
|
// Short-circuit if any Relay-related data has changed
|
426
|
-
if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
|
456
|
+
if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp || nextState.resolverGeneration !== this.state.resolverGeneration) {
|
427
457
|
return true;
|
428
458
|
} // Otherwise, for convenience short-circuit if all non-Relay props
|
429
459
|
// are scalar and equal
|
@@ -456,6 +486,37 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
456
486
|
refetchConnection: this._refetchConnection,
|
457
487
|
environment: relayContext.environment
|
458
488
|
};
|
489
|
+
};
|
490
|
+
|
491
|
+
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
492
|
+
var data = this.state.data; // External values could change between render and commit.
|
493
|
+
// Check for this case, even though it requires an extra store read.
|
494
|
+
|
495
|
+
var maybeNewData = this._resolver.resolve();
|
496
|
+
|
497
|
+
if (data !== maybeNewData) {
|
498
|
+
this.setState({
|
499
|
+
data: maybeNewData
|
500
|
+
});
|
501
|
+
}
|
502
|
+
};
|
503
|
+
|
504
|
+
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
505
|
+
var data = this.state.data;
|
506
|
+
|
507
|
+
var maybeNewData = this._resolver.resolve(); // Event listeners are only safe to add during the commit phase,
|
508
|
+
// So they won't leak if render is interrupted or errors.
|
509
|
+
|
510
|
+
|
511
|
+
this._resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
|
512
|
+
// Check for this case, even though it requires an extra store read.
|
513
|
+
|
514
|
+
|
515
|
+
if (data !== maybeNewData) {
|
516
|
+
this.setState({
|
517
|
+
data: maybeNewData
|
518
|
+
});
|
519
|
+
}
|
459
520
|
}
|
460
521
|
/**
|
461
522
|
* Render new data for the existing props/context.
|
@@ -525,7 +586,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
525
586
|
};
|
526
587
|
|
527
588
|
_proto._fetchPage = function _fetchPage(paginatingVariables, observer, options) {
|
528
|
-
var
|
589
|
+
var _this3 = this;
|
529
590
|
|
530
591
|
var _assertRelayContext = assertRelayContext(this.props.__relayContext),
|
531
592
|
environment = _assertRelayContext.environment;
|
@@ -537,17 +598,14 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
537
598
|
restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props2, ["componentRef", "__relayContext", "__rootIsQueryRenderer"]);
|
538
599
|
var props = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, restProps), this.state.data);
|
539
600
|
var fragmentVariables;
|
540
|
-
var rootVariables = getRootVariablesForFragments(fragments, restProps);
|
541
|
-
|
542
|
-
fragmentVariables = getVariablesFromObject(fragments, restProps); // $FlowFixMe[cannot-spread-interface]
|
543
|
-
|
601
|
+
var rootVariables = getRootVariablesForFragments(fragments, restProps);
|
602
|
+
fragmentVariables = getVariablesFromObject(fragments, restProps);
|
544
603
|
fragmentVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, rootVariables), fragmentVariables), this._refetchVariables);
|
545
604
|
var fetchVariables = connectionConfig.getVariables(props, {
|
546
605
|
count: paginatingVariables.count,
|
547
606
|
cursor: paginatingVariables.cursor
|
548
607
|
}, fragmentVariables);
|
549
|
-
!(typeof fetchVariables === 'object' && fetchVariables !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getVariables()` to ' + 'return an object, got `%s` in `%s`.', fetchVariables, componentName) : invariant(false) : void 0;
|
550
|
-
|
608
|
+
!(typeof fetchVariables === 'object' && fetchVariables !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getVariables()` to ' + 'return an object, got `%s` in `%s`.', fetchVariables, componentName) : invariant(false) : void 0;
|
551
609
|
fetchVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, fetchVariables), this._refetchVariables);
|
552
610
|
fragmentVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, fetchVariables), fragmentVariables);
|
553
611
|
var cacheConfig = options ? {
|
@@ -569,11 +627,11 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
569
627
|
this._hasFetched = true;
|
570
628
|
|
571
629
|
var onNext = function onNext(payload, complete) {
|
572
|
-
var prevData =
|
630
|
+
var prevData = _this3._resolver.resolve();
|
573
631
|
|
574
|
-
|
632
|
+
_this3._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount), operation.request.node);
|
575
633
|
|
576
|
-
var nextData =
|
634
|
+
var nextData = _this3._resolver.resolve(); // Workaround slightly different handling for connection in different
|
577
635
|
// core implementations:
|
578
636
|
// - Classic core requires the count to be explicitly incremented
|
579
637
|
// - Modern core automatically appends new items, updating the count
|
@@ -585,10 +643,10 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
585
643
|
|
586
644
|
|
587
645
|
if (!areEqual(prevData, nextData)) {
|
588
|
-
|
646
|
+
_this3.setState({
|
589
647
|
data: nextData,
|
590
648
|
contextForChildren: {
|
591
|
-
environment:
|
649
|
+
environment: _this3.props.__relayContext.environment
|
592
650
|
}
|
593
651
|
}, complete);
|
594
652
|
} else {
|
@@ -597,9 +655,9 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
597
655
|
};
|
598
656
|
|
599
657
|
var cleanup = function cleanup() {
|
600
|
-
if (
|
601
|
-
|
602
|
-
|
658
|
+
if (_this3._refetchSubscription === refetchSubscription) {
|
659
|
+
_this3._refetchSubscription = null;
|
660
|
+
_this3._isARequestInFlight = false;
|
603
661
|
}
|
604
662
|
};
|
605
663
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -17,9 +17,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
17
17
|
var invariant = require('invariant');
|
18
18
|
|
19
19
|
var _require = require('relay-runtime'),
|
20
|
+
fetchQuery = _require.__internal.fetchQuery,
|
20
21
|
createOperationDescriptor = _require.createOperationDescriptor,
|
21
|
-
isRelayModernEnvironment = _require.isRelayModernEnvironment
|
22
|
-
fetchQuery = _require.__internal.fetchQuery;
|
22
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment;
|
23
23
|
|
24
24
|
var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
25
25
|
function ReactRelayQueryFetcher(args) {
|