diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index 94b2c2f8c6..6caea831b3 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -36,11 +36,11 @@ if (__DEV__) { var checkReactTypeSpec = require('checkReactTypeSpec'); } -let contextStackCursor : StackCursor = createCursor(); -let didPerformWorkStackCursor : StackCursor = createCursor(); +let contextStackCursor : StackCursor = createCursor((null: ?Object)); +let didPerformWorkStackCursor : StackCursor = createCursor((null: ?boolean)); function getUnmaskedContext() { - return contextStackCursor.current; + return contextStackCursor.current || emptyObject; } exports.getMaskedContext = function(workInProgress : Fiber) { @@ -52,6 +52,7 @@ exports.getMaskedContext = function(workInProgress : Fiber) { const unmaskedContext = getUnmaskedContext(); const context = {}; + for (let key in contextTypes) { context[key] = unmaskedContext[key]; } diff --git a/src/renderers/shared/fiber/ReactFiberHostContext.js b/src/renderers/shared/fiber/ReactFiberHostContext.js index 9effc291d4..8997d33e0f 100644 --- a/src/renderers/shared/fiber/ReactFiberHostContext.js +++ b/src/renderers/shared/fiber/ReactFiberHostContext.js @@ -16,6 +16,8 @@ import type { Fiber } from 'ReactFiber'; import type { HostConfig } from 'ReactFiberReconciler'; import type { StackCursor } from 'ReactFiberStack'; +const emptyObject = require('emptyObject'); + const { createCursor, pop, @@ -41,8 +43,8 @@ module.exports = function( getRootHostContext, } = config; - let contextStackCursor : StackCursor = createCursor(); - let rootInstanceStackCursor : StackCursor = createCursor(); + let contextStackCursor : StackCursor = createCursor((null: ?CX)); + let rootInstanceStackCursor : StackCursor = createCursor((null: ?C)); function getRootHostContainer() : C { if (rootInstanceStackCursor.current == null) { @@ -81,7 +83,7 @@ module.exports = function( throw new Error('Expected root host context to exist.'); } - const context = contextStackCursor.current; + const context = contextStackCursor.current || emptyObject; const rootInstance = rootInstanceStackCursor.current; const nextContext = getChildHostContext(context, fiber.type, rootInstance); diff --git a/src/renderers/shared/fiber/ReactFiberStack.js b/src/renderers/shared/fiber/ReactFiberStack.js index 9f7b98bee8..f4e11e0e0f 100644 --- a/src/renderers/shared/fiber/ReactFiberStack.js +++ b/src/renderers/shared/fiber/ReactFiberStack.js @@ -14,14 +14,13 @@ import type { Fiber } from 'ReactFiber'; -export type StackCursor = {| - current: any +export type StackCursor = {| + current: T |}; -const emptyObject = require('emptyObject'); const warning = require('warning'); -const valueStack : Array = []; +const valueStack : Array = []; if (__DEV__) { var fiberStack : Array = []; @@ -29,9 +28,9 @@ if (__DEV__) { let index = -1; -exports.createCursor = function() : StackCursor { +exports.createCursor = function(defaultValue : T) : StackCursor { return { - current: null, + current: defaultValue, }; }; @@ -39,8 +38,8 @@ exports.isEmpty = function() : boolean { return index === -1; }; -exports.pop = function( - cursor : StackCursor, +exports.pop = function( + cursor : StackCursor, fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber ) : void { if (index < 0) { @@ -56,21 +55,21 @@ exports.pop = function( } } - valueStack[index] = emptyObject; + valueStack[index] = null; if (__DEV__) { - fiberStack[index] = emptyObject; + fiberStack[index] = null; } index--; cursor.current = index > -1 ? valueStack[index] - : null; + : (null : any); }; -exports.push = function( - cursor : StackCursor, +exports.push = function( + cursor : StackCursor, value : any, fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber ) : void { @@ -85,18 +84,18 @@ exports.push = function( } }; -exports.reset = function( - cursor : StackCursor, +exports.reset = function( + cursor : StackCursor, ) : void { while (index > -1) { - valueStack[index] = emptyObject; + valueStack[index] = null; if (__DEV__) { - fiberStack[index] = emptyObject; + fiberStack[index] = null; } index--; } - cursor.current = null; + cursor.current = (null : any); };