Don't track side-effects unless needed
We don't need to track side-effects for a parent that has never been mounted before. It will simply inject all its children when it completes.
Sebastian Markbage committed
Sep 20, 2016 at 18:12 UTC
3979bb9e247f1da9e906be22857898e28d6ff052
1 file changed
+46
-48
src/renderers/shared/fiber/ReactChildFiber.js
+46
-48
@@ -56,62 +56,60 @@ const {
56
NoWork,
57
} = ReactPriorityLevel;
58
59
+// This wrapper function exists because I expect to clone the code in each path
60
+// to be able to optimize each path individually by branching early. This needs
61
+// a compiler or we can do it manually. Helpers that don't need this branching
62
+// live outside of this function.
63
+function ChildReconciler(shouldClone, shouldTrackSideEffects) {
64
60
-function deleteChild(
61
- returnFiber : Fiber,
62
- childToDelete : Fiber
63
-) {
64
- if (!shouldTrackSideEffects) {
65
- // Noop.
66
- return;
67
- }
65
+ function deleteChild(
66
+ returnFiber : Fiber,
67
+ childToDelete : Fiber
68
+ ) {
69
+ if (!shouldTrackSideEffects) {
70
+ // Noop.
71
+ return;
72
+ }
73
69
- // TODO: Add this child to the side-effect queue for deletion.
70
-}
74
+ // TODO: Add this child to the side-effect queue for deletion.
75
+ }
76
72
-function deleteRemainingChildren(
73
- returnFiber : Fiber,
74
- currentFirstChild : ?Fiber
75
-) {
76
- if (!shouldTrackSideEffects) {
77
- // Noop.
77
+ function deleteRemainingChildren(
78
+ returnFiber : Fiber,
79
+ currentFirstChild : ?Fiber
80
+ ) {
81
+ if (!shouldTrackSideEffects) {
82
+ // Noop.
83
+ return null;
84
+ }
85
+ // TODO: Add these children to the side-effect queue for deletion.
86
return null;
87
}
80
- // TODO: Add these children to the side-effect queue for deletion.
81
- return null;
82
-}
88
84
-function mapAndDeleteRemainingChildren(
85
- returnFiber : Fiber,
86
- currentFirstChild : ?Fiber
87
-) : Map<string, Fiber> {
88
- // Add the remaining children to a temporary map so that we can find them by
89
- // keys quickly. At the same time, we'll flag them all for deletion. However,
90
- // we will then undo the deletion as we restore children. Implicit (null) keys
91
- // don't get added to this set.
92
- const existingChildren : Map<string, Fiber> = new Map();
93
- let existingChild = currentFirstChild;
94
- while (existingChild) {
95
- if (existingChild.key !== null) {
96
- existingChildren.set(existingChild.key, existingChild);
89
+ function mapAndDeleteRemainingChildren(
90
+ returnFiber : Fiber,
91
+ currentFirstChild : ?Fiber
92
+ ) : Map<string, Fiber> {
93
+ // Add the remaining children to a temporary map so that we can find them by
94
+ // keys quickly. At the same time, we'll flag them all for deletion. However,
95
+ // we will then undo the deletion as we restore children. Implicit (null) keys
96
+ // don't get added to this set.
97
+ const existingChildren : Map<string, Fiber> = new Map();
98
+ let existingChild = currentFirstChild;
99
+ while (existingChild) {
100
+ if (existingChild.key !== null) {
101
+ existingChildren.set(existingChild.key, existingChild);
102
+ }
103
+ // Add everything to the delete queue
104
+ // Actually... It is not possible to delete things from the queue since
105
+ // we don't have access to the previous link. Does that mean we need a
106
+ // second pass to add them? We should be able to keep track of the
107
+ // previous deletion as we're iterating through the list the next time.
108
+ // That way we know which item to patch when we delete a deletion.
109
+ existingChild = existingChild.sibling;
110
}
98
- // Add everything to the delete queue
99
- // Actually... It is not possible to delete things from the queue since
100
- // we don't have access to the previous link. Does that mean we need a
101
- // second pass to add them? We should be able to keep track of the
102
- // previous deletion as we're iterating through the list the next time.
103
- // That way we know which item to patch when we delete a deletion.
104
- existingChild = existingChild.sibling;
111
+ return existingChildren;
112
}
106
- return existingChildren;
107
-}
108
-
109
-
110
-// This wrapper function exists because I expect to clone the code in each path
111
-// to be able to optimize each path individually by branching early. This needs
112
-// a compiler or we can do it manually. Helpers that don't need this branching
113
-// live outside of this function.
114
-function ChildReconciler(shouldClone, shouldTrackSideEffects) {
113
114
function useFiber(fiber : Fiber, priority : PriorityLevel) {
115
// We currently set sibling to null and index to 0 here because it is easy