@samitouri / QOS-React / commits / 6b51e037ca

Avoid popping hosts that do not provide unique contexts

Brian Vaughn committed Dec 21, 2016 at 13:38 UTC 6b51e037ca773bd5afd68bb13d5f913ab8e68b3f
3 files changed +15 -7
src/renderers/shared/fiber/ReactFiberBeginWork.js
+1 -1
@@ -633,4 +633,4 @@ module.exports = function<T, P, I, TI, C, CX>(
633 beginFailedWork,
634 };
635
636 -};
\ No newline at end of file
636 +};
src/renderers/shared/fiber/ReactFiberHostContext.js
+13 -5
@@ -44,6 +44,7 @@ module.exports = function<T, P, I, TI, C, CX>(
44 } = config;
45
46 let contextStackCursor : StackCursor<?CX> = createCursor((null: ?CX));
47 + let contextFiberStackCursor : StackCursor<?Fiber> = createCursor((null: ?Fiber));
48 let rootInstanceStackCursor : StackCursor<?C> = createCursor((null: ?C));
49
50 function getRootHostContainer() : C {
@@ -60,13 +61,15 @@ module.exports = function<T, P, I, TI, C, CX>(
61
62 const nextRootContext = getRootHostContext(nextRootInstance);
63
63 - // TODO (bvaughn) Push context-providing Fiber with its own cursor
64 + // Track the context and the Fiber that provided it.
65 + // This enables us to pop only Fibers that provide unique contexts.
66 + push(contextFiberStackCursor, fiber, fiber);
67 push(contextStackCursor, nextRootContext, fiber);
68 }
69
70 function popHostContainer(fiber : Fiber) {
71 pop(contextStackCursor, fiber);
69 - // TODO (bvaughn) Pop context-providing Fiber with its own cursor
72 + pop(contextFiberStackCursor, fiber);
73 pop(rootInstanceStackCursor, fiber);
74 }
75
@@ -87,21 +90,26 @@ module.exports = function<T, P, I, TI, C, CX>(
90 const rootInstance = rootInstanceStackCursor.current;
91 const nextContext = getChildHostContext(context, fiber.type, rootInstance);
92
93 + // Don't push this Fiber's context unless it's unique.
94 if (context === nextContext) {
95 return;
96 }
97
94 - // TODO (bvaughn) Push context-providing Fiber with its own cursor
98 + // Track the context and the Fiber that provided it.
99 + // This enables us to pop only Fibers that provide unique contexts.
100 + push(contextFiberStackCursor, fiber, fiber);
101 push(contextStackCursor, nextContext, fiber);
102 }
103
104 function popHostContext(fiber : Fiber) : void {
99 - if (contextStackCursor.current == null) {
105 + // Do not pop unless this Fiber provided the current context.
106 + // pushHostContext() only pushes Fibers that provide unique contexts.
107 + if (contextFiberStackCursor.current !== fiber) {
108 return;
109 }
110
103 - // TODO (bvaughn) Check context-providing Fiber and only pop if it matches
111 pop(contextStackCursor, fiber);
112 + pop(contextFiberStackCursor, fiber);
113 }
114
115 function resetHostContainer() {
src/renderers/shared/fiber/ReactFiberScheduler.js
+1 -1
@@ -1126,4 +1126,4 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
1126 syncUpdates: syncUpdates,
1127 deferredUpdates: deferredUpdates,
1128 };
1129 -};
\ No newline at end of file
1129 +};