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,

0 commit comments

Comments
 (0)