🏁 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:
parent
4f79b9744d
commit
093dd97af3
|
|
@ -25,6 +25,7 @@ import {
|
||||||
isEnableScopedCSS,
|
isEnableScopedCSS,
|
||||||
performanceMark,
|
performanceMark,
|
||||||
performanceMeasure,
|
performanceMeasure,
|
||||||
|
performanceGetEntriesByName,
|
||||||
toArray,
|
toArray,
|
||||||
validateExportLifecycle,
|
validateExportLifecycle,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
@ -363,9 +364,9 @@ export async function loadApp<T extends ObjectType>(
|
||||||
mount: [
|
mount: [
|
||||||
async () => {
|
async () => {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
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
|
// mark length is zero means the app is remounting
|
||||||
if (!marks.length) {
|
if (marks && !marks.length) {
|
||||||
performanceMark(markName);
|
performanceMark(markName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/utils.ts
11
src/utils.ts
|
|
@ -101,7 +101,16 @@ const supportsUserTiming =
|
||||||
typeof performance.mark === 'function' &&
|
typeof performance.mark === 'function' &&
|
||||||
typeof performance.clearMarks === 'function' &&
|
typeof performance.clearMarks === 'function' &&
|
||||||
typeof performance.measure === '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) {
|
export function performanceMark(markName: string) {
|
||||||
if (supportsUserTiming) {
|
if (supportsUserTiming) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user