react-relay 13.1.0 → 14.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +7 -4
- package/ReactRelayLocalQueryRenderer.js.flow +1 -1
- package/ReactRelayPaginationContainer.js.flow +13 -8
- package/ReactRelayQueryFetcher.js.flow +1 -0
- package/ReactRelayQueryRenderer.js.flow +7 -6
- package/ReactRelayRefetchContainer.js.flow +10 -3
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +2 -2
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/jest-react/internalAct.js.flow +25 -9
- package/legacy.js +1 -1
- package/lib/ReactRelayQueryFetcher.js +1 -0
- package/lib/ReactRelayQueryRenderer.js +1 -2
- package/lib/jest-react/internalAct.js +24 -4
- package/lib/readContext.js +2 -1
- package/lib/relay-hooks/FragmentResource.js +62 -23
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- package/lib/relay-hooks/MatchContainer.js +1 -0
- package/lib/relay-hooks/QueryResource.js +4 -166
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +7 -11
- package/lib/relay-hooks/react-cache/RelayReactCache.js +37 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +540 -0
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +51 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +56 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +125 -0
- package/lib/relay-hooks/useFragment.js +15 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +18 -2
- package/lib/relay-hooks/useMutation.js +4 -5
- package/lib/relay-hooks/usePreloadedQuery.js +18 -2
- 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 -0
- package/relay-hooks/FragmentResource.js.flow +72 -27
- package/relay-hooks/HooksImplementation.js.flow +45 -0
- package/relay-hooks/MatchContainer.js.flow +8 -1
- package/relay-hooks/QueryResource.js.flow +8 -203
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
- package/relay-hooks/loadQuery.js.flow +2 -1
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +7 -14
- package/relay-hooks/react-cache/RelayReactCache.js.flow +42 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +424 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +559 -0
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +74 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +72 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +153 -0
- package/relay-hooks/useFragment.js.flow +17 -10
- package/relay-hooks/useLazyLoadQuery.js.flow +38 -3
- package/relay-hooks/useMutation.js.flow +3 -3
- package/relay-hooks/usePreloadedQuery.js.flow +30 -2
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -11
- package/relay-hooks/useSubscription.js.flow +14 -8
package/ReactRelayContext.js
CHANGED
@@ -11,11 +11,11 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
|
13
13
|
'use strict';
|
14
|
-
|
15
14
|
import type {GeneratedNodeMap, RelayProp, $RelayProps} from './ReactRelayTypes';
|
16
15
|
import type {
|
17
16
|
FragmentMap,
|
18
17
|
FragmentSpecResolver,
|
18
|
+
IEnvironment,
|
19
19
|
RelayContext,
|
20
20
|
} from 'relay-runtime';
|
21
21
|
|
@@ -58,7 +58,7 @@ function createContainerWithFragments<
|
|
58
58
|
|
59
59
|
return class extends React.Component<ContainerProps, ContainerState> {
|
60
60
|
static displayName = containerName;
|
61
|
-
constructor(props) {
|
61
|
+
constructor(props: $FlowFixMe) {
|
62
62
|
super(props);
|
63
63
|
const relayContext = assertRelayContext(props.__relayContext);
|
64
64
|
const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
|
@@ -163,7 +163,10 @@ function createContainerWithFragments<
|
|
163
163
|
this.state.resolver.dispose();
|
164
164
|
}
|
165
165
|
|
166
|
-
shouldComponentUpdate(
|
166
|
+
shouldComponentUpdate(
|
167
|
+
nextProps: ContainerProps,
|
168
|
+
nextState: ContainerState,
|
169
|
+
): boolean {
|
167
170
|
// Short-circuit if any Relay-related data has changed
|
168
171
|
if (nextState.data !== this.state.data) {
|
169
172
|
return true;
|
@@ -247,7 +250,7 @@ function createContainerWithFragments<
|
|
247
250
|
};
|
248
251
|
}
|
249
252
|
|
250
|
-
function getRelayProp(environment) {
|
253
|
+
function getRelayProp(environment: IEnvironment) {
|
251
254
|
return {
|
252
255
|
environment,
|
253
256
|
};
|
@@ -40,7 +40,7 @@ const queryRendererContext: ReactRelayQueryRendererContextType = {
|
|
40
40
|
rootIsQueryRenderer: true,
|
41
41
|
};
|
42
42
|
|
43
|
-
function useDeepCompare<T:
|
43
|
+
function useDeepCompare<T: {...}>(value: T): T {
|
44
44
|
const latestValue = React.useRef(value);
|
45
45
|
if (!areEqual(latestValue.current, value)) {
|
46
46
|
if (__DEV__) {
|
@@ -235,7 +235,7 @@ function createGetConnectionFromProps(metadata: ReactConnectionMetadata) {
|
|
235
235
|
'ReactRelayPaginationContainer: Unable to synthesize a ' +
|
236
236
|
'getConnectionFromProps function.',
|
237
237
|
);
|
238
|
-
return props => {
|
238
|
+
return (props: any) => {
|
239
239
|
let data = props[metadata.fragmentName];
|
240
240
|
for (let i = 0; i < path.length; i++) {
|
241
241
|
if (!data || typeof data !== 'object') {
|
@@ -264,7 +264,9 @@ function createGetFragmentVariables(
|
|
264
264
|
|
265
265
|
type ReactConnectionMetadata = ConnectionMetadata & {fragmentName: string, ...};
|
266
266
|
|
267
|
-
function findConnectionMetadata(
|
267
|
+
function findConnectionMetadata(
|
268
|
+
fragments: FragmentMap,
|
269
|
+
): ReactConnectionMetadata {
|
268
270
|
let foundConnectionMetadata = null;
|
269
271
|
let isRelayModern = false;
|
270
272
|
for (const fragmentName in fragments) {
|
@@ -308,7 +310,7 @@ function toObserver(observerOrCallback: ?ObserverOrCallback): Observer<void> {
|
|
308
310
|
? {
|
309
311
|
error: observerOrCallback,
|
310
312
|
complete: observerOrCallback,
|
311
|
-
unsubscribe: subscription => {
|
313
|
+
unsubscribe: (subscription: Subscription) => {
|
312
314
|
typeof observerOrCallback === 'function' && observerOrCallback();
|
313
315
|
},
|
314
316
|
}
|
@@ -356,7 +358,7 @@ function createContainerWithFragments<
|
|
356
358
|
_isUnmounted: boolean;
|
357
359
|
_hasFetched: boolean;
|
358
360
|
|
359
|
-
constructor(props) {
|
361
|
+
constructor(props: any) {
|
360
362
|
super(props);
|
361
363
|
const relayContext = assertRelayContext(props.__relayContext);
|
362
364
|
const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
|
@@ -415,7 +417,7 @@ function createContainerWithFragments<
|
|
415
417
|
* for updates. Props may be the same in which case previous data and
|
416
418
|
* subscriptions can be reused.
|
417
419
|
*/
|
418
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
420
|
+
UNSAFE_componentWillReceiveProps(nextProps: any) {
|
419
421
|
const relayContext = assertRelayContext(nextProps.__relayContext);
|
420
422
|
const rootIsQueryRenderer = nextProps.__rootIsQueryRenderer ?? false;
|
421
423
|
const prevIDs = getDataIDsFromObject(fragments, this.props);
|
@@ -479,7 +481,10 @@ function createContainerWithFragments<
|
|
479
481
|
this._cleanup();
|
480
482
|
}
|
481
483
|
|
482
|
-
shouldComponentUpdate(
|
484
|
+
shouldComponentUpdate(
|
485
|
+
nextProps: Props,
|
486
|
+
nextState: ContainerState,
|
487
|
+
): boolean {
|
483
488
|
// Short-circuit if any Relay-related data has changed
|
484
489
|
if (
|
485
490
|
nextState.data !== this.state.data ||
|
@@ -722,7 +727,7 @@ function createContainerWithFragments<
|
|
722
727
|
return this._queryFetcher;
|
723
728
|
}
|
724
729
|
|
725
|
-
_canFetchPage(method): boolean {
|
730
|
+
_canFetchPage(method: 'loadMore' | 'refetchConnection'): boolean {
|
726
731
|
if (this._isUnmounted) {
|
727
732
|
warning(
|
728
733
|
false,
|
@@ -813,7 +818,7 @@ function createContainerWithFragments<
|
|
813
818
|
}
|
814
819
|
this._hasFetched = true;
|
815
820
|
|
816
|
-
const onNext = (payload, complete) => {
|
821
|
+
const onNext = (payload: mixed, complete: () => void) => {
|
817
822
|
const prevData = this._resolver.resolve();
|
818
823
|
this._resolver.setVariables(
|
819
824
|
getFragmentVariables(
|
@@ -29,7 +29,6 @@ const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext
|
|
29
29
|
const areEqual = require('areEqual');
|
30
30
|
const React = require('react');
|
31
31
|
const {
|
32
|
-
RelayFeatureFlags,
|
33
32
|
createOperationDescriptor,
|
34
33
|
deepFreeze,
|
35
34
|
getRequest,
|
@@ -56,7 +55,12 @@ export type RenderProps<T> = {|
|
|
56
55
|
* constructor. If a request is already in flight from a previous call to the
|
57
56
|
* constructor, just reuse the query fetcher and wait for the response.
|
58
57
|
*/
|
59
|
-
const requestCache
|
58
|
+
const requestCache: {
|
59
|
+
[string]: void | {|
|
60
|
+
queryFetcher: ReactRelayQueryFetcher,
|
61
|
+
snapshot: ?Snapshot,
|
62
|
+
|},
|
63
|
+
} = {};
|
60
64
|
|
61
65
|
const queryRendererContext: ReactRelayQueryRendererContextType = {
|
62
66
|
rootIsQueryRenderer: true,
|
@@ -157,10 +161,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
157
161
|
}
|
158
162
|
|
159
163
|
componentDidMount() {
|
160
|
-
if (
|
161
|
-
RelayFeatureFlags.ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT === true &&
|
162
|
-
this._maybeHiddenOrFastRefresh === true
|
163
|
-
) {
|
164
|
+
if (this._maybeHiddenOrFastRefresh === true) {
|
164
165
|
// This block only runs if the component has previously "unmounted"
|
165
166
|
// due to it being hidden by the Offscreen API, or during fast refresh.
|
166
167
|
// At this point, the current cached resource will have been disposed
|
@@ -24,6 +24,7 @@ import type {
|
|
24
24
|
Disposable,
|
25
25
|
FragmentMap,
|
26
26
|
GraphQLTaggedNode,
|
27
|
+
IEnvironment,
|
27
28
|
RelayContext,
|
28
29
|
Subscription,
|
29
30
|
Variables,
|
@@ -86,7 +87,7 @@ function createContainerWithFragments<
|
|
86
87
|
_queryFetcher: ?ReactRelayQueryFetcher;
|
87
88
|
_isUnmounted: boolean;
|
88
89
|
|
89
|
-
constructor(props) {
|
90
|
+
constructor(props: any) {
|
90
91
|
super(props);
|
91
92
|
const relayContext = assertRelayContext(props.__relayContext);
|
92
93
|
const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
|
@@ -217,7 +218,10 @@ function createContainerWithFragments<
|
|
217
218
|
this._refetchSubscription && this._refetchSubscription.unsubscribe();
|
218
219
|
}
|
219
220
|
|
220
|
-
shouldComponentUpdate(
|
221
|
+
shouldComponentUpdate(
|
222
|
+
nextProps: ContainerProps,
|
223
|
+
nextState: ContainerState,
|
224
|
+
): boolean {
|
221
225
|
// Short-circuit if any Relay-related data has changed
|
222
226
|
if (
|
223
227
|
nextState.data !== this.state.data ||
|
@@ -465,7 +469,10 @@ function createContainerWithFragments<
|
|
465
469
|
};
|
466
470
|
}
|
467
471
|
|
468
|
-
function getRelayProp(
|
472
|
+
function getRelayProp(
|
473
|
+
environment: IEnvironment,
|
474
|
+
refetch: RelayRefetchProp['refetch'],
|
475
|
+
): RelayRefetchProp {
|
469
476
|
return {
|
470
477
|
environment,
|
471
478
|
refetch,
|
package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<23bcef30afc22a42d79dd52e0cfe899c>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<af6c4570779066ea564051c9c71c494f>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<6d173a357c286b417fdc586a839384d4>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -27,8 +27,8 @@ export type ReactRelayPaginationContainerFlowtestQuery$data = {|
|
|
27
27
|
|},
|
28
28
|
|};
|
29
29
|
export type ReactRelayPaginationContainerFlowtestQuery = {|
|
30
|
-
variables: ReactRelayPaginationContainerFlowtestQuery$variables,
|
31
30
|
response: ReactRelayPaginationContainerFlowtestQuery$data,
|
31
|
+
variables: ReactRelayPaginationContainerFlowtestQuery$variables,
|
32
32
|
|};
|
33
33
|
*/
|
34
34
|
|
package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<b3cddee250d0ff22e89a7f0331e85df6>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -23,7 +23,7 @@ export type ReactRelayPaginationContainerFlowtest_viewer$data = {|
|
|
23
23
|
+friends: ?{|
|
24
24
|
+edges: ?$ReadOnlyArray<?{|
|
25
25
|
+node: ?{|
|
26
|
-
+__typename:
|
26
|
+
+__typename: "User",
|
27
27
|
|},
|
28
28
|
|}>,
|
29
29
|
|},
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<3b1b16b5d5ec1c94783d6161ae61bc3d>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -27,8 +27,8 @@ export type ReactRelayRefetchContainerFlowtestQuery$data = {|
|
|
27
27
|
|},
|
28
28
|
|};
|
29
29
|
export type ReactRelayRefetchContainerFlowtestQuery = {|
|
30
|
-
variables: ReactRelayRefetchContainerFlowtestQuery$variables,
|
31
30
|
response: ReactRelayRefetchContainerFlowtestQuery$data,
|
31
|
+
variables: ReactRelayRefetchContainerFlowtestQuery$variables,
|
32
32
|
|};
|
33
33
|
*/
|
34
34
|
|
package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<6d04d7f7bf097d5869a1fdf0dea1e659>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -23,7 +23,7 @@ export type ReactRelayRefetchContainerFlowtest_viewer$data = {|
|
|
23
23
|
+friends: ?{|
|
24
24
|
+edges: ?$ReadOnlyArray<?{|
|
25
25
|
+node: ?{|
|
26
|
-
+__typename:
|
26
|
+
+__typename: "User",
|
27
27
|
|},
|
28
28
|
|}>,
|
29
29
|
|},
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<d3c71cb965d8374d40fb30f3c5ae9fd4>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<bd60df80c19d8248426865abbc23562e>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<527809017626cb43378afb92fed67feb>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
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.
|
6
6
|
*
|
7
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<8a94ce305c03af7280da9b95a665349f>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -11,7 +11,7 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
|
13
13
|
'use strict';
|
14
|
-
|
14
|
+
import type {ReaderFragment} from '../relay-runtime/util/ReaderNode';
|
15
15
|
import type {GeneratedNodeMap} from './ReactRelayTypes';
|
16
16
|
import type {FragmentMap} from 'relay-runtime';
|
17
17
|
|
@@ -45,7 +45,7 @@ function buildReactRelayContainer<TBase: React$ComponentType<any>>(
|
|
45
45
|
const containerName = getContainerName(ComponentClass);
|
46
46
|
assertFragmentMap(getComponentName(ComponentClass), fragmentSpec);
|
47
47
|
|
48
|
-
const fragments = {};
|
48
|
+
const fragments: {[string]: ReaderFragment} = {};
|
49
49
|
for (const key in fragmentSpec) {
|
50
50
|
fragments[key] = getFragment(fragmentSpec[key]);
|
51
51
|
}
|
package/hooks.js
CHANGED
package/index.js
CHANGED
@@ -36,7 +36,7 @@ interface Thenable<+R> {
|
|
36
36
|
|
37
37
|
let actingUpdatesScopeDepth = 0;
|
38
38
|
|
39
|
-
function act(scope: () => Thenable<
|
39
|
+
function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
|
40
40
|
if (Scheduler.unstable_flushAllWithoutAsserting === undefined) {
|
41
41
|
throw Error(
|
42
42
|
'This version of `act` requires a special mock build of Scheduler.',
|
@@ -49,10 +49,19 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
49
49
|
);
|
50
50
|
}
|
51
51
|
|
52
|
+
const previousIsActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
52
53
|
const previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
53
54
|
actingUpdatesScopeDepth++;
|
55
|
+
if (__DEV__ && actingUpdatesScopeDepth === 1) {
|
56
|
+
// Because this is not the "real" `act`, we set this to `false` so React
|
57
|
+
// knows not to fire `act` warnings.
|
58
|
+
global.IS_REACT_ACT_ENVIRONMENT = false;
|
59
|
+
}
|
54
60
|
|
55
61
|
const unwind = () => {
|
62
|
+
if (__DEV__ && actingUpdatesScopeDepth === 1) {
|
63
|
+
global.IS_REACT_ACT_ENVIRONMENT = previousIsActEnvironment;
|
64
|
+
}
|
56
65
|
actingUpdatesScopeDepth--;
|
57
66
|
|
58
67
|
if (__DEV__) {
|
@@ -71,20 +80,21 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
71
80
|
// returned and 2) we could use async/await. Since it's only our used in
|
72
81
|
// our test suite, we should be able to.
|
73
82
|
try {
|
74
|
-
const
|
83
|
+
const result = scope();
|
75
84
|
if (
|
76
|
-
typeof
|
77
|
-
|
78
|
-
typeof
|
85
|
+
typeof result === 'object' &&
|
86
|
+
result !== null &&
|
87
|
+
typeof result.then === 'function'
|
79
88
|
) {
|
89
|
+
const thenableResult: Thenable<T> = (result: any);
|
80
90
|
return {
|
81
|
-
then(resolve
|
82
|
-
|
83
|
-
|
91
|
+
then(resolve, reject) {
|
92
|
+
thenableResult.then(
|
93
|
+
returnValue => {
|
84
94
|
flushActWork(
|
85
95
|
() => {
|
86
96
|
unwind();
|
87
|
-
resolve();
|
97
|
+
resolve(returnValue);
|
88
98
|
},
|
89
99
|
error => {
|
90
100
|
unwind();
|
@@ -100,6 +110,7 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
100
110
|
},
|
101
111
|
};
|
102
112
|
} else {
|
113
|
+
const returnValue: T = (result: any);
|
103
114
|
try {
|
104
115
|
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
105
116
|
// migrate existing tests.
|
@@ -107,6 +118,11 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
107
118
|
do {
|
108
119
|
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
109
120
|
} while (didFlushWork);
|
121
|
+
return {
|
122
|
+
then(resolve, reject) {
|
123
|
+
resolve(returnValue);
|
124
|
+
},
|
125
|
+
};
|
110
126
|
} finally {
|
111
127
|
unwind();
|
112
128
|
}
|
package/legacy.js
CHANGED
@@ -153,6 +153,7 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
153
153
|
};
|
154
154
|
|
155
155
|
if (onDataChange && this._fetchOptions.onDataChangeCallbacks.indexOf(onDataChange) === -1) {
|
156
|
+
// $FlowFixMe[incompatible-use]
|
156
157
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
157
158
|
}
|
158
159
|
|
@@ -31,7 +31,6 @@ var areEqual = require("fbjs/lib/areEqual");
|
|
31
31
|
var React = require('react');
|
32
32
|
|
33
33
|
var _require = require('relay-runtime'),
|
34
|
-
RelayFeatureFlags = _require.RelayFeatureFlags,
|
35
34
|
createOperationDescriptor = _require.createOperationDescriptor,
|
36
35
|
deepFreeze = _require.deepFreeze,
|
37
36
|
getRequest = _require.getRequest;
|
@@ -132,7 +131,7 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
|
|
132
131
|
_proto.componentDidMount = function componentDidMount() {
|
133
132
|
var _this2 = this;
|
134
133
|
|
135
|
-
if (
|
134
|
+
if (this._maybeHiddenOrFastRefresh === true) {
|
136
135
|
// This block only runs if the component has previously "unmounted"
|
137
136
|
// due to it being hidden by the Offscreen API, or during fast refresh.
|
138
137
|
// At this point, the current cached resource will have been disposed
|
@@ -36,10 +36,21 @@ function act(scope) {
|
|
36
36
|
throw Error("This version of `act` requires Jest's timer mocks " + '(i.e. jest.useFakeTimers).');
|
37
37
|
}
|
38
38
|
|
39
|
+
var previousIsActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
39
40
|
var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
40
41
|
actingUpdatesScopeDepth++;
|
41
42
|
|
43
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
44
|
+
// Because this is not the "real" `act`, we set this to `false` so React
|
45
|
+
// knows not to fire `act` warnings.
|
46
|
+
global.IS_REACT_ACT_ENVIRONMENT = false;
|
47
|
+
}
|
48
|
+
|
42
49
|
var unwind = function unwind() {
|
50
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
51
|
+
global.IS_REACT_ACT_ENVIRONMENT = previousIsActEnvironment;
|
52
|
+
}
|
53
|
+
|
43
54
|
actingUpdatesScopeDepth--;
|
44
55
|
|
45
56
|
if (process.env.NODE_ENV !== "production") {
|
@@ -55,15 +66,16 @@ function act(scope) {
|
|
55
66
|
|
56
67
|
|
57
68
|
try {
|
58
|
-
var
|
69
|
+
var result = scope();
|
59
70
|
|
60
|
-
if (typeof
|
71
|
+
if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
|
72
|
+
var thenableResult = result;
|
61
73
|
return {
|
62
74
|
then: function then(resolve, reject) {
|
63
|
-
|
75
|
+
thenableResult.then(function (returnValue) {
|
64
76
|
flushActWork(function () {
|
65
77
|
unwind();
|
66
|
-
resolve();
|
78
|
+
resolve(returnValue);
|
67
79
|
}, function (error) {
|
68
80
|
unwind();
|
69
81
|
reject(error);
|
@@ -75,6 +87,8 @@ function act(scope) {
|
|
75
87
|
}
|
76
88
|
};
|
77
89
|
} else {
|
90
|
+
var returnValue = result;
|
91
|
+
|
78
92
|
try {
|
79
93
|
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
80
94
|
// migrate existing tests.
|
@@ -83,6 +97,12 @@ function act(scope) {
|
|
83
97
|
do {
|
84
98
|
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
85
99
|
} while (didFlushWork);
|
100
|
+
|
101
|
+
return {
|
102
|
+
then: function then(resolve, reject) {
|
103
|
+
resolve(returnValue);
|
104
|
+
}
|
105
|
+
};
|
86
106
|
} finally {
|
87
107
|
unwind();
|
88
108
|
}
|
package/lib/readContext.js
CHANGED
@@ -10,7 +10,8 @@
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var React = require('react');
|
13
|
+
var React = require('react'); // $FlowFixMe[incompatible-use]
|
14
|
+
|
14
15
|
|
15
16
|
var _React$__SECRET_INTER =
|
16
17
|
/* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
|