Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 82 additions & 86 deletions src/renderers/shared/fiber/ReactChildFiber.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/renderers/shared/fiber/ReactDebugCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (__DEV__) {
function getCurrentFiberOwnerName() : string | null {
if (__DEV__) {
const fiber = ReactDebugCurrentFiber.current;
if (fiber == null) {
if (fiber === null) {
return null;
}
if (fiber._debugOwner != null) {
Expand All @@ -35,7 +35,7 @@ function getCurrentFiberOwnerName() : string | null {
function getCurrentFiberStackAddendum() : string | null {
if (__DEV__) {
const fiber = ReactDebugCurrentFiber.current;
if (fiber == null) {
if (fiber === null) {
return null;
}
// Safe because if current fiber exists, we are reconciling,
Expand Down
22 changes: 11 additions & 11 deletions src/renderers/shared/fiber/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export type Fiber = {
// This is effectively the parent, but there can be multiple parents (two)
// so this is only the parent of the thing we're currently processing.
// It is conceptually the same as the return address of a stack frame.
return: ?Fiber,
return: Fiber | null,

// Singly Linked List Tree Structure.
child: ?Fiber,
sibling: ?Fiber,
child: Fiber | null,
sibling: Fiber | null,
index: number,

// The ref last used to attach this node.
Expand All @@ -119,13 +119,13 @@ export type Fiber = {
effectTag: TypeOfSideEffect,

// Singly linked list fast path to the next fiber with side-effects.
nextEffect: ?Fiber,
nextEffect: Fiber | null,

// The first and last fiber with side-effect within this subtree. This allows
// us to reuse a slice of the linked list when we reuse the work done within
// this fiber.
firstEffect: ?Fiber,
lastEffect: ?Fiber,
firstEffect: Fiber | null,
lastEffect: Fiber | null,

// This will be used to quickly determine if a subtree has no pending changes.
pendingWorkPriority: PriorityLevel,
Expand All @@ -139,19 +139,19 @@ export type Fiber = {
// priority, then we need to store the progressed work somewhere. This holds
// the started child set until we need to get back to working on it. It may
// or may not be the same as the "current" child.
progressedChild: ?Fiber,
progressedChild: Fiber | null,

// When we reconcile children onto progressedChild it is possible that we have
// to delete some child fibers. We need to keep track of this side-effects so
// that if we continue later on, we have to include those effects. Deletions
// are added in the reverse order from sibling pointers.
progressedFirstDeletion: ?Fiber,
progressedLastDeletion: ?Fiber,
progressedFirstDeletion: Fiber | null,
progressedLastDeletion: Fiber | null,

// This is a pooled version of a Fiber. Every fiber that gets updated will
// eventually have a pair. There are cases when we can clean up pairs to save
// memory if we need to.
alternate: ?Fiber,
alternate: Fiber | null,

// Conceptual aliases
// workInProgress : Fiber -> alternate The alternate used for reuse happens
Expand Down Expand Up @@ -249,7 +249,7 @@ exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fi
// objects for things that are never updated. It also allow us to reclaim the
// extra memory if needed.
let alt = fiber.alternate;
if (alt) {
if (alt !== null) {
// If we clone, then we do so from the "current" state. The current state
// can't have any side-effects that are still valid so we reset just to be
// sure.
Expand Down
44 changes: 22 additions & 22 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// We now have clones. Let's store them as the currently progressed work.
workInProgress.progressedChild = workInProgress.child;
workInProgress.progressedPriority = priorityLevel;
if (current) {
if (current !== null) {
// We also store it on the current. When the alternate swaps in we can
// continue from this point.
current.progressedChild = workInProgress.progressedChild;
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// At this point any memoization is no longer valid since we'll have changed
// the children.
workInProgress.memoizedProps = null;
if (!current) {
if (current === null) {
// If this is a fresh new component that hasn't been rendered yet, we
// won't update its child set by applying minimal side-effects. Instead,
// we will add them all to the child before it gets rendered. That means
Expand Down Expand Up @@ -191,9 +191,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return workInProgress.child;
}

function markRef(current : ?Fiber, workInProgress : Fiber) {
function markRef(current : Fiber | null, workInProgress : Fiber) {
const ref = workInProgress.ref;
if (ref && (!current || current.ref !== ref)) {
if (ref !== null && (!current || current.ref !== ref)) {
// Schedule a Ref effect
workInProgress.effectTag |= Ref;
}
Expand All @@ -211,7 +211,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
nextProps = memoizedProps;
}
} else {
if (nextProps == null || memoizedProps === nextProps) {
if (nextProps === null || memoizedProps === nextProps) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}
// TODO: Disable this before release, since it is not part of the public API
Expand Down Expand Up @@ -240,14 +240,14 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return workInProgress.child;
}

function updateClassComponent(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) {
function updateClassComponent(current : Fiber | null, workInProgress : Fiber, priorityLevel : PriorityLevel) {
// Push context providers early to prevent context stack mismatches.
// During mounting we don't know the child context yet as the instance doesn't exist.
// We will invalidate the child context in finishClassComponent() right after rendering.
const hasContext = pushContextProvider(workInProgress);

let shouldUpdate;
if (!current) {
if (current === null) {
if (!workInProgress.stateNode) {
// In the initial pass we might need to construct the instance.
constructClassInstance(workInProgress);
Expand All @@ -264,7 +264,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}

function finishClassComponent(
current : ?Fiber,
current : Fiber | null,
workInProgress : Fiber,
shouldUpdate : boolean,
hasContext : boolean,
Expand Down Expand Up @@ -314,7 +314,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
pushHostContainer(workInProgress, root.containerInfo);

const updateQueue = workInProgress.updateQueue;
if (updateQueue) {
if (updateQueue !== null) {
const prevState = workInProgress.memoizedState;
const state = beginUpdateQueue(workInProgress, updateQueue, null, prevState, null, priorityLevel);
if (prevState === state) {
Expand All @@ -335,7 +335,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
pushHostContext(workInProgress);

let nextProps = workInProgress.pendingProps;
const prevProps = current ? current.memoizedProps : null;
const prevProps = current !== null ? current.memoizedProps : null;
const memoizedProps = workInProgress.memoizedProps;
if (hasContextChanged()) {
// Normally we can bail out on props equality but if context has changed
Expand All @@ -359,7 +359,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// that is a bit tricky since workInProgress and current can have
// different "hidden" settings.
let child = workInProgress.progressedChild;
while (child) {
while (child !== null) {
// To ensure that this subtree gets its priority reset, the children
// need to be reset.
child.pendingWorkPriority = OffscreenPriority;
Expand Down Expand Up @@ -409,16 +409,16 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// Reconcile the children and stash them for later work.
reconcileChildrenAtPriority(current, workInProgress, nextChildren, OffscreenPriority);
memoizeProps(workInProgress, nextProps);
workInProgress.child = current ? current.child : null;
workInProgress.child = current !== null ? current.child : null;

if (!current) {
if (current === null) {
// If this doesn't have a current we won't track it for placement
// effects. However, when we come back around to this we have already
// inserted the parent which means that we'll infact need to make this a
// placement.
// TODO: There has to be a better solution to this problem.
let child = workInProgress.progressedChild;
while (child) {
while (child !== null) {
child.effectTag = Placement;
child = child.sibling;
}
Expand Down Expand Up @@ -464,7 +464,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
value = fn(props, context);
}

if (typeof value === 'object' && value && typeof value.render === 'function') {
if (typeof value === 'object' && value !== null && typeof value.render === 'function') {
// Proceed under the assumption that this is a class instance
workInProgress.tag = ClassComponent;

Expand All @@ -479,7 +479,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// Proceed under the assumption that this is a functional component
workInProgress.tag = FunctionalComponent;
if (__DEV__) {
if (workInProgress.ref != null) {
if (workInProgress.ref !== null) {
let info = '';
const ownerName = ReactDebugCurrentFiber.getCurrentFiberOwnerName();
if (ownerName) {
Expand Down Expand Up @@ -517,7 +517,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
if (nextCoroutine === null) {
nextCoroutine = current && current.memoizedProps;
invariant(
nextCoroutine != null,
nextCoroutine !== null,
'We should always have pending or current props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
Expand All @@ -538,7 +538,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// At this point any memoization is no longer valid since we'll have changed
// the children.
workInProgress.memoizedProps = null;
if (!current) {
if (current === null) {
workInProgress.stateNode = mountChildFibersInPlace(
workInProgress,
workInProgress.stateNode,
Expand Down Expand Up @@ -592,7 +592,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}

if (!current) {
if (current === null) {
// Portals are special because we don't append the children during mount
// but at commit. Therefore we need to track insertions which the normal
// flow doesn't do during mount. This doesn't happen at the root because
Expand Down Expand Up @@ -632,7 +632,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
*/

function bailoutOnAlreadyFinishedWork(current, workInProgress : Fiber) : ?Fiber {
function bailoutOnAlreadyFinishedWork(current, workInProgress : Fiber) : Fiber | null {
const priorityLevel = workInProgress.pendingWorkPriority;
// TODO: We should ideally be able to bail out early if the children have no
// more work to do. However, since we don't have a separation of this
Expand Down Expand Up @@ -687,7 +687,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// is handled by beginUpdateQueue.
}

function beginWork(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) : ?Fiber {
function beginWork(current : Fiber | null, workInProgress : Fiber, priorityLevel : PriorityLevel) : Fiber | null {
if (workInProgress.pendingWorkPriority === NoWork ||
workInProgress.pendingWorkPriority > priorityLevel) {
return bailoutOnLowPriority(current, workInProgress);
Expand Down Expand Up @@ -744,7 +744,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

function beginFailedWork(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) {
function beginFailedWork(current : Fiber | null, workInProgress : Fiber, priorityLevel : PriorityLevel) {
invariant(
workInProgress.tag === ClassComponent ||
workInProgress.tag === HostRoot,
Expand Down
14 changes: 7 additions & 7 deletions src/renderers/shared/fiber/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function(
};

function checkShouldComponentUpdate(workInProgress, oldProps, newProps, oldState, newState, newContext) {
if (oldProps === null || (workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate)) {
if (oldProps === null || (workInProgress.updateQueue !== null && workInProgress.updateQueue.hasForceUpdate)) {
// If the workInProgress already has an Update effect, return true
return true;
}
Expand Down Expand Up @@ -208,10 +208,10 @@ module.exports = function(
workInProgress.effectTag |= Update;
}

function markUpdateIfAlreadyInProgress(current: ?Fiber, workInProgress : Fiber) {
function markUpdateIfAlreadyInProgress(current: Fiber | null, workInProgress : Fiber) {
// If an update was already in progress, we should schedule an Update
// effect even though we're bailing out, so that cWU/cDU are called.
if (current) {
if (current !== null) {
if (workInProgress.memoizedProps !== current.memoizedProps ||
workInProgress.memoizedState !== current.memoizedState) {
markUpdate(workInProgress);
Expand Down Expand Up @@ -274,7 +274,7 @@ module.exports = function(
// If we had additional state updates during this life-cycle, let's
// process them now.
const updateQueue = workInProgress.updateQueue;
if (updateQueue) {
if (updateQueue !== null) {
instance.state = beginUpdateQueue(
workInProgress,
updateQueue,
Expand Down Expand Up @@ -343,7 +343,7 @@ module.exports = function(
// They may be from componentWillMount() or from error boundary's setState()
// during initial mounting.
const newUpdateQueue = workInProgress.updateQueue;
if (newUpdateQueue) {
if (newUpdateQueue !== null) {
newInstance.state = beginUpdateQueue(
workInProgress,
newUpdateQueue,
Expand Down Expand Up @@ -392,7 +392,7 @@ module.exports = function(
const oldState = workInProgress.memoizedState;
// TODO: Previous state can be null.
let newState;
if (updateQueue) {
if (updateQueue !== null) {
newState = beginUpdateQueue(
workInProgress,
updateQueue,
Expand All @@ -408,7 +408,7 @@ module.exports = function(
if (oldProps === newProps &&
oldState === newState &&
!hasContextChanged() &&
!(updateQueue && updateQueue.hasForceUpdate)) {
!(updateQueue !== null && updateQueue.hasForceUpdate)) {
markUpdateIfAlreadyInProgress(current, workInProgress);
return false;
}
Expand Down
Loading