From 6674f0c3c61c926f1ae4483e36a6f2536c9afa8d Mon Sep 17 00:00:00 2001 From: liaohuanyu Date: Tue, 29 Jun 2021 15:23:23 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20profiler=20=E9=9D=A2=E6=9D=BF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=9A=E6=97=B6=E9=97=B4=E5=8C=BA=E9=97=B4=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../extensions/src/contentScript/contentScript.ts | 2 +- packages/extensions/src/devtoolsPage.ts | 2 +- .../frontend/src/components/layout/basicLayout.san | 2 +- packages/frontend/src/store/setTreeData.ts | 9 ++++----- packages/frontend/src/utils/flameJsonGenerator.ts | 11 +++++++++-- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4700e93..097ef18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ChangeLog - [Bugfix] - Fix incorrect number of components. - Fix incoreect layout of the san-devtools pannel(chrome extensions) in some special scenes. + - Fix data error in profiler pannel. 1.1.4 ------- diff --git a/packages/extensions/src/contentScript/contentScript.ts b/packages/extensions/src/contentScript/contentScript.ts index 1193dbc..4ac94e1 100644 --- a/packages/extensions/src/contentScript/contentScript.ts +++ b/packages/extensions/src/contentScript/contentScript.ts @@ -9,5 +9,5 @@ if (__DEBUG__) { console.log('content_script'); } -injector.fromExtensionUrlSync(chrome.runtime.getURL('js/san_devtools_backend.js')); +chrome.runtime && injector.fromExtensionUrlSync(chrome.runtime.getURL('js/san_devtools_backend.js')); relay(); diff --git a/packages/extensions/src/devtoolsPage.ts b/packages/extensions/src/devtoolsPage.ts index ccf1c5d..144eeba 100644 --- a/packages/extensions/src/devtoolsPage.ts +++ b/packages/extensions/src/devtoolsPage.ts @@ -17,7 +17,7 @@ function createDevtoolPanelIfNeeded() { return; } clearInterval(createdCheckInterval); - chrome.devtools.panels.create( + chrome.runtime && chrome.devtools.panels.create( 'San', chrome.runtime.getURL('/icons/logo128.png'), 'panel.html' diff --git a/packages/frontend/src/components/layout/basicLayout.san b/packages/frontend/src/components/layout/basicLayout.san index 764c9d3..dacc066 100644 --- a/packages/frontend/src/components/layout/basicLayout.san +++ b/packages/frontend/src/components/layout/basicLayout.san @@ -71,7 +71,7 @@ document.querySelector(`.${prefix}-right`).style = 'width: 100%'; let parent = document.querySelector(`.${prefix}-wrapper`); let child = document.querySelector(`.gutter-${status}-wrapper`); - parent.removeChild(child); + child && parent && parent.removeChild(child); } } diff --git a/packages/frontend/src/store/setTreeData.ts b/packages/frontend/src/store/setTreeData.ts index 2c09310..edbcf0f 100644 --- a/packages/frontend/src/store/setTreeData.ts +++ b/packages/frontend/src/store/setTreeData.ts @@ -14,12 +14,11 @@ interface ComponentTreeInfo{ */ function getIDListFromTreeData(treeData: ComponentTreeData[]) { let ids: string[] = []; - if (!treeData) { - return ids; + if (treeData) { + treeData.forEach((data: any) => { + data.id && ids.push(data.id); + }); } - treeData.forEach((data: any) => { - data.id && ids.push(data.id); - }); return ids; } diff --git a/packages/frontend/src/utils/flameJsonGenerator.ts b/packages/frontend/src/utils/flameJsonGenerator.ts index 980e504..4ecb5c4 100644 --- a/packages/frontend/src/utils/flameJsonGenerator.ts +++ b/packages/frontend/src/utils/flameJsonGenerator.ts @@ -125,8 +125,9 @@ function timeFragementCacheHandler(children: TimeFragement[], timeFragment: Time default: break; } } - // 如果数组遍历完了,还是没有找到 case 0 的情况,则直接 push 到 curChildren,并结束深度遍历 - if (index === len) { + // 1. 如果数组遍历完了,还是没有找到 case 0 的情况,则直接 push 到 curChildren + // 2. 如果找到了 case 0,并且当前位置的 children 为空,则直接添加到 children 中 + if (index === len || curChildren.length === 0) { curChildren.push(timeFragment); return; } @@ -147,6 +148,12 @@ function getTimeSlotsRelation(timeSlotA: TimeFragement, timeSlotB: TimeFragement // 包含关系: startDiff > 0 为 B 包含 A,startDiff < 0 为 A 包含 B return startDiff < 0 ? 1 : 0; } + else if (startDiff === 0) { + return endDiff < 0 ? 0 : 1; + } + else if (endDiff === 0) { + return startDiff < 0 ? 1 : 0; + } else { if (timeSlotA.start >= timeSlotB.end) { // timeSlotA 在 timeSlotB 的右边