Skip to content

Commit 04ea352

Browse files
committed
Quick fix to the return top level problem
This doesn't deal with the fact that work is usually deferred so this will return null for first render (except in sync tests). It also doesn't deal with top levels being fragments etc. It doesn't deal with the host instance type being a wrapper around the public instance. This needs to be unified with refs and findDOMNode better. However, this does expose that we reactComponentExpect and ReactTestUtils doesn't work very well with Fiber.
1 parent 4132cc4 commit 04ea352

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ var ReactDOM = {
120120

121121
render(element : ReactElement<any>, container : DOMContainerElement) {
122122
warnAboutUnstableUse();
123+
let root;
123124
if (!container._reactRootContainer) {
124-
container._reactRootContainer = DOMRenderer.mountContainer(element, container);
125+
root = container._reactRootContainer = DOMRenderer.mountContainer(element, container);
125126
} else {
126-
DOMRenderer.updateContainer(element, container._reactRootContainer);
127+
DOMRenderer.updateContainer(element, root = container._reactRootContainer);
127128
}
129+
return DOMRenderer.getPublicRootInstance(root);
128130
},
129131

130132
unmountComponentAtNode(container : DOMContainerElement) {

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ export type HostConfig<T, P, I, TI, C> = {
5454

5555
type OpaqueNode = Fiber;
5656

57-
export type Reconciler<C> = {
57+
export type Reconciler<C, I> = {
5858
mountContainer(element : ReactElement<any>, containerInfo : C) : OpaqueNode,
5959
updateContainer(element : ReactElement<any>, container : OpaqueNode) : void,
6060
unmountContainer(container : OpaqueNode) : void,
6161
performWithPriority(priorityLevel : PriorityLevel, fn : Function) : void,
6262

6363
// Used to extract the return value from the initial render. Legacy API.
64-
getPublicRootInstance(container : OpaqueNode) : (C | null),
64+
getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | I | null),
6565
};
6666

67-
module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) : Reconciler<C> {
67+
module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) : Reconciler<C, I> {
6868

6969
var { scheduleWork, performWithPriority } = ReactFiberScheduler(config);
7070

@@ -106,8 +106,13 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) :
106106

107107
performWithPriority,
108108

109-
getPublicRootInstance(container : OpaqueNode) : (C | null) {
110-
return null;
109+
getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | I | null) {
110+
const root : FiberRoot = (container.stateNode : any);
111+
const containerFiber = root.current;
112+
if (!containerFiber.child) {
113+
return null;
114+
}
115+
return containerFiber.child.stateNode;
111116
},
112117

113118
};

0 commit comments

Comments
 (0)