@samitouri / QOS-React-2 / commits / c739cef2fc

Flow: ReactFiberHotReloading recursive type (#25225)

Jan Kassens committed Sep 12, 2022 at 10:25 UTC c739cef2fc628e50ffbb71d9f91f12c4e8e8cf36
3 files changed +45 -55
packages/react-reconciler/src/ReactFiberHotReloading.js
+25 -9
@@ -7,16 +7,11 @@
7 * @flow
8 */
9
10 -import {enableNewReconciler} from 'shared/ReactFeatureFlags';
10 +import type {Instance} from './ReactFiberHostConfig';
11 +import type {FiberRoot} from './ReactInternalTypes';
12 +import type {ReactNodeList} from 'shared/ReactTypes';
13
12 -export type {
13 - Family,
14 - RefreshUpdate,
15 - SetRefreshHandler,
16 - ScheduleRefresh,
17 - ScheduleRoot,
18 - FindHostInstancesForRefresh,
19 -} from './ReactFiberHotReloading';
14 +import {enableNewReconciler} from 'shared/ReactFeatureFlags';
15
16 import {
17 setRefreshHandler as setRefreshHandler_old,
@@ -42,6 +37,27 @@ import {
37 findHostInstancesForRefresh as findHostInstancesForRefresh_new,
38 } from './ReactFiberHotReloading.new';
39
40 +export type Family = {
41 + current: any,
42 +};
43 +
44 +export type RefreshUpdate = {
45 + staleFamilies: Set<Family>,
46 + updatedFamilies: Set<Family>,
47 +};
48 +
49 +// Resolves type to a family.
50 +export type RefreshHandler = any => Family | void;
51 +
52 +// Used by React Refresh runtime through DevTools Global Hook.
53 +export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
54 +export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
55 +export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
56 +export type FindHostInstancesForRefresh = (
57 + root: FiberRoot,
58 + families: Array<Family>,
59 +) => Set<Instance>;
60 +
61 export const setRefreshHandler = enableNewReconciler
62 ? setRefreshHandler_new
63 : setRefreshHandler_old;
packages/react-reconciler/src/ReactFiberHotReloading.new.js
+10 -23
@@ -10,11 +10,19 @@
10 /* eslint-disable react-internal/prod-error-codes */
11
12 import type {ReactElement} from 'shared/ReactElementType';
13 -import type {Fiber} from './ReactInternalTypes';
14 -import type {FiberRoot} from './ReactInternalTypes';
13 +import type {Fiber, FiberRoot} from './ReactInternalTypes';
14 import type {Instance} from './ReactFiberHostConfig';
15 import type {ReactNodeList} from 'shared/ReactTypes';
16
17 +import type {
18 + Family,
19 + FindHostInstancesForRefresh,
20 + RefreshHandler,
21 + RefreshUpdate,
22 + ScheduleRefresh,
23 + ScheduleRoot,
24 +} from './ReactFiberHotReloading';
25 +
26 import {
27 flushSync,
28 scheduleUpdateOnFiber,
@@ -40,27 +48,6 @@ import {
48 REACT_LAZY_TYPE,
49 } from 'shared/ReactSymbols';
50
43 -export type Family = {
44 - current: any,
45 -};
46 -
47 -export type RefreshUpdate = {
48 - staleFamilies: Set<Family>,
49 - updatedFamilies: Set<Family>,
50 -};
51 -
52 -// Resolves type to a family.
53 -type RefreshHandler = any => Family | void;
54 -
55 -// Used by React Refresh runtime through DevTools Global Hook.
56 -export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
57 -export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
58 -export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
59 -export type FindHostInstancesForRefresh = (
60 - root: FiberRoot,
61 - families: Array<Family>,
62 -) => Set<Instance>;
63 -
51 let resolveFamily: RefreshHandler | null = null;
52 // $FlowFixMe Flow gets confused by a WeakSet feature check below.
53 let failedBoundaries: WeakSet<Fiber> | null = null;
packages/react-reconciler/src/ReactFiberHotReloading.old.js
+10 -23
@@ -10,11 +10,19 @@
10 /* eslint-disable react-internal/prod-error-codes */
11
12 import type {ReactElement} from 'shared/ReactElementType';
13 -import type {Fiber} from './ReactInternalTypes';
14 -import type {FiberRoot} from './ReactInternalTypes';
13 +import type {Fiber, FiberRoot} from './ReactInternalTypes';
14 import type {Instance} from './ReactFiberHostConfig';
15 import type {ReactNodeList} from 'shared/ReactTypes';
16
17 +import type {
18 + Family,
19 + FindHostInstancesForRefresh,
20 + RefreshHandler,
21 + RefreshUpdate,
22 + ScheduleRefresh,
23 + ScheduleRoot,
24 +} from './ReactFiberHotReloading';
25 +
26 import {
27 flushSync,
28 scheduleUpdateOnFiber,
@@ -40,27 +48,6 @@ import {
48 REACT_LAZY_TYPE,
49 } from 'shared/ReactSymbols';
50
43 -export type Family = {
44 - current: any,
45 -};
46 -
47 -export type RefreshUpdate = {
48 - staleFamilies: Set<Family>,
49 - updatedFamilies: Set<Family>,
50 -};
51 -
52 -// Resolves type to a family.
53 -type RefreshHandler = any => Family | void;
54 -
55 -// Used by React Refresh runtime through DevTools Global Hook.
56 -export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
57 -export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
58 -export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
59 -export type FindHostInstancesForRefresh = (
60 - root: FiberRoot,
61 - families: Array<Family>,
62 -) => Set<Instance>;
63 -
51 let resolveFamily: RefreshHandler | null = null;
52 // $FlowFixMe Flow gets confused by a WeakSet feature check below.
53 let failedBoundaries: WeakSet<Fiber> | null = null;