Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 376d5c1

Browse files
committed
Split cross-package types from implementation
Some of our internal reconciler types have leaked into other packages. Usually, these types are treated as opaque; we don't read and write to its fields. This is good. However, the type is often passed back to a reconciler method. For example, React DOM creates a FiberRoot with `createContainer`, then passes that root to `updateContainer`. It doesn't do anything with the root except pass it through, but because `updateContainer` expects a full FiberRoot, React DOM is still coupled to all its fields. I don't know if there's an idiomatic way to handle this in Flow. Opaque types are simlar, but those only work within a single file. AFAIK, there's no way to use a package as the boundary for opaqueness. The immediate problem this presents is that the reconciler refactor will involve changes to our internal data structures. I don't want to have to fork every single package that happens to pass through a Fiber or FiberRoot, or access any one of its fields. So my current plan is to share the same Flow type across both forks. The shared type will be a superset of each implementation's type, e.g. Fiber will have both an `expirationTime` field and a `lanes` field. The implementations will diverge, but not the types. To do this, I lifted the type definitions into a separate module.
1 parent d686f3f commit 376d5c1

File tree

69 files changed

+490
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+490
-438
lines changed

packages/legacy-events/PluginModuleType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {
1212
DispatchConfig,
1313
ReactSyntheticEvent,

packages/legacy-events/ReactSyntheticEventType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @flow
99
*/
1010

11-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
11+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {EventPriority} from 'shared/ReactTypes';
1313
import type {TopLevelType} from './TopLevelEventTypes';
1414

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import type {
1717
ReactEventResponderListener,
1818
ReactScopeMethods,
1919
} from 'shared/ReactTypes';
20-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
21-
import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
22-
2320
import type {
24-
Hook,
25-
TimeoutConfig,
21+
Fiber,
2622
Dispatcher as DispatcherType,
27-
} from 'react-reconciler/src/ReactFiberHooks.old';
28-
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig.old';
23+
} from 'react-reconciler/src/ReactInternalTypes';
24+
import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
25+
26+
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig';
2927
import {NoMode} from 'react-reconciler/src/ReactTypeOfMode';
3028

3129
import ErrorStackParser from 'error-stack-parser';
@@ -70,6 +68,15 @@ let primitiveStackCache: null | Map<string, Array<any>> = null;
7068

7169
let currentFiber: Fiber | null = null;
7270

71+
type Hook = {
72+
memoizedState: any,
73+
next: Hook | null,
74+
};
75+
76+
type TimeoutConfig = {|
77+
timeoutMs: number,
78+
|};
79+
7380
function getPrimitiveStackCache(): Map<string, Array<any>> {
7481
// This initializes a cache of all primitive hooks so that the top
7582
// most stack frames added by calling the primitive hook can be removed.

packages/react-devtools-shared/src/backend/console.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import {getInternalReactConstants} from './renderer';
1111
import describeComponentFrame from './describeComponentFrame';
1212

13-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
13+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1414
import type {ReactRenderer} from './types';
1515

1616
const APPEND_STACK_TO_METHODS = ['error', 'trace', 'warn'];

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
registerRenderer as registerRendererWithConsole,
5151
} from './console';
5252

