Match-id-c11e1befe0eb42e72a1ff5aeab9cd80718bdf2ae

This commit is contained in:
* 2022-02-22 16:56:23 +08:00 committed by *
parent 4d173bd7a0
commit 5dd5a50663
11 changed files with 22 additions and 33 deletions

View File

@ -236,7 +236,7 @@ function buildVNodeTree(treeRoot: VNode) {
// 当在componentWillUnmount中调用setStateparent可能是null因为startVNode会被clear
if (parent !== null) {
resetNamespaceCtx(parent);
setNamespaceCtx(parent, parent.outerDom);
setNamespaceCtx(parent, parent.realNode);
}
// 恢复父节点的context

View File

@ -39,7 +39,7 @@ export type ContextType<T> = {
export type PortalType = {
vtype: number;
key: null | string;
outerDom: any;
realNode: any;
children: any;
};

View File

@ -3,13 +3,13 @@ import type {PortalType} from '../Types';
export function createPortal(
children: any,
outerDom: any,
realNode: any,
key: string = '',
): PortalType {
return {
vtype: TYPE_PORTAL,
key: key == '' ? '' : '' + key,
children,
outerDom,
realNode,
};
}

View File

@ -153,7 +153,7 @@ function getNewNode(parentNode: VNode, newChild: any, oldNode: VNode | null) {
}
break;
} else if (newChild.vtype === TYPE_PORTAL) {
if (oldNode === null || oldNode.tag !== DomPortal || oldNode.outerDom !== newChild.outerDom) {
if (oldNode === null || oldNode.tag !== DomPortal || oldNode.realNode !== newChild.realNode) {
resultNode = createPortalVNode(newChild);
} else {
resultNode = updateVNode(oldNode, newChild.children || []);
@ -578,7 +578,7 @@ function diffObjectNodeHandler(
} else if (newChild.vtype === TYPE_PORTAL) {
if (canReuseNode) {
// 可以复用
if (canReuseNode.tag === DomPortal && canReuseNode.outerDom === newChild.outerDom) {
if (canReuseNode.tag === DomPortal && canReuseNode.realNode === newChild.realNode) {
resultNode = updateVNode(canReuseNode, newChild.children || []);
startDelVNode = canReuseNode.next;
resultNode.next = null;

View File

@ -18,7 +18,7 @@ import componentRenders from './index';
function handlerContext(processing: VNode) {
switch (processing.tag) {
case TreeRoot:
setNamespaceCtx(processing, processing.outerDom);
setNamespaceCtx(processing, processing.realNode);
break;
case DomComponent:
setNamespaceCtx(processing);
@ -29,7 +29,7 @@ function handlerContext(processing: VNode) {
break;
}
case DomPortal:
setNamespaceCtx(processing, processing.outerDom);
setNamespaceCtx(processing, processing.realNode);
break;
case ContextProvider: {
const newValue = processing.props.value;

View File

@ -7,12 +7,12 @@ export function bubbleRender(processing: VNode) {
resetNamespaceCtx(processing);
if (processing.isCreated) {
prePortal(processing.outerDom);
prePortal(processing.realNode);
}
}
function capturePortalComponent(processing: VNode) {
setNamespaceCtx(processing, processing.outerDom);
setNamespaceCtx(processing, processing.realNode);
const newElements = processing.props;
if (processing.isCreated) {

View File

@ -12,7 +12,7 @@ export function bubbleRender(processing: VNode) {
}
function updateTreeRoot(processing) {
setNamespaceCtx(processing, processing.outerDom);
setNamespaceCtx(processing, processing.realNode);
const updates = processing.updates;
throwIfTrue(

View File

@ -225,12 +225,9 @@ function submitAddition(vNode: VNode): void {
let tag;
while (parent !== null) {
tag = parent.tag;
if (tag === DomComponent) {
if (tag === DomComponent || tag === TreeRoot || tag === DomPortal) {
parentDom = parent.realNode;
break;
} else if (tag === TreeRoot || tag === DomPortal) {
parentDom = parent.outerDom;
break;
}
parent = parent.parent;
}
@ -292,12 +289,9 @@ function unmountDomComponents(vNode: VNode): void {
let tag;
while (parent !== null) {
tag = parent.tag;
if (tag === DomComponent) {
if (tag === DomComponent || tag === TreeRoot || tag === DomPortal) {
currentParent = parent.realNode;
break;
} else if (tag === TreeRoot || tag === DomPortal) {
currentParent = parent.outerDom;
break;
}
parent = parent.parent;
}
@ -312,7 +306,7 @@ function unmountDomComponents(vNode: VNode): void {
removeChildDom(currentParent, node.realNode);
} else if (node.tag === DomPortal) {
if (node.child !== null) {
currentParent = node.outerDom;
currentParent = node.realNode;
}
} else {
unmountVNode(node);
@ -349,12 +343,9 @@ function submitClear(vNode: VNode): void {
let tag;
while (parent !== null) {
tag = parent.tag;
if (tag === DomComponent) {
if (tag === DomComponent || tag === TreeRoot || tag === DomPortal) {
parentDom = parent.realNode;
break;
} else if (tag === TreeRoot || tag === DomPortal) {
parentDom = parent.outerDom;
break;
}
parent = parent.parent;
}

View File

@ -39,7 +39,6 @@ export class VNode {
dirtyNodes: Array<VNode> | null = null; // 需要改动的节点数组
shouldUpdate: boolean = false;
childShouldUpdate: boolean = false;
outerDom: any;
task: any;
// 使用这个变量来记录修改前的值,用于恢复。
@ -67,7 +66,7 @@ export class VNode {
belongClassVNode: VNode | null = null; // 记录JSXElement所属class vNode处理ref的时候使用
constructor(tag: VNodeTag, props: any, key: null | string, outerDom) {
constructor(tag: VNodeTag, props: any, key: null | string, realNode) {
this.tag = tag; // 对应组件的类型比如ClassComponent等
this.key = key;
@ -75,10 +74,9 @@ export class VNode {
switch (tag) {
case TreeRoot:
this.outerDom = outerDom;
this.realNode = realNode;
this.task = null;
this.toUpdateNodes = new Set<VNode>();
this.realNode = null;
this.updates = null;
this.stateCallbacks = null;
this.state = null;

View File

@ -38,8 +38,8 @@ const typeMap = {
[TYPE_LAZY]: LazyComponent,
};
const newVirtualNode = function(tag: VNodeTag, key?: null | string, vNodeProps?: any, outerDom?: any): VNode {
return new VNode(tag, vNodeProps, key, outerDom);
const newVirtualNode = function(tag: VNodeTag, key?: null | string, vNodeProps?: any, realNode?: any): VNode {
return new VNode(tag, vNodeProps, key, realNode);
};
function isClassComponent(comp: Function) {
@ -99,7 +99,7 @@ export function createPortalVNode(portal) {
const children = portal.children ?? [];
const vNode = newVirtualNode(DomPortal, portal.key, children);
vNode.shouldUpdate = true;
vNode.outerDom = portal.outerDom;
vNode.realNode = portal.realNode;
return vNode;
}

View File

@ -210,7 +210,7 @@ function isPortalRoot(vNode, targetContainer) {
while (topVNode !== null) {
const grandTag = topVNode.tag;
if (grandTag === TreeRoot || grandTag === DomPortal) {
const topContainer = topVNode.outerDom;
const topContainer = topVNode.realNode;
// 如果topContainer是targetContainer不需要在这里处理
if (isSameContainer(topContainer, targetContainer)) {
return true;
@ -229,7 +229,7 @@ export function getExactNode(targetVNode, targetContainer) {
let vNode = targetVNode;
while (vNode !== null) {
if (vNode.tag === TreeRoot || vNode.tag === DomPortal) {
let container = vNode.outerDom;
let container = vNode.realNode;
if (isSameContainer(container, targetContainer)) {
break;
}