diff --git a/packages/react-native/src/private/webapis/performance/LongTasks.js b/packages/react-native/src/private/webapis/performance/LongTasks.js new file mode 100644 index 00000000000..20164b7fc32 --- /dev/null +++ b/packages/react-native/src/private/webapis/performance/LongTasks.js @@ -0,0 +1,39 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict + */ + +// flowlint unsafe-getters-setters:off + +import type {PerformanceEntryJSON} from './PerformanceEntry'; + +import {PerformanceEntry} from './PerformanceEntry'; + +export type PerformanceLongTaskTimingJSON = { + ...PerformanceEntryJSON, + attribution: $ReadOnlyArray, + ... +}; + +export class TaskAttributionTiming extends PerformanceEntry {} + +const EMPTY_ATTRIBUTION: $ReadOnlyArray = + Object.preventExtensions([]); + +export class PerformanceLongTaskTiming extends PerformanceEntry { + get attribution(): $ReadOnlyArray { + return EMPTY_ATTRIBUTION; + } + + toJSON(): PerformanceLongTaskTimingJSON { + return { + ...super.toJSON(), + attribution: this.attribution, + }; + } +} diff --git a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js index 843886f19a3..5ccedba8e0c 100644 --- a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js +++ b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js @@ -14,6 +14,7 @@ import type { RawPerformanceEntryType, } from './specs/NativePerformanceObserver'; +import {PerformanceLongTaskTiming} from './LongTasks'; import {PerformanceEntry} from './PerformanceEntry'; import PerformanceEventTiming from './PerformanceEventTiming'; import {PerformanceMark, PerformanceMeasure} from './UserTiming'; @@ -37,6 +38,13 @@ export function rawToPerformanceEntry( processingEnd: entry.processingEnd, interactionId: entry.interactionId, }); + } else if (entry.entryType === RawPerformanceEntryTypeValues.LONGTASK) { + return new PerformanceLongTaskTiming({ + name: entry.name, + entryType: rawToPerformanceEntryType(entry.entryType), + startTime: entry.startTime, + duration: entry.duration, + }); } else if (entry.entryType === RawPerformanceEntryTypeValues.MARK) { return new PerformanceMark(entry.name, { startTime: entry.startTime,