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) {