@samitouri / QOS-React / commits / e05f0a3a13

Only expose FiberRoot at the top level instead of a Fiber (#8934)

It is strange to get a handle on the Fiber since it is one of possibly two root Fibers. The correct way to get the current Fiber is through the root.current. I exposed the Fiber originally because I thought we might use it for Portals but we went with a different approach. So we don't need this.

Sebastian Markbåge committed Feb 6, 2017 at 13:19 UTC e05f0a3a13686c78b556199d725124d54fb711aa
2 files changed +22 -29
src/renderers/noop/ReactNoop.js
+1 -1
@@ -362,7 +362,7 @@ var ReactNoop = {
362 log('HOST INSTANCES:');
363 logContainer(rootContainer, 0);
364 log('FIBERS:');
365 - logFiber((root.stateNode : any).current, 0);
365 + logFiber(root.current, 0);
366
367 console.log(...bufferedLog);
368 },
src/renderers/shared/fiber/ReactFiberReconciler.js
+21 -28
@@ -41,7 +41,8 @@ export type Deadline = {
41 timeRemaining : () => number
42 };
43
44 -type OpaqueNode = Fiber;
44 +type OpaqueHandle = Fiber;
45 +type OpaqueRoot = FiberRoot;
46
47 export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
48
@@ -54,7 +55,7 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
55 props : P,
56 rootContainerInstance : C,
57 hostContext : CX,
57 - internalInstanceHandle : OpaqueNode
58 + internalInstanceHandle : OpaqueHandle
59 ) : I,
60 appendInitialChild(parentInstance : I, child : I | TI) : void,
61 finalizeInitialChildren(parentInstance : I, type : T, props : P, rootContainerInstance : C) : boolean,
@@ -73,9 +74,9 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
74 type : T,
75 oldProps : P,
76 newProps : P,
76 - internalInstanceHandle : OpaqueNode
77 + internalInstanceHandle : OpaqueHandle
78 ) : void,
78 - commitMount(instance : I, type : T, newProps : P, internalInstanceHandle : OpaqueNode) : void,
79 + commitMount(instance : I, type : T, newProps : P, internalInstanceHandle : OpaqueHandle) : void,
80
81 shouldSetTextContent(props : P) : boolean,
82 resetTextContent(instance : I) : void,
@@ -84,7 +85,7 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
85 text : string,
86 rootContainerInstance : C,
87 hostContext : CX,
87 - internalInstanceHandle : OpaqueNode
88 + internalInstanceHandle : OpaqueHandle
89 ) : TI,
90 commitTextUpdate(textInstance : TI, oldText : string, newText : string) : void,
91
@@ -102,10 +103,10 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
103 };
104
105 export type Reconciler<C, I, TI> = {
105 - createContainer(containerInfo : C) : OpaqueNode,
106 + createContainer(containerInfo : C) : OpaqueRoot,
107 updateContainer(
108 element : ReactNodeList,
108 - container : OpaqueNode,
109 + container : OpaqueRoot,
110 parentComponent : ?ReactComponent<any, any, any>
111 ) : void,
112 performWithPriority(priorityLevel : PriorityLevel, fn : Function) : void,
@@ -115,7 +116,7 @@ export type Reconciler<C, I, TI> = {
116 deferredUpdates<A>(fn : () => A) : A,
117
118 // Used to extract the return value from the initial render. Legacy API.
118 - getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | TI | I | null),
119 + getPublicRootInstance(container : OpaqueRoot) : (ReactComponent<any, any, any> | TI | I | null),
120
121 // Use for findDOMNode/findHostNode. Legacy API.
122 findHostInstance(component : Fiber) : I | TI | null,
@@ -150,43 +151,36 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
151
152 return {
153
153 - createContainer(containerInfo : C) : OpaqueNode {
154 - const root = createFiberRoot(containerInfo);
155 - const current = root.current;
156 -
157 - // It may seem strange that we don't return the root here, but that will
158 - // allow us to have containers that are in the middle of the tree instead
159 - // of being roots.
160 - return current;
154 + createContainer(containerInfo : C) : OpaqueRoot {
155 + return createFiberRoot(containerInfo);
156 },
157
158 updateContainer(
159 element : ReactNodeList,
165 - container : OpaqueNode,
160 + container : OpaqueRoot,
161 parentComponent : ?ReactComponent<any, any, any>,
162 callback: ?Function
163 ) : void {
164 // TODO: If this is a nested container, this won't be the root.
170 - const root : FiberRoot = (container.stateNode : any);
171 - const current = root.current;
165 + const current = container.current;
166
167 if (__DEV__) {
168 if (ReactFiberInstrumentation.debugTool) {
169 if (current.alternate === null) {
176 - ReactFiberInstrumentation.debugTool.onMountContainer(root);
170 + ReactFiberInstrumentation.debugTool.onMountContainer(container);
171 } else if (element === null) {
178 - ReactFiberInstrumentation.debugTool.onUnmountContainer(root);
172 + ReactFiberInstrumentation.debugTool.onUnmountContainer(container);
173 } else {
180 - ReactFiberInstrumentation.debugTool.onUpdateContainer(root);
174 + ReactFiberInstrumentation.debugTool.onUpdateContainer(container);
175 }
176 }
177 }
178
179 const context = getContextForSubtree(parentComponent);
186 - if (root.context === null) {
187 - root.context = context;
180 + if (container.context === null) {
181 + container.context = context;
182 } else {
189 - root.pendingContext = context;
183 + container.pendingContext = context;
184 }
185
186 scheduleTopLevelUpdate(current, element, callback);
@@ -202,9 +196,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
196
197 deferredUpdates,
198
205 - getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | I | TI | null) {
206 - const root : FiberRoot = (container.stateNode : any);
207 - const containerFiber = root.current;
199 + getPublicRootInstance(container : OpaqueRoot) : (ReactComponent<any, any, any> | I | TI | null) {
200 + const containerFiber = container.current;
201 if (!containerFiber.child) {
202 return null;
203 }