diff --git a/libs/horizon/src/renderer/diff/nodeDiffComparator.ts b/libs/horizon/src/renderer/diff/nodeDiffComparator.ts index 530e9f87..773a15fd 100644 --- a/libs/horizon/src/renderer/diff/nodeDiffComparator.ts +++ b/libs/horizon/src/renderer/diff/nodeDiffComparator.ts @@ -471,7 +471,7 @@ function diffIteratorNodesHandler( parentNode: VNode, firstChild: VNode | null, newChildrenIterable: Iterable, - isComparing: boolean = true + isComparing: boolean ): VNode | null { const iteratorFn = getIteratorFn(newChildrenIterable); const iteratorObj = iteratorFn.call(newChildrenIterable); @@ -604,7 +604,7 @@ export function createChildrenByDiff( parentNode: VNode, firstChild: VNode | null, newChild: any, - isComparing: boolean = true + isComparing: boolean ): VNode | null { const isFragment = isNoKeyFragment(newChild); newChild = isFragment ? newChild.props.children : newChild; diff --git a/libs/horizon/src/renderer/render/ContextProvider.ts b/libs/horizon/src/renderer/render/ContextProvider.ts index c3c287d8..9e60f2b0 100644 --- a/libs/horizon/src/renderer/render/ContextProvider.ts +++ b/libs/horizon/src/renderer/render/ContextProvider.ts @@ -56,7 +56,7 @@ function handleContextChange(processing: VNode, context: ContextType): void }, node => // 如果这是匹配的provider,则不要更深入地扫描 node.tag === ContextProvider && node.type === processing.type - , processing); + , processing, null); // 找到了依赖context的子节点,触发一次更新 if (isMatch) { diff --git a/libs/horizon/src/renderer/render/DomComponent.ts b/libs/horizon/src/renderer/render/DomComponent.ts index 7aef0d8d..99ca2010 100644 --- a/libs/horizon/src/renderer/render/DomComponent.ts +++ b/libs/horizon/src/renderer/render/DomComponent.ts @@ -88,7 +88,7 @@ export function bubbleRender(processing: VNode) { }, node => // 已经append到父节点,或者是DomPortal都不需要处理child了 node.tag === DomComponent || node.tag === DomText || node.tag === DomPortal - , processing); + , processing, null); } processing.realNode = dom; diff --git a/libs/horizon/src/renderer/render/DomPortal.ts b/libs/horizon/src/renderer/render/DomPortal.ts index e8da4a6e..b3be42df 100644 --- a/libs/horizon/src/renderer/render/DomPortal.ts +++ b/libs/horizon/src/renderer/render/DomPortal.ts @@ -17,7 +17,7 @@ function capturePortalComponent(processing: VNode) { const newElements = processing.props; if (processing.isCreated) { - processing.child = createChildrenByDiff(processing, null, newElements); + processing.child = createChildrenByDiff(processing, null, newElements, true); } else { processing.child = createVNodeChildren(processing, newElements); } diff --git a/libs/horizon/src/renderer/submit/LifeCycleHandler.ts b/libs/horizon/src/renderer/submit/LifeCycleHandler.ts index dd68847b..554d7d0f 100644 --- a/libs/horizon/src/renderer/submit/LifeCycleHandler.ts +++ b/libs/horizon/src/renderer/submit/LifeCycleHandler.ts @@ -147,7 +147,7 @@ function hideOrUnhideAllChildren(vNode, isHidden) { unHideDom(node.tag, instance, node.props); } } - }); + }, null, vNode, null); } function attachRef(vNode: VNode) { @@ -216,7 +216,7 @@ function unmountNestedVNodes(vNode: VNode): void { }, node => // 如果是DomPortal,不需要遍历child node.tag === DomPortal - ); + , vNode, null); } function submitAddition(vNode: VNode): void { @@ -314,7 +314,7 @@ function unmountDomComponents(vNode: VNode): void { } }, node => // 如果是dom不用再遍历child - node.tag === DomComponent || node.tag === DomText, null, (node) => { + node.tag === DomComponent || node.tag === DomText, vNode, (node) => { if (node.tag === DomPortal) { // 当离开portal,需要重新设置parent currentParentIsValid = false; diff --git a/libs/horizon/src/renderer/vnode/VNodeUtils.ts b/libs/horizon/src/renderer/vnode/VNodeUtils.ts index 400ee792..c1b0c1dc 100644 --- a/libs/horizon/src/renderer/vnode/VNodeUtils.ts +++ b/libs/horizon/src/renderer/vnode/VNodeUtils.ts @@ -27,11 +27,11 @@ export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinis export function travelVNodeTree( beginVNode: VNode, handleVNode: Function, - childFilter: Function = () => false, // 返回true不处理child - finishVNode?: VNode, // 结束遍历节点,有时候和beginVNode不相同 - handleWhenToParent?: Function + childFilter: ((node: VNode) => boolean) | null, // 返回true不处理child + finishVNode: VNode, // 结束遍历节点,有时候和beginVNode不相同 + handleWhenToParent: Function | null ): VNode | null { - const overVNode = finishVNode || beginVNode; + const filter = childFilter === null; let node = beginVNode; while (true) { @@ -43,20 +43,20 @@ export function travelVNodeTree( // 找子节点 const childVNode = node.child; - if (childVNode !== null && !childFilter(node)) { + if (childVNode !== null && (filter || !childFilter(node))) { childVNode.parent = node; node = childVNode; continue; } // 回到开始节点 - if (node === overVNode) { + if (node === finishVNode) { return null; } // 找兄弟,没有就往上再找兄弟 while (node.next === null) { - if (node.parent === null || node.parent === overVNode) { + if (node.parent === null || node.parent === finishVNode) { return null; } node = node.parent; @@ -119,7 +119,7 @@ export function findDomVNode(vNode: VNode): VNode | null { return node; } return null; - }); + }, null, vNode, null); } export function findDOMByClassInst(inst) {