Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ReactFiberStack shared by ReactFiberContext and ReactFiberHostContext #8611

Merged
merged 10 commits into from
Dec 22, 2016
Prev Previous commit
Next Next commit
Avoid popping hosts that do not provide unique contexts
  • Loading branch information
Brian Vaughn committed Dec 21, 2016
commit 6b51e037ca773bd5afd68bb13d5f913ab8e68b3f
2 changes: 1 addition & 1 deletion src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,4 @@ module.exports = function<T, P, I, TI, C, CX>(
beginFailedWork,
};

};
};
18 changes: 13 additions & 5 deletions src/renderers/shared/fiber/ReactFiberHostContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function<T, P, I, TI, C, CX>(
} = config;

let contextStackCursor : StackCursor<?CX> = createCursor((null: ?CX));
let contextFiberStackCursor : StackCursor<?Fiber> = createCursor((null: ?Fiber));
let rootInstanceStackCursor : StackCursor<?C> = createCursor((null: ?C));

function getRootHostContainer() : C {
Expand All @@ -60,13 +61,15 @@ module.exports = function<T, P, I, TI, C, CX>(

const nextRootContext = getRootHostContext(nextRootInstance);

// TODO (bvaughn) Push context-providing Fiber with its own cursor
// Track the context and the Fiber that provided it.
// This enables us to pop only Fibers that provide unique contexts.
push(contextFiberStackCursor, fiber, fiber);
push(contextStackCursor, nextRootContext, fiber);
}

function popHostContainer(fiber : Fiber) {
pop(contextStackCursor, fiber);
// TODO (bvaughn) Pop context-providing Fiber with its own cursor
pop(contextFiberStackCursor, fiber);
pop(rootInstanceStackCursor, fiber);
}

Expand All @@ -87,21 +90,26 @@ module.exports = function<T, P, I, TI, C, CX>(
const rootInstance = rootInstanceStackCursor.current;
const nextContext = getChildHostContext(context, fiber.type, rootInstance);

// Don't push this Fiber's context unless it's unique.
if (context === nextContext) {
return;
}

// TODO (bvaughn) Push context-providing Fiber with its own cursor
// Track the context and the Fiber that provided it.
// This enables us to pop only Fibers that provide unique contexts.
push(contextFiberStackCursor, fiber, fiber);
push(contextStackCursor, nextContext, fiber);
}

function popHostContext(fiber : Fiber) : void {
if (contextStackCursor.current == null) {
// Do not pop unless this Fiber provided the current context.
// pushHostContext() only pushes Fibers that provide unique contexts.
if (contextFiberStackCursor.current !== fiber) {
return;
}

// TODO (bvaughn) Check context-providing Fiber and only pop if it matches
pop(contextStackCursor, fiber);
pop(contextFiberStackCursor, fiber);
}

function resetHostContainer() {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,4 +1126,4 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
syncUpdates: syncUpdates,
deferredUpdates: deferredUpdates,
};
};
};