🏁 upgrade compatibility of performance.getEntriesByName api (#1173)

Co-authored-by: 李海涛 <“liht@dustess.com”>
Co-authored-by: Kuitos <kuitos.lau@gmail.com>
This commit is contained in:
Haitao Lee 2020-12-24 15:47:31 +08:00 committed by GitHub
parent 4f79b9744d
commit 093dd97af3
2 changed files with 13 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import {
isEnableScopedCSS,
performanceMark,
performanceMeasure,
performanceGetEntriesByName,
toArray,
validateExportLifecycle,
} from './utils';
@ -363,9 +364,9 @@ export async function loadApp<T extends ObjectType>(
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);
}
}

View File

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