Skip to content

Commit 1841e1c

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. 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 1841e1c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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> | 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)