Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/isomorphic/hooks/ReactComponentTreeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ var ReactComponentTreeHook = {

var currentOwner = ReactCurrentOwner.current;
if (currentOwner && typeof currentOwner._debugID === 'number') {
var id = currentOwner && currentOwner._debugID;
var id = currentOwner ? currentOwner._debugID : null;
info += ReactComponentTreeHook.getStackAddendumByID(id);
}
return info;
Expand Down
8 changes: 4 additions & 4 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ var ReactNoop = {

function logFiber(fiber : Fiber, depth) {
log(
' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'),
' '.repeat(depth) + '- ' + (fiber.type ? (fiber.type : any).name || fiber.type : '[root]'),
'[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']'
);
if (fiber.updateQueue) {
logUpdateQueue(fiber.updateQueue, depth);
if ((fiber : any).updateQueue) {
logUpdateQueue((fiber : any).updateQueue, depth);
}
const childInProgress = fiber.progressedChild;
if (childInProgress && childInProgress !== fiber.child) {
Expand All @@ -332,7 +332,7 @@ var ReactNoop = {
log('HOST INSTANCES:');
logContainer(rootContainer, 0);
log('FIBERS:');
logFiber((root.stateNode : any).current, 0);
logFiber((root : any).stateNode.current, 0);

console.log(...bufferedLog);
},
Expand Down
45 changes: 35 additions & 10 deletions src/renderers/shared/fiber/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

import type { ReactCoroutine, ReactYield } from 'ReactCoroutine';
import type { ReactPortal } from 'ReactPortal';
import type { Fiber } from 'ReactFiber';
import type {
Fiber,
ElementFiber,
ParentFiber,
} from 'ReactFiber';
import type { ReactInstance } from 'ReactInstanceType';
import type { PriorityLevel } from 'ReactPriorityLevel';

Expand Down Expand Up @@ -55,6 +59,8 @@ const isArray = Array.isArray;

const {
ClassComponent,
FunctionalComponent,
HostComponent,
HostText,
HostPortal,
CoroutineComponent,
Expand All @@ -68,7 +74,11 @@ const {
Deletion,
} = ReactTypeOfSideEffect;

function coerceRef(current: ?Fiber, element: ReactElement<any>) {
function coerceRef(current: ?ElementFiber, element: ReactElement<any>) :
// TODO: This should either be a typed host ref or it should be a typed class
// component ref. This should move into the type check that we do in
// createFiberFromElementType where we know which one it is.
((handle : any) => void) & { _stringRef: ?string } {
let mixedRef = element.ref;
if (mixedRef != null && typeof mixedRef !== 'function') {
if (element._owner) {
Expand Down Expand Up @@ -110,7 +120,7 @@ function coerceRef(current: ?Fiber, element: ReactElement<any>) {
function ChildReconciler(shouldClone, shouldTrackSideEffects) {

function deleteChild(
returnFiber : Fiber,
returnFiber : ParentFiber,
childToDelete : Fiber
) : void {
if (!shouldTrackSideEffects) {
Expand Down Expand Up @@ -141,7 +151,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}

function deleteRemainingChildren(
returnFiber : Fiber,
returnFiber : ParentFiber,
currentFirstChild : ?Fiber
) : null {
if (!shouldTrackSideEffects) {
Expand Down Expand Up @@ -180,7 +190,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return existingChildren;
}

function useFiber(fiber : Fiber, priority : PriorityLevel) : Fiber {
function useFiber<T : Fiber>(fiber : T, priority : PriorityLevel) : T {
// We currently set sibling to null and index to 0 here because it is easy
// to forget to do before returning it. E.g. for the single child case.
if (shouldClone) {
Expand Down Expand Up @@ -259,10 +269,17 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
element : ReactElement<any>,
priority : PriorityLevel
) : Fiber {
if (current == null || current.type !== element.type) {
if (current == null ||
// Verify that this is indeed an element tag
current.tag !== HostComponent ||
current.tag !== ClassComponent ||
current.tag !== FunctionalComponent ||
// If it is an element tag, check the type.
current.type !== element.type
) {
// Insert
const created = createFiberFromElement(element, priority);
created.ref = coerceRef(current, element);
created.ref = coerceRef(null, element);
created.return = returnFiber;
return created;
} else {
Expand Down Expand Up @@ -537,7 +554,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}

function reconcileChildrenArray(
returnFiber : Fiber,
returnFiber : ParentFiber,
currentFirstChild : ?Fiber,
newChildren : Array<*>,
priority : PriorityLevel) : ?Fiber {
Expand Down Expand Up @@ -863,7 +880,15 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
// TODO: If key === null and child.key === null, then this only applies to
// the first item in the list.
if (child.key === key) {
if (child.type === element.type) {
if (
// Verify that this is indeed an element tag
child.tag === HostComponent &&
child.tag === ClassComponent &&
child.tag === FunctionalComponent &&
// And if it is, then compare the type field to validate that we
// should indeed update this one.
child.type === element.type
) {
deleteRemainingChildren(returnFiber, child.sibling);
const existing = useFiber(child, priority);
existing.ref = coerceRef(child, element);
Expand All @@ -881,7 +906,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}

const created = createFiberFromElement(element, priority);
created.ref = coerceRef(currentFirstChild, element);
created.ref = coerceRef(null, element);
created.return = returnFiber;
return created;
}
Expand Down
Loading