Add Fibers to ReactTreeTraversal
This traverses parent based on the type of internal instance it is passed. If it is a Fiber it may have to traverse multiple steps until it finds a HostComponent. This will allow us to use the event system with Fiber.
Sebastian Markbage committed
Nov 16, 2016 at 15:43 UTC
b3af02a3cdca6865d3bbd3346b7f12afd2a57b0d
4 files changed
+49
-29
scripts/fiber/tests-failing.txt
-18
@@ -11,13 +11,6 @@ src/addons/__tests__/renderSubtreeIntoContainer-test.js
11
* should update context if it changes due to setState
12
* should update context if it changes due to re-render
13
14
-src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
15
-* should clean-up silently after the timeout elapses
16
-* should keep both sets of DOM nodes around
17
-* should switch transitionLeave from false to true
18
-* should transition from one to null
19
-* should transition from false to one
20
-
14
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
15
* should pass previous context to lifecycles
16
@@ -388,17 +381,6 @@ src/renderers/shared/hooks/__tests__/ReactHostOperationHistoryHook-test.js
381
* gets reported when a child is inserted
382
* gets reported when a child is removed
383
391
-src/renderers/shared/shared/__tests__/ReactTreeTraversal-test.js
392
-* should traverse two phase across component boundary
393
-* should traverse two phase at shallowest node
394
-* should traverse enter/leave to sibling - avoids parent
395
-* should traverse enter/leave to parent - avoids parent
396
-* should enter from the window
397
-* should enter from the window to the shallowest
398
-* should leave to the window
399
-* should leave to the window from the shallowest
400
-* should determine the first common ancestor correctly
401
-
384
src/renderers/shared/shared/event/__tests__/EventPluginHub-test.js
385
* should prevent non-function listeners, at dispatch
386
* should not prevent null listeners, at dispatch
scripts/fiber/tests-passing.txt
+14
@@ -75,8 +75,13 @@ src/addons/__tests__/update-test.js
75
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
76
* should warn if timeouts aren't specified
77
* should not warn if timeouts is zero
78
+* should clean-up silently after the timeout elapses
79
+* should keep both sets of DOM nodes around
80
+* should switch transitionLeave from false to true
81
* should work with no children
82
* should work with a null child
83
+* should transition from one to null
84
+* should transition from false to one
85
* should use transition-type specific names when they're provided
86
* should clear transition timeouts when unmounted
87
* should handle unmounted elements properly
@@ -963,8 +968,17 @@ src/renderers/shared/hooks/__tests__/ReactHostOperationHistoryHook-test.js
968
969
src/renderers/shared/shared/__tests__/ReactTreeTraversal-test.js
970
* should not traverse when traversing outside DOM
971
+* should traverse two phase across component boundary
972
+* should traverse two phase at shallowest node
973
* should not traverse when enter/leaving outside DOM
974
* should not traverse if enter/leave the same node
975
+* should traverse enter/leave to sibling - avoids parent
976
+* should traverse enter/leave to parent - avoids parent
977
+* should enter from the window
978
+* should enter from the window to the shallowest
979
+* should leave to the window
980
+* should leave to the window from the shallowest
981
+* should determine the first common ancestor correctly
982
983
src/renderers/shared/shared/event/__tests__/EventPluginRegistry-test.js
984
* should be able to inject ordering before plugins
src/renderers/dom/fiber/ReactDOMFiber.js
+6
@@ -75,6 +75,9 @@ var DOMRenderer = ReactFiberReconciler({
75
typeof props.dangerouslySetInnerHTML.__html === 'string') {
76
domElement.innerHTML = props.dangerouslySetInnerHTML.__html;
77
}
78
+ if (typeof props.id === 'string') {
79
+ domElement.id = props.id;
80
+ }
81
return domElement;
82
},
83
@@ -99,6 +102,9 @@ var DOMRenderer = ReactFiberReconciler({
102
typeof newProps.dangerouslySetInnerHTML.__html === 'string') {
103
domElement.innerHTML = newProps.dangerouslySetInnerHTML.__html;
104
}
105
+ if (typeof newProps.id === 'string') {
106
+ domElement.id = newProps.id;
107
+ }
108
},
109
110
createTextInstance(text : string, internalInstanceHandle : Object) : TextInstance {
src/renderers/shared/shared/ReactTreeTraversal.js
+29
-11
@@ -11,29 +11,47 @@
11
12
'use strict';
13
14
+var { HostComponent } = require('ReactTypeOfWork');
15
+
16
+function getParent(inst) {
17
+ if (inst._hostParent !== undefined) {
18
+ return inst._hostParent;
19
+ }
20
+ if (typeof inst.tag === 'number') {
21
+ do {
22
+ inst = inst.return;
23
+ // TODO: If this is a HostContainer we might want to bail out.
24
+ // That is depending on if we want nested subtrees (layers) to bubble
25
+ // events to their parent.
26
+ } while (inst && inst.tag !== HostComponent);
27
+ return inst;
28
+ }
29
+ return null;
30
+}
31
+
32
/**
33
* Return the lowest common ancestor of A and B, or null if they are in
34
* different trees.
35
*/
36
function getLowestCommonAncestor(instA, instB) {
37
var depthA = 0;
20
- for (var tempA = instA; tempA; tempA = tempA._hostParent) {
38
+ for (var tempA = instA; tempA; tempA = getParent(tempA)) {
39
depthA++;
40
}
41
var depthB = 0;
24
- for (var tempB = instB; tempB; tempB = tempB._hostParent) {
42
+ for (var tempB = instB; tempB; tempB = getParent(tempB)) {
43
depthB++;
44
}
45
46
// If A is deeper, crawl up.
47
while (depthA - depthB > 0) {
30
- instA = instA._hostParent;
48
+ instA = getParent(instA);
49
depthA--;
50
}
51
52
// If B is deeper, crawl up.
53
while (depthB - depthA > 0) {
36
- instB = instB._hostParent;
54
+ instB = getParent(instB);
55
depthB--;
56
}
57
@@ -43,8 +61,8 @@ function getLowestCommonAncestor(instA, instB) {
61
if (instA === instB) {
62
return instA;
63
}
46
- instA = instA._hostParent;
47
- instB = instB._hostParent;
64
+ instA = getParent(instA);
65
+ instB = getParent(instB);
66
}
67
return null;
68
}
@@ -57,7 +75,7 @@ function isAncestor(instA, instB) {
75
if (instB === instA) {
76
return true;
77
}
60
- instB = instB._hostParent;
78
+ instB = getParent(instB);
79
}
80
return false;
81
}
@@ -66,7 +84,7 @@ function isAncestor(instA, instB) {
84
* Return the parent instance of the passed-in instance.
85
*/
86
function getParentInstance(inst) {
69
- return inst._hostParent;
87
+ return getParent(inst);
88
}
89
90
/**
@@ -76,7 +94,7 @@ function traverseTwoPhase(inst, fn, arg) {
94
var path = [];
95
while (inst) {
96
path.push(inst);
79
- inst = inst._hostParent;
97
+ inst = getParent(inst);
98
}
99
var i;
100
for (i = path.length; i-- > 0;) {
@@ -99,12 +117,12 @@ function traverseEnterLeave(from, to, fn, argFrom, argTo) {
117
var pathFrom = [];
118
while (from && from !== common) {
119
pathFrom.push(from);
102
- from = from._hostParent;
120
+ from = getParent(from);
121
}
122
var pathTo = [];
123
while (to && to !== common) {
124
pathTo.push(to);
107
- to = to._hostParent;
125
+ to = getParent(to);
126
}
127
var i;
128
for (i = 0; i < pathFrom.length; i++) {