From 5cac630e3404d9ea6b7df9efccdc2b4e7fc58ffe Mon Sep 17 00:00:00 2001 From: * <*> Date: Tue, 21 Feb 2023 18:20:13 +0800 Subject: [PATCH] Match-id-c19116d686a2df946cbfab9c8e3f9e8d79ddce4b --- CHANGELOG.md | 3 ++ libs/horizon/global.d.ts | 1 + libs/horizon/package.json | 2 +- libs/horizon/src/renderer/TreeBuilder.ts | 3 ++ libs/horizon/src/renderer/vnode/VNode.ts | 2 +- libs/horizon/src/renderer/vnode/VNodeUtils.ts | 43 +++++++++++++------ package.json | 2 - 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d81d5e..23d98919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.0.39 (2023-02-21) +- **core**: #102 使用eview-react组件Dialog时,关闭组件horizon报错,且无法再打开弹框 + ## 0.0.38 (2023-02-01) - **core**: 增加flushSync接口 diff --git a/libs/horizon/global.d.ts b/libs/horizon/global.d.ts index 9da3e079..598a8670 100644 --- a/libs/horizon/global.d.ts +++ b/libs/horizon/global.d.ts @@ -20,3 +20,4 @@ declare var isDev: boolean; declare var isTest: boolean; declare const __VERSION__: string; declare var setImmediate: Function; +declare var __HORIZON_DEV_HOOK__: any; diff --git a/libs/horizon/package.json b/libs/horizon/package.json index c9a179bc..d70cdf4c 100644 --- a/libs/horizon/package.json +++ b/libs/horizon/package.json @@ -4,7 +4,7 @@ "keywords": [ "horizon" ], - "version": "0.0.38", + "version": "0.0.39", "homepage": "", "bugs": "", "main": "index.js", diff --git a/libs/horizon/src/renderer/TreeBuilder.ts b/libs/horizon/src/renderer/TreeBuilder.ts index 2abace80..7d37de2f 100644 --- a/libs/horizon/src/renderer/TreeBuilder.ts +++ b/libs/horizon/src/renderer/TreeBuilder.ts @@ -312,6 +312,7 @@ function recoverTreeContext(vNode: VNode) { } parent = parent.parent; } + contextProviders.forEach(node => { setContext(node, node.props.value); }); @@ -336,6 +337,7 @@ function resetTreeContext(vNode: VNode) { function renderFromRoot(treeRoot) { runAsyncEffects(); pushCurrentRoot(treeRoot); + // 1. 构建vNode树 buildVNodeTree(treeRoot); @@ -346,6 +348,7 @@ function renderFromRoot(treeRoot) { // 2. 提交变更 submitToRender(treeRoot); + popCurrentRoot(); if (window.__HORIZON_DEV_HOOK__) { const hook = window.__HORIZON_DEV_HOOK__; diff --git a/libs/horizon/src/renderer/vnode/VNode.ts b/libs/horizon/src/renderer/vnode/VNode.ts index a5ec09bc..4214e928 100644 --- a/libs/horizon/src/renderer/vnode/VNode.ts +++ b/libs/horizon/src/renderer/vnode/VNode.ts @@ -89,7 +89,7 @@ export class VNode { oldChild: VNode | null = null; promiseResolve: boolean; // suspense的promise是否resolve devProps: any; // 用于dev插件临时保存更新props值 - suspenseState: SuspenseState; + suspenseState: SuspenseState | null; path = ''; // 保存从根到本节点的路径 diff --git a/libs/horizon/src/renderer/vnode/VNodeUtils.ts b/libs/horizon/src/renderer/vnode/VNodeUtils.ts index 6616d4c5..7e55f48d 100644 --- a/libs/horizon/src/renderer/vnode/VNodeUtils.ts +++ b/libs/horizon/src/renderer/vnode/VNodeUtils.ts @@ -17,15 +17,19 @@ * 提供:vNode的“遍历”,“查找”,“判断”的相关工具方法 */ -import type { VNode } from '../Types'; +import type {VNode} from '../Types'; -import { DomComponent, DomPortal, DomText, TreeRoot } from './VNodeTags'; -import { isComment } from '../../dom/utils/Common'; -import { getNearestVNode } from '../../dom/DOMInternalKeys'; -import { Addition, InitFlag } from './VNodeFlags'; +import {DomComponent, DomPortal, DomText, TreeRoot} from './VNodeTags'; +import {isComment} from '../../dom/utils/Common'; +import {getNearestVNode} from '../../dom/DOMInternalKeys'; +import {Addition, InitFlag} from './VNodeFlags'; -export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinish?: Function) { - let node: VNode | null = beginVNode; +export function travelChildren( + beginVNode: VNode | null, + handleVNode: (node: VNode) => void, + isFinish?: (node: VNode) => boolean +) { + let node = beginVNode; while (node !== null) { if (isFinish && isFinish(node)) { @@ -41,15 +45,16 @@ export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinis // 从beginVNode开始深度遍历vNode树,对每个vNode调用handleVNode方法 export function travelVNodeTree( beginVNode: VNode, - handleVNode: Function, + handleVNode: (node: VNode) => VNode | boolean | null | void, childFilter: ((node: VNode) => boolean) | null, // 返回true不处理child finishVNode: VNode, // 结束遍历节点,有时候和beginVNode不相同 - handleWhenToParent: Function | null -): VNode | null { + handleWhenToParent: ((node: VNode) => void) | null +): VNode | boolean | null | void { let node = beginVNode; while (true) { const ret = handleVNode(node); + // 如果处理一个vNode时有返回值,则中断遍历 if (ret) { return ret; @@ -68,6 +73,8 @@ export function travelVNodeTree( return null; } + const isFun = typeof handleWhenToParent === 'function'; + // 找兄弟,没有就往上再找兄弟 while (node.next === null) { if (node.parent === null || node.parent === finishVNode) { @@ -75,8 +82,8 @@ export function travelVNodeTree( } node = node.parent; - if (typeof handleWhenToParent === 'function') { - handleWhenToParent(node); + if (isFun) { + handleWhenToParent!(node); } } // 找到兄弟 @@ -89,14 +96,20 @@ export function travelVNodeTree( // 置空vNode export function clearVNode(vNode: VNode) { vNode.isCleared = true; + + // 孩子节点的parent也置空 + travelChildren(vNode.child, (node) => { + node.parent = null; + }); vNode.child = null; + + vNode.parent = null; vNode.next = null; vNode.depContexts = null; vNode.dirtyNodes = null; vNode.state = null; vNode.hooks = null; vNode.props = null; - vNode.parent = null; vNode.suspenseState = null; vNode.changeList = null; vNode.effectList = null; @@ -129,7 +142,7 @@ function isDomContainer(vNode: VNode): boolean { } export function findDomVNode(vNode: VNode): VNode | null { - return travelVNodeTree( + const ret = travelVNodeTree( vNode, node => { if (node.tag === DomComponent || node.tag === DomText) { @@ -141,6 +154,8 @@ export function findDomVNode(vNode: VNode): VNode | null { vNode, null ); + + return ret as VNode | null; } export function findDOMByClassInst(inst) { diff --git a/package.json b/package.json index f2d728f2..eae43edd 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,6 @@ "prettier": "prettier -w libs/**/*.ts", "build": "rollup --config ./scripts/rollup/rollup.config.js", "build:watch": "rollup --watch --config ./scripts/rollup/rollup.config.js", - "build:3rdLib": "node ./scripts/gen3rdLib.js build:3rdLib", - "build:3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js build:3rdLib-dev", "build:horizon3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js build:horizon3rdLib-dev", "build-types": "tsc -p ./libs/horizon/index.ts --emitDeclarationOnly --declaration --declarationDir ./build/horizon/@types --skipLibCheck || echo \"WARNING: TSC exited with status $?\"", "debug-test": "yarn test --debug",