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.
This commit is contained in:
Sebastian Markbage 2016-10-20 21:01:16 -07:00
parent 9b1b40ca93
commit 6e7c89ed8a
2 changed files with 14 additions and 7 deletions

View File

@ -120,11 +120,13 @@ var ReactDOM = {
render(element : ReactElement<any>, container : DOMContainerElement) {
warnAboutUnstableUse();
let root;
if (!container._reactRootContainer) {
container._reactRootContainer = DOMRenderer.mountContainer(element, container);
root = container._reactRootContainer = DOMRenderer.mountContainer(element, container);
} else {
DOMRenderer.updateContainer(element, container._reactRootContainer);
DOMRenderer.updateContainer(element, root = container._reactRootContainer);
}
return DOMRenderer.getPublicRootInstance(root);
},
unmountComponentAtNode(container : DOMContainerElement) {

View File

@ -54,17 +54,17 @@ export type HostConfig<T, P, I, TI, C> = {
type OpaqueNode = Fiber;
export type Reconciler<C> = {
export type Reconciler<C, I> = {
mountContainer(element : ReactElement<any>, containerInfo : C) : OpaqueNode,
updateContainer(element : ReactElement<any>, container : OpaqueNode) : void,
unmountContainer(container : OpaqueNode) : void,
performWithPriority(priorityLevel : PriorityLevel, fn : Function) : void,
// Used to extract the return value from the initial render. Legacy API.
getPublicRootInstance(container : OpaqueNode) : (C | null),
getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | I | null),
};
module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) : Reconciler<C> {
module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) : Reconciler<C, I> {
var { scheduleWork, performWithPriority } = ReactFiberScheduler(config);
@ -106,8 +106,13 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) :
performWithPriority,
getPublicRootInstance(container : OpaqueNode) : (C | null) {
return null;
getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | I | null) {
const root : FiberRoot = (container.stateNode : any);
const containerFiber = root.current;
if (!containerFiber.child) {
return null;
}
return containerFiber.child.stateNode;
},
};