react-relay 14.1.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +19 -5
  9. package/ReactRelayQueryRenderer.js.flow +32 -1
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +1 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +7 -5
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +2 -2
  47. package/lib/ReactRelayContext.js +3 -3
  48. package/lib/ReactRelayFragmentContainer.js +39 -66
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -3
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -30
  51. package/lib/ReactRelayPaginationContainer.js +66 -159
  52. package/lib/ReactRelayQueryFetcher.js +48 -74
  53. package/lib/ReactRelayQueryRenderer.js +62 -82
  54. package/lib/ReactRelayQueryRendererContext.js +2 -1
  55. package/lib/ReactRelayRefetchContainer.js +52 -99
  56. package/lib/ReactRelayTestMocker.js +32 -66
  57. package/lib/ReactRelayTypes.js +2 -0
  58. package/lib/RelayContext.js +4 -6
  59. package/lib/assertFragmentMap.js +3 -4
  60. package/lib/buildReactRelayContainer.js +10 -25
  61. package/lib/getRootVariablesForFragments.js +5 -8
  62. package/lib/hooks.js +5 -17
  63. package/lib/index.js +5 -24
  64. package/lib/isRelayEnvironment.js +5 -3
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -7
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
  74. package/lib/relay-hooks/FragmentResource.js +102 -196
  75. package/lib/relay-hooks/HooksImplementation.js +2 -5
  76. package/lib/relay-hooks/InternalLogger.js +2 -2
  77. package/lib/relay-hooks/LRUCache.js +2 -19
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
  79. package/lib/relay-hooks/MatchContainer.js +14 -22
  80. package/lib/relay-hooks/ProfilerContext.js +3 -2
  81. package/lib/relay-hooks/QueryResource.js +30 -99
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
  83. package/lib/relay-hooks/SuspenseResource.js +8 -31
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +41 -77
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
  99. package/lib/relay-hooks/useClientQuery.js +3 -6
  100. package/lib/relay-hooks/useEntryPointLoader.js +17 -36
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
  102. package/lib/relay-hooks/useFragment.js +8 -18
  103. package/lib/relay-hooks/useFragmentNode.js +20 -31
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -5
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
  109. package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
  111. package/lib/relay-hooks/useMemoVariables.js +15 -33
  112. package/lib/relay-hooks/useMutation.js +8 -25
  113. package/lib/relay-hooks/usePaginationFragment.js +61 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +12 -29
  115. package/lib/relay-hooks/useQueryLoader.js +23 -47
  116. package/lib/relay-hooks/useRefetchableFragment.js +8 -18
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -7
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
  121. package/lib/relay-hooks/useSubscription.js +5 -9
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +1 -1
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
  135. package/relay-hooks/FragmentResource.js.flow +34 -8
  136. package/relay-hooks/HooksImplementation.js.flow +1 -1
  137. package/relay-hooks/InternalLogger.js.flow +1 -1
  138. package/relay-hooks/LRUCache.js.flow +1 -1
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
  140. package/relay-hooks/MatchContainer.js.flow +1 -1
  141. package/relay-hooks/ProfilerContext.js.flow +1 -1
  142. package/relay-hooks/QueryResource.js.flow +25 -5
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  144. package/relay-hooks/SuspenseResource.js.flow +1 -1
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
  153. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
  169. package/relay-hooks/useClientQuery.js.flow +1 -1
  170. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  171. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  172. package/relay-hooks/useFragment.js.flow +2 -2
  173. package/relay-hooks/useFragmentNode.js.flow +5 -4
  174. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  179. package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  181. package/relay-hooks/useMemoVariables.js.flow +13 -29
  182. package/relay-hooks/useMutation.js.flow +4 -4
  183. package/relay-hooks/usePaginationFragment.js.flow +53 -46
  184. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  185. package/relay-hooks/useQueryLoader.js.flow +85 -22
  186. package/relay-hooks/useRefetchableFragment.js.flow +64 -33
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  191. package/relay-hooks/useSubscription.js.flow +1 -1
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -27
  194. package/readContext.js.flow +0 -29
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v14.1.0
2
+ * Relay v15.0.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,10 +6,11 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
12
- import type {GeneratedNodeMap, RelayProp, $RelayProps} from './ReactRelayTypes';
13
+ import type {$RelayProps, GeneratedNodeMap, RelayProp} from './ReactRelayTypes';
13
14
  import type {
14
15
  FragmentMap,
15
16
  FragmentSpecResolver,
@@ -55,6 +56,7 @@ function createContainerWithFragments<
55
56
  const containerName = getContainerName(Component);
56
57
 
57
58
  return class extends React.Component<ContainerProps, ContainerState> {
59
+ // $FlowFixMe[missing-local-annot]
58
60
  static displayName = containerName;
59
61
  constructor(props: $FlowFixMe) {
60
62
  super(props);
@@ -88,7 +90,7 @@ function createContainerWithFragments<
88
90
  static getDerivedStateFromProps(
89
91
  nextProps: ContainerProps,
90
92
  prevState: ContainerState,
91
- ): $Shape<ContainerState> | null {
93
+ ): Partial<ContainerState> | null {
92
94
  // Any props change could impact the query, so we mirror props in state.
93
95
  // This is an unusual pattern, but necessary for this container usecase.
94
96
  const {prevProps} = prevState;
@@ -235,7 +237,9 @@ function createContainerWithFragments<
235
237
  }
236
238
  }
237
239
 
240
+ // $FlowFixMe[missing-local-annot]
238
241
  render() {
242
+ // eslint-disable-next-line no-unused-vars
239
243
  const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
240
244
  this.props;
241
245
  return React.createElement(Component, {
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,12 +6,14 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
12
13
 
13
14
  import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
14
15
  import type {GraphQLTaggedNode, IEnvironment, Variables} from 'relay-runtime';
16
+ import type {SelectorData} from 'relay-runtime/store/RelayStoreTypes';
15
17
 
16
18
  const ReactRelayContext = require('./ReactRelayContext');
17
19
  const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
@@ -61,9 +63,9 @@ function ReactRelayLocalQueryRenderer(props: Props): React.Node {
61
63
 
62
64
  // Use a ref to prevent rendering twice when data changes
63
65
  // because of props change
64
- const dataRef = useRef(null);
65
- const [, forceUpdate] = useState(null);
66
- const cleanupFnRef = useRef(null);
66
+ const dataRef = useRef<?SelectorData>(null);
67
+ const [, forceUpdate] = useState<?SelectorData>(null);
68
+ const cleanupFnRef = useRef<null | (() => void)>(null);
67
69
 
68
70
  const snapshot = useMemo(() => {
69
71
  environment.check(operation);
@@ -6,16 +6,18 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
12
13
 
14
+ import type {Sink} from '../relay-runtime/network/RelayObservable';
13
15
  import type {
16
+ $RelayProps,
14
17
  GeneratedNodeMap,
15
18
  ObserverOrCallback,
16
19
  RefetchOptions,
17
20
  RelayPaginationProp,
18
- $RelayProps,
19
21
  } from './ReactRelayTypes';
20
22
  import type {
21
23
  CacheConfig,
@@ -254,9 +256,9 @@ function createGetFragmentVariables(
254
256
  'ReactRelayPaginationContainer: Unable to synthesize a ' +
255
257
  'getFragmentVariables function.',
256
258
  );
257
- return (prevVars: Variables, totalCount: number) => ({
259
+ return (prevVars: Variables, totalCount: number): Variables => ({
258
260
  ...prevVars,
259
- [countVariable]: totalCount,
261
+ [(countVariable: string)]: totalCount,
260
262
  });
261
263
  }
262
264
 
@@ -346,6 +348,7 @@ function createContainerWithFragments<
346
348
  createGetFragmentVariables(metadata);
347
349
 
348
350
  return class extends React.Component<$FlowFixMeProps, ContainerState> {
351
+ // $FlowFixMe[missing-local-annot]
349
352
  static displayName = containerName;
350
353
 
351
354
  _isARequestInFlight: boolean;
@@ -564,6 +567,7 @@ function createContainerWithFragments<
564
567
  ...
565
568
  } {
566
569
  // Extract connection data and verify there are more edges to fetch
570
+ // eslint-disable-next-line no-unused-vars
567
571
  const {componentRef: _, ...restProps} = this.props;
568
572
  const props = {
569
573
  ...restProps,
@@ -694,7 +698,7 @@ function createContainerWithFragments<
694
698
  const observer = toObserver(observerOrCallback);
695
699
  const connectionData = this._getConnectionData();
696
700
  if (!connectionData) {
697
- Observable.create(sink => sink.complete()).subscribe(observer);
701
+ Observable.create<empty>(sink => sink.complete()).subscribe(observer);
698
702
  return null;
699
703
  }
700
704
  const totalCount = connectionData.edgeCount + pageSize;
@@ -755,8 +759,11 @@ function createContainerWithFragments<
755
759
  ): Subscription {
756
760
  const {environment} = assertRelayContext(this.props.__relayContext);
757
761
  const {
762
+ // eslint-disable-next-line no-unused-vars
758
763
  componentRef: _,
764
+ // eslint-disable-next-line no-unused-vars
759
765
  __relayContext,
766
+ // eslint-disable-next-line no-unused-vars
760
767
  __rootIsQueryRenderer,
761
768
  ...restProps
762
769
  } = this.props;
@@ -764,7 +771,7 @@ function createContainerWithFragments<
764
771
  ...restProps,
765
772
  ...this.state.data,
766
773
  };
767
- let fragmentVariables;
774
+ let fragmentVariables: Variables;
768
775
  const rootVariables = getRootVariablesForFragments(fragments, restProps);
769
776
  fragmentVariables = getVariablesFromObject(fragments, restProps);
770
777
  fragmentVariables = {
@@ -772,7 +779,7 @@ function createContainerWithFragments<
772
779
  ...fragmentVariables,
773
780
  ...this._refetchVariables,
774
781
  };
775
- let fetchVariables = connectionConfig.getVariables(
782
+ let fetchVariables: Variables = connectionConfig.getVariables(
776
783
  props,
777
784
  {
778
785
  count: paginatingVariables.count,
@@ -787,14 +794,14 @@ function createContainerWithFragments<
787
794
  fetchVariables,
788
795
  componentName,
789
796
  );
790
- fetchVariables = {
797
+ fetchVariables = ({
791
798
  ...fetchVariables,
792
799
  ...this._refetchVariables,
793
- };
794
- fragmentVariables = {
800
+ }: Variables);
801
+ fragmentVariables = ({
795
802
  ...fetchVariables,
796
803
  ...fragmentVariables,
797
- };
804
+ }: Variables);
798
805
 
799
806
  const cacheConfig: ?CacheConfig = options
800
807
  ? {force: !!options.force}
@@ -865,8 +872,8 @@ function createContainerWithFragments<
865
872
  operation,
866
873
  preservePreviousReferences: true,
867
874
  })
868
- .mergeMap(payload =>
869
- Observable.create(sink => {
875
+ .mergeMap<void>(payload =>
876
+ Observable.create<void>((sink: Sink<void>) => {
870
877
  onNext(payload, () => {
871
878
  sink.next(); // pass void to public observer's `next`
872
879
  sink.complete();
@@ -902,7 +909,9 @@ function createContainerWithFragments<
902
909
  }
903
910
  }
904
911
 
912
+ // $FlowFixMe[missing-local-annot]
905
913
  render() {
914
+ // eslint-disable-next-line no-unused-vars
906
915
  const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
907
916
  this.props;
908
917
  return (
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -62,7 +63,7 @@ class ReactRelayQueryFetcher {
62
63
  _snapshot: ?Snapshot; // results of the root fragment;
63
64
  _error: ?Error; // fetch error
64
65
  _cacheSelectionReference: ?Disposable;
65
- _callOnDataChangeWhenSet: boolean = false;
66
+ _didFetchFinish: boolean = false;
66
67
 
67
68
  constructor(args?: {
68
69
  cacheSelectionReference: ?Disposable,
@@ -102,6 +103,19 @@ class ReactRelayQueryFetcher {
102
103
  return null;
103
104
  }
104
105
 
106
+ getFetchResult(): ?{error?: Error, snapshot?: Snapshot} {
107
+ if (this._didFetchFinish) {
108
+ // We don't reset '_didFetchFinish' because another callback may be set
109
+ if (this._error != null) {
110
+ return {error: this._error};
111
+ } else if (this._snapshot != null) {
112
+ return {snapshot: this._snapshot};
113
+ }
114
+ } else {
115
+ return null;
116
+ }
117
+ }
118
+
105
119
  execute({
106
120
  environment,
107
121
  operation,
@@ -151,8 +165,8 @@ class ReactRelayQueryFetcher {
151
165
  this._fetchOptions.onDataChangeCallbacks || [];
152
166
  this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
153
167
 
154
- if (this._callOnDataChangeWhenSet) {
155
- // We don't reset '_callOnDataChangeWhenSet' because another callback may be set
168
+ if (this._didFetchFinish) {
169
+ // We don't reset '_didFetchFinish' because another callback may be set
156
170
  if (this._error != null) {
157
171
  onDataChange({error: this._error});
158
172
  } else if (this._snapshot != null) {
@@ -215,7 +229,7 @@ class ReactRelayQueryFetcher {
215
229
  next: () => {
216
230
  // If we received a response,
217
231
  // Make a note that to notify the callback when it's later added.
218
- this._callOnDataChangeWhenSet = true;
232
+ this._didFetchFinish = true;
219
233
  this._error = null;
220
234
 
221
235
  // Only notify of the first result if `next` is being called **asynchronously**
@@ -225,7 +239,7 @@ class ReactRelayQueryFetcher {
225
239
  error: err => {
226
240
  // If we received a response when we didn't have a change callback,
227
241
  // Make a note that to notify the callback when it's later added.
228
- this._callOnDataChangeWhenSet = true;
242
+ this._didFetchFinish = true;
229
243
  this._error = err;
230
244
  this._snapshot = null;
231
245
 
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -26,6 +27,7 @@ const ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
26
27
  const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
27
28
  const areEqual = require('areEqual');
28
29
  const React = require('react');
30
+ const {RelayFeatureFlags} = require('relay-runtime');
29
31
  const {
30
32
  createOperationDescriptor,
31
33
  deepFreeze,
@@ -169,7 +171,36 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
169
171
  this._maybeHiddenOrFastRefresh = false;
170
172
  // eslint-disable-next-line react/no-did-mount-set-state
171
173
  this.setState(prevState => {
172
- return resetQueryStateForUpdate(this.props, prevState);
174
+ const newState = resetQueryStateForUpdate(this.props, prevState);
175
+ const {requestCacheKey, queryFetcher} = newState;
176
+ if (requestCacheKey != null && requestCache[requestCacheKey] != null) {
177
+ if (RelayFeatureFlags.ENABLE_QUERY_RENDERER_SET_STATE_PREVENTION) {
178
+ const fetchResult = queryFetcher.getFetchResult();
179
+ if (fetchResult != null) {
180
+ const snapshot = fetchResult.snapshot ?? null;
181
+ const error = fetchResult.error ?? null;
182
+
183
+ const {requestCacheKey: prevRequestCacheKey} = prevState;
184
+ if (prevRequestCacheKey != null) {
185
+ delete requestCache[prevRequestCacheKey];
186
+ }
187
+
188
+ newState.renderProps = getRenderProps(
189
+ error,
190
+ snapshot,
191
+ queryFetcher,
192
+ prevState.retryCallbacks,
193
+ );
194
+ newState.snapshot = snapshot;
195
+ newState.requestCacheKey = null;
196
+ } else {
197
+ queryFetcher.setOnDataChange(this._handleDataChange);
198
+ }
199
+ } else {
200
+ queryFetcher.setOnDataChange(this._handleDataChange);
201
+ }
202
+ }
203
+ return newState;
173
204
  });
174
205
  return;
175
206
  }
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,16 +6,17 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
12
13
 
13
14
  import type {
15
+ $RelayProps,
14
16
  GeneratedNodeMap,
15
17
  ObserverOrCallback,
16
18
  RefetchOptions,
17
19
  RelayRefetchProp,
18
- $RelayProps,
19
20
  } from './ReactRelayTypes';
20
21
  import type {
21
22
  CacheConfig,
@@ -79,6 +80,7 @@ function createContainerWithFragments<
79
80
  const containerName = getContainerName(Component);
80
81
 
81
82
  return class extends React.Component<ContainerProps, ContainerState> {
83
+ // $FlowFixMe[missing-local-annot]
82
84
  static displayName = containerName;
83
85
 
84
86
  _refetchSubscription: ?Subscription;
@@ -142,7 +144,7 @@ function createContainerWithFragments<
142
144
  static getDerivedStateFromProps(
143
145
  nextProps: ContainerProps,
144
146
  prevState: ContainerState,
145
- ): $Shape<ContainerState> | null {
147
+ ): Partial<ContainerState> | null {
146
148
  // Any props change could impact the query, so we mirror props in state.
147
149
  // This is an unusual pattern, but necessary for this container usecase.
148
150
  const {prevProps} = prevState;
@@ -369,7 +371,7 @@ function createContainerWithFragments<
369
371
 
370
372
  // Declare refetchSubscription before assigning it in .start(), since
371
373
  // synchronous completion may call callbacks .subscribe() returns.
372
- let refetchSubscription;
374
+ let refetchSubscription: Subscription;
373
375
 
374
376
  const storeSnapshot = this._getQueryFetcher().lookupInStore(
375
377
  environment,
@@ -405,12 +407,12 @@ function createContainerWithFragments<
405
407
  // TODO (T26430099): Cleanup old references
406
408
  preservePreviousReferences: true,
407
409
  })
408
- .mergeMap(response => {
410
+ .mergeMap<void>(response => {
409
411
  this.state.resolver.setVariables(
410
412
  fragmentVariables,
411
413
  operation.request.node,
412
414
  );
413
- return Observable.create(sink =>
415
+ return Observable.create<void>(sink =>
414
416
  this.setState(
415
417
  latestState => ({
416
418
  data: latestState.resolver.resolve(),
@@ -447,7 +449,9 @@ function createContainerWithFragments<
447
449
  };
448
450
  };
449
451
 
452
+ // $FlowFixMe[missing-local-annot]
450
453
  render() {
454
+ // eslint-disable-next-line no-unused-vars
451
455
  const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
452
456
  this.props;
453
457
  const {relayProp, contextForChildren} = this.state;
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -13,6 +14,7 @@
13
14
  import type {
14
15
  CacheConfig,
15
16
  ConcreteRequest,
17
+ GraphQLResponse,
16
18
  GraphQLSingularResponse,
17
19
  IEnvironment,
18
20
  PayloadError,
@@ -145,7 +147,7 @@ class ReactRelayTestMocker {
145
147
  ) => {
146
148
  let resolve;
147
149
  let reject;
148
- const promise = new Promise((res, rej) => {
150
+ const promise = new Promise<GraphQLResponse>((res, rej) => {
149
151
  resolve = res;
150
152
  reject = rej;
151
153
  });
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -139,7 +140,7 @@ module.exports = {
139
140
  render(): React.Element<typeof Bar> {
140
141
  return (
141
142
  <Bar
142
- componentRef={ref => {
143
+ componentRef={(ref: empty) => {
143
144
  this._barRef = (ref: empty);
144
145
  }}
145
146
  requiredProp="bar"
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -4,7 +4,9 @@
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<<23bcef30afc22a42d79dd52e0cfe899c>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<97ebbfa87de00690617b84f5dc0b3dd7>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -4,7 +4,9 @@
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<<af6c4570779066ea564051c9c71c494f>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<493af2df808158f1c08ec6aafda2e783>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -4,7 +4,9 @@
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<<6d173a357c286b417fdc586a839384d4>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<073d1d174775daaac06d462623886192>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -16,7 +18,7 @@
16
18
 
17
19
  /*::
18
20
  import type { ConcreteRequest, Query } from 'relay-runtime';
19
- type ReactRelayPaginationContainerFlowtest_viewer$fragmentType = any;
21
+ import type { ReactRelayPaginationContainerFlowtest_viewer$fragmentType } from "./ReactRelayPaginationContainerFlowtest_viewer.graphql";
20
22
  export type ReactRelayPaginationContainerFlowtestQuery$variables = {|
21
23
  count: number,
22
24
  cursor?: ?string,
@@ -4,7 +4,9 @@
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<<b3cddee250d0ff22e89a7f0331e85df6>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<03cbc84be1e0fb9c3986ea29a3e335db>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -4,7 +4,9 @@
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<<3b1b16b5d5ec1c94783d6161ae61bc3d>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<909036439f4d2e9e2d5728ade52035dc>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -16,7 +18,7 @@
16
18
 
17
19
  /*::
18
20
  import type { ConcreteRequest, Query } from 'relay-runtime';
19
- type ReactRelayRefetchContainerFlowtest_viewer$fragmentType = any;
21
+ import type { ReactRelayRefetchContainerFlowtest_viewer$fragmentType } from "./ReactRelayRefetchContainerFlowtest_viewer.graphql";
20
22
  export type ReactRelayRefetchContainerFlowtestQuery$variables = {|
21
23
  count: number,
22
24
  cursor?: ?string,
@@ -4,7 +4,9 @@
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<<6d04d7f7bf097d5869a1fdf0dea1e659>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<6f9cebfabb127ad6db1de1705f8a9764>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -4,7 +4,9 @@
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<<d3c71cb965d8374d40fb30f3c5ae9fd4>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<1d67fc8ab171aeb4c45cb1df2d036371>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -16,7 +18,7 @@
16
18
 
17
19
  /*::
18
20
  import type { Fragment, ReaderFragment } from 'relay-runtime';
19
- type RelayModernFlowtest_user$fragmentType = any;
21
+ import type { RelayModernFlowtest_user$fragmentType } from "./RelayModernFlowtest_user.graphql";
20
22
  import type { FragmentType } from "relay-runtime";
21
23
  declare export opaque type RelayModernFlowtest_badref$fragmentType: FragmentType;
22
24
  export type RelayModernFlowtest_badref$data = {|