react-relay 17.0.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/ReactRelayContainerUtils.js.flow +2 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -1
  4. package/ReactRelayFragmentContainer.js.flow +2 -2
  5. package/ReactRelayPaginationContainer.js.flow +2 -2
  6. package/ReactRelayQueryRenderer.js.flow +1 -1
  7. package/ReactRelayQueryRendererContext.js.flow +1 -1
  8. package/ReactRelayRefetchContainer.js.flow +2 -2
  9. package/ReactRelayTypes.js.flow +45 -18
  10. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
  11. package/buildReactRelayContainer.js.flow +5 -5
  12. package/hooks.js +1 -1
  13. package/index.js +1 -1
  14. package/legacy.js +1 -1
  15. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  16. package/lib/relay-hooks/loadQuery.js +2 -14
  17. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  18. package/lib/relay-hooks/useFragment.js +4 -7
  19. package/lib/relay-hooks/useFragmentInternal.js +6 -484
  20. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +483 -0
  21. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
  22. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  23. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  24. package/lib/relay-hooks/useQueryLoader.js +1 -3
  25. package/multi-actor/ActorChange.js.flow +1 -1
  26. package/package.json +3 -3
  27. package/react-relay-hooks.js +2 -2
  28. package/react-relay-hooks.min.js +2 -2
  29. package/react-relay-legacy.js +1 -1
  30. package/react-relay-legacy.min.js +1 -1
  31. package/react-relay.js +2 -2
  32. package/react-relay.min.js +2 -2
  33. package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
  34. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
  35. package/relay-hooks/MatchContainer.js.flow +1 -1
  36. package/relay-hooks/ProfilerContext.js.flow +1 -1
  37. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  38. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  39. package/relay-hooks/loadQuery.js.flow +4 -28
  40. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  41. package/relay-hooks/useEntryPointLoader.js.flow +3 -4
  42. package/relay-hooks/useFragment.js.flow +0 -5
  43. package/relay-hooks/useFragmentInternal.js.flow +19 -643
  44. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +669 -0
  45. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
  46. package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
  47. package/relay-hooks/usePaginationFragment.js.flow +1 -1
  48. package/relay-hooks/usePreloadedQuery.js.flow +0 -5
  49. package/relay-hooks/useQueryLoader.js.flow +1 -2
@@ -30,7 +30,6 @@ import type {
30
30
  } from 'relay-runtime';
31
31
 
32
32
  const invariant = require('invariant');
33
- const React = require('react');
34
33
  const {
35
34
  __internal: {fetchQueryDeduped},
36
35
  Observable,
@@ -41,30 +40,19 @@ const {
41
40
  getRequest,
42
41
  getRequestIdentifier,
43
42
  } = require('relay-runtime');
44
- const warning = require('warning');
45
43
 
46
- let RenderDispatcher = null;
47
44
  let fetchKey = 100001;
48
45
 
49
- hook useTrackLoadQueryInRender() {
50
- if (RenderDispatcher === null) {
51
- // Flow does not know of React internals (rightly so), but we need to
52
- // ensure here that this function isn't called inside render.
53
- RenderDispatcher =
54
- // $FlowFixMe[prop-missing]
55
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
56
- ?.ReactCurrentDispatcher?.current;
57
- }
58
- }
59
-
60
46
  type QueryType<T> =
61
47
  T extends Query<infer V, infer D, infer RR>
62
48
  ? {
63
49
  variables: V,
64
50
  response: D,
65
51
  rawResponse?: $NonMaybeType<RR>,
66
- } // $FlowFixMe[deprecated-type]
67
- : $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
52
+ }
53
+ : [+t: T] extends [+t: PreloadableConcreteRequest<infer V>]
54
+ ? V
55
+ : empty;
68
56
 
69
57
  declare function loadQuery<
70
58
  T,
@@ -87,17 +75,6 @@ function loadQuery<
87
75
  options?: ?LoadQueryOptions,
