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.
Sebastian Markbage committed
Oct 20, 2016 at 21:01 UTC
6e7c89ed8ac705522a051c5ebe55c0f6f4dc33d5
2 files changed
+14
-7
src/renderers/dom/fiber/ReactDOMFiber.js
+4
-2
@@ -120,11 +120,13 @@ var ReactDOM = {
120
121
render(element : ReactElement<any>, container : DOMContainerElement) {
122
warnAboutUnstableUse();
123
+ let root;
124
if (!container._reactRootContainer) {
124
- container._reactRootContainer = DOMRenderer.mountContainer(element, container);
125
+ root = container._reactRootContainer = DOMRenderer.mountContainer(element, container);
126
} else {
126
- DOMRenderer.updateContainer(element, container._reactRootContainer);
127
+ DOMRenderer.updateContainer(element, root = container._reactRootContainer);
128
}
129
+ return DOMRenderer.getPublicRootInstance(root);
130
},
131
132
unmountComponentAtNode(container : DOMContainerElement) {
src/renderers/shared/fiber/ReactFiberReconciler.js
+10
-5
@@ -54,17 +54,17 @@ export type HostConfig<T, P, I, TI, C> = {
54
55
type OpaqueNode = Fiber;
56
57
-export type Reconciler<C> = {
57
+export type Reconciler<C, I> = {
58
mountContainer(element : ReactElement<any>, containerInfo : C) : OpaqueNode,
59
updateContainer(element : ReactElement<any>, container : OpaqueNode) : void,
60
unmountContainer(container : OpaqueNode) : void,
61
performWithPriority(priorityLevel : PriorityLevel, fn : Function) : void,
62
63
// 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),
65
};
66
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> {
68
69
var { scheduleWork, performWithPriority } = ReactFiberScheduler(config);
70
@@ -106,8 +106,13 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) :
106
107
performWithPriority,
108
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;
116
},
117
118
};