53-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
53+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
5454
import type {
5555
ChangeDescription,
5656
CommitDataBackend,

packages/react-devtools-shared/src/backend/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type {ReactContext} from 'shared/ReactTypes';
1111
import type {Source} from 'shared/ReactElementType';
12-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
12+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1313
import type {
1414
ComponentFilter,
1515
ElementType,

packages/react-dom/src/client/ReactDOMComponentTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {
1212
Container,
1313
TextInstance,

packages/react-dom/src/client/ReactDOMRoot.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import type {Container} from './ReactDOMHostConfig';
1111
import type {RootTag} from 'react-reconciler/src/ReactRootTags';
1212
import type {ReactNodeList} from 'shared/ReactTypes';
13-
// TODO: This type is shared between the reconciler and ReactDOM, but will
14-
// eventually be lifted out to the renderer.
15-
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot.old';
13+
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1614
import {findHostInstanceWithNoPortals} from 'react-reconciler/src/ReactFiberReconciler';
1715

1816
export type RootType = {

packages/react-dom/src/events/DOMLegacyEventPluginSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
1111
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1212
import type {ElementListenerMap} from '../events/DOMEventListenerMap';
1313
import type {EventSystemFlags} from './EventSystemFlags';
14-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
14+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1515
import type {PluginModule} from 'legacy-events/PluginModuleType';
1616
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1717
import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';

packages/react-dom/src/events/DOMModernPluginEventSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
} from '../events/DOMEventListenerMap';
1616
import type {EventSystemFlags} from './EventSystemFlags';
1717
import type {EventPriority, ReactScopeMethods} from 'shared/ReactTypes';
18-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
18+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1919
import type {PluginModule} from 'legacy-events/PluginModuleType';
2020
import type {
2121
ReactSyntheticEvent,

packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
flushDiscreteUpdatesIfNeeded,
3232
executeUserEventHandler,
3333
} from './ReactDOMUpdateBatching';
34-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
34+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
3535
import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags';
3636
import invariant from 'shared/invariant';
3737

packages/react-dom/src/events/ReactDOMEventListener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
1111
import type {EventPriority} from 'shared/ReactTypes';
12-
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot.old';
12+
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1313
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1414
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1515

packages/react-dom/src/events/ReactDOMEventReplaying.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1212
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1313
import type {ElementListenerMap} from '../events/DOMEventListenerMap';
1414
import type {EventSystemFlags} from './EventSystemFlags';
15-
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot.old';
15+
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1616

1717
import {
1818
enableDeprecatedFlareAPI,

packages/react-dom/src/events/SimpleEventPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
DOMTopLevelEventType,
1313
} from 'legacy-events/TopLevelEventTypes';
1414
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
15-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
15+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1616
import type {PluginModule} from 'legacy-events/PluginModuleType';
1717
import type {EventSystemFlags} from './EventSystemFlags';
1818

packages/react-dom/src/events/accumulateEnterLeaveListeners.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1212

1313
import {HostComponent} from 'react-reconciler/src/ReactWorkTags';

packages/react-dom/src/events/accumulateEventTargetListeners.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1212
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1313

packages/react-dom/src/events/accumulateTwoPhaseListeners.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1212
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1313

packages/react-dom/src/events/getListener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @flow
77
*/
88

9-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
9+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1010
import type {Props} from '../client/ReactDOMHostConfig';
1111

1212
import invariant from 'shared/invariant';

packages/react-dom/src/server/ReactPartialRendererHooks.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
* @flow
88
*/
99

10-
import type {
11-
Dispatcher as DispatcherType,
12-
TimeoutConfig,
13-
} from 'react-reconciler/src/ReactFiberHooks.old';
10+
import type {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactInternalTypes';
1411
import type {ThreadID} from './ReactThreadIDAllocator';
1512
import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
1613

@@ -21,7 +18,7 @@ import type {
2118
ReactContext,
2219
ReactEventResponderListener,
2320
} from 'shared/ReactTypes';
24-
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig.old';
21+
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig';
2522
import type {ReactDOMListenerMap} from '../shared/ReactDOMTypes';
2623

2724
import {validateContextBounds} from './ReactPartialRendererContext';
@@ -49,6 +46,10 @@ type Hook = {|
4946
next: Hook | null,
5047
|};
5148

49+
type TimeoutConfig = {|
50+
timeoutMs: number,
51+
|};
52+
5253
let currentlyRenderingComponent: Object | null = null;
5354
let firstWorkInProgressHook: Hook | null = null;
5455
let workInProgressHook: Hook | null = null;

packages/react-native-renderer/src/ReactFabricEventEmitter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
11+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {PluginModule} from 'legacy-events/PluginModuleType';
1313
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1414
import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';

packages/react-native-renderer/src/ReactNativeEventEmitter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
11+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {PluginModule} from 'legacy-events/PluginModuleType';
1313
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
1414
import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';

packages/react-native-renderer/src/ReactNativeFiberInspector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
10+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {TouchedViewDataAtPoint, InspectorData} from './ReactNativeTypes';
1212

1313
import {

packages/react-native-renderer/src/ReactNativeGetListener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @flow
77
*/
88

9-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
9+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1010

1111
import invariant from 'shared/invariant';
1212
import {getFiberCurrentPropsFromNode} from 'legacy-events/EventPluginUtils';

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* environment.
1515
*/
1616

17-
import type {Fiber} from 'react-reconciler/src/ReactFiber.old';
17+
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1818
import type {UpdateQueue} from 'react-reconciler/src/ReactUpdateQueue';
1919
import type {ReactNodeList} from 'shared/ReactTypes';
2020
import type {RootTag} from 'react-reconciler/src/ReactRootTags';

packages/react-reconciler/src/ReactCapturedValue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from './ReactFiber.old';
10+
import type {Fiber} from './ReactInternalTypes';
1111

1212
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
1313

packages/react-reconciler/src/ReactChildFiber.old.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import type {ReactElement} from 'shared/ReactElementType';
1111
import type {ReactPortal} from 'shared/ReactTypes';
1212
import type {BlockComponent} from 'react/src/ReactBlock';
1313
import type {LazyComponent} from 'react/src/ReactLazy';
14-
import type {Fiber} from './ReactFiber.old';
15-
import type {ExpirationTime} from './ReactFiberExpirationTime.old';
14+
import type {Fiber} from './ReactInternalTypes';
15+
import type {ExpirationTime} from './ReactFiberExpirationTime';
1616

1717
import getComponentName from 'shared/getComponentName';
1818
import {Placement, Deletion} from './ReactSideEffectTags';

packages/react-reconciler/src/ReactCurrentFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Fiber} from './ReactFiber.old';
10+
import type {Fiber} from './ReactInternalTypes';
1111

1212
import ReactSharedInternals from 'shared/ReactSharedInternals';
1313
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';

0 commit comments

Comments
 (0)