88
76
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
89
77
  ): PreloadedQueryInner<TQuery, TEnvironmentProviderOptions> {
90
- // This code ensures that we don't call loadQuery during render.
91
- const CurrentDispatcher =
92
- // $FlowFixMe[prop-missing]
93
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
94
- ?.ReactCurrentDispatcher?.current;
95
- warning(
96
- RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher,
97
- 'Relay: `%s` should not be called inside a React render function.',
98
- options?.__nameForWarning ?? 'loadQuery',
99
- );
100
-
101
78
  // Every time you call loadQuery, we will generate a new fetchKey.
102
79
  // This will ensure that every query reference that is created and
103
80
  // passed to usePreloadedQuery is independently evaluated,
@@ -407,5 +384,4 @@ function loadQuery<
407
384
 
408
385
  module.exports = {
409
386
  loadQuery,
410
- useTrackLoadQueryInRender,
411
387
  };
@@ -16,13 +16,15 @@ import type {
16
16
  EntryPointComponent,
17
17
  EnvironmentProviderOptions,
18
18
  IEnvironmentProvider,
19
+ PreloadedQuery,
19
20
  } from './EntryPointTypes.flow';
20
21
 
21
22
  const preloadQuery = require('./preloadQuery_DEPRECATED');
22
23
 
23
24
  function prepareEntryPoint<
24
25
  TEntryPointParams: {...},
25
- TPreloadedQueries: {...},
26
+ // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
27
+ TPreloadedQueries: {+[string]: PreloadedQuery<any>},
26
28
  TPreloadedEntryPoints: {...},
27
29
  TRuntimeProps: {...},
28
30
  TExtraProps,
@@ -59,6 +61,7 @@ function prepareEntryPoint<
59
61
  environmentProviderOptions,
60
62
  );
61
63
 
64
+ // $FlowFixMe[incompatible-type]
62
65
  preloadedQueries[queryPropName] = preloadQuery<OperationType, mixed>(
63
66
  environment,
64
67
  parameters,
@@ -17,10 +17,10 @@ import type {
17
17
  EnvironmentProviderOptions,
18
18
  IEnvironmentProvider,
19
19
  PreloadedEntryPoint,
20
+ PreloadedQuery,
20
21
  } from './EntryPointTypes.flow';
21
22
 
22
23
  const loadEntryPoint = require('./loadEntryPoint');
23
- const {useTrackLoadQueryInRender} = require('./loadQuery');
24
24
  const useIsMountedRef = require('./useIsMountedRef');
25
25
  const {useCallback, useEffect, useRef, useState} = require('react');
26
26
 
@@ -52,7 +52,8 @@ const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
52
52
 
53
53
  hook useLoadEntryPoint<
54
54
  TEntryPointParams: {...},
55
- TPreloadedQueries: {...},
55
+ // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
56
+ TPreloadedQueries: {+[string]: PreloadedQuery<any>},
56
57
  TPreloadedEntryPoints: {...},
57
58
  TRuntimeProps: {...},
58
59
  TExtraProps,
@@ -102,8 +103,6 @@ hook useLoadEntryPoint<
102
103
  * entry point references.
103
104
  */
104
105
 
105
- useTrackLoadQueryInRender();
106
-
107
106
  const initialEntryPointReferenceInternal =
108
107
  options?.TEST_ONLY__initialEntryPointData?.entryPointReference ??
109
108
  initialNullEntryPointReferenceState;
@@ -13,7 +13,6 @@
13
13
 
14
14
  import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
15
15
 
16
- const {useTrackLoadQueryInRender} = require('./loadQuery');
17
16
  const useFragmentInternal = require('./useFragmentInternal');
18
17
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
19
18
  const {useDebugValue} = require('react');
@@ -49,10 +48,6 @@ declare hook useFragment<TFragmentType: FragmentType, TData>(
49
48
  ): ?TData;
50
49
 
51
50
  hook useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
52
- // We need to use this hook in order to be able to track if
53
- // loadQuery was called during render
54
- useTrackLoadQueryInRender();
55
-
56
51
  const fragmentNode = getFragment(fragment);
57
52
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
58
53
  const data = useFragmentInternal(fragmentNode, key, 'useFragment()');