From 093dd97af3344048adec2b3fd050f0508436cbdb Mon Sep 17 00:00:00 2001 From: Haitao Lee Date: Thu, 24 Dec 2020 15:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=81=20=20upgrade=20compatibility=20of?= =?UTF-8?q?=20performance.getEntriesByName=20api=20=20(#1173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李海涛 <“liht@dustess.com”> Co-authored-by: Kuitos --- src/loader.ts | 5 +++-- src/utils.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index 825392d..839ee92 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -25,6 +25,7 @@ import { isEnableScopedCSS, performanceMark, performanceMeasure, + performanceGetEntriesByName, toArray, validateExportLifecycle, } from './utils'; @@ -363,9 +364,9 @@ export async function loadApp( mount: [ async () => { if (process.env.NODE_ENV === 'development') { - const marks = performance.getEntriesByName(markName, 'mark'); + const marks = performanceGetEntriesByName(markName, 'mark'); // mark length is zero means the app is remounting - if (!marks.length) { + if (marks && !marks.length) { performanceMark(markName); } } diff --git a/src/utils.ts b/src/utils.ts index 4ef27da..b9abdac 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -101,7 +101,16 @@ const supportsUserTiming = typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && - typeof performance.clearMeasures === 'function'; + typeof performance.clearMeasures === 'function' && + typeof performance.getEntriesByName === 'function'; + +export function performanceGetEntriesByName(markName: string, type?: string) { + let marks = null; + if (supportsUserTiming) { + marks = performance.getEntriesByName(markName, type); + } + return marks; +} export function performanceMark(markName: string) { if (supportsUserTiming) {