From 3a2422663fbc451f9b85e1ca2a279b7788a71603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 17 Oct 2024 12:58:39 -0700 Subject: [PATCH] Fix incorrect type being passed to NativePerformance.mark (#47102) Summary: Changelog: [internal] In D64466057 / https://github.com/facebook/react-native/commit/32f7b3b4e0b8be1d1138f43c46b3c86d9a64c29a we accidentally modified the API of `NativePerformance.mark` (which we wanted to preserve and move the changes to `NativePerformance.markWithResult` after some iteration) to make `startTime` optional. This change isn't OTA safe and no automated systems caught this problem. This fixes the issue by reverting the type back to being required and always passing it from the JS API. Differential Revision: D64557467 --- .../src/private/webapis/performance/Performance.js | 6 ++++-- .../private/webapis/performance/specs/NativePerformance.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-native/src/private/webapis/performance/Performance.js b/packages/react-native/src/private/webapis/performance/Performance.js index 2447879e619e31..8ac0054fd0aa4f 100644 --- a/packages/react-native/src/private/webapis/performance/Performance.js +++ b/packages/react-native/src/private/webapis/performance/Performance.js @@ -116,13 +116,15 @@ export default class Performance { markOptions?.startTime, ); } else if (NativePerformance?.mark) { - NativePerformance.mark(markName, markOptions?.startTime); + computedStartTime = markOptions?.startTime ?? performance.now(); + NativePerformance?.mark?.(markName, computedStartTime); } else { warnNoNativePerformance(); + computedStartTime = performance.now(); } return new PerformanceMark(markName, { - startTime: computedStartTime ?? performance.now(), + startTime: computedStartTime, detail: markOptions?.detail, }); } diff --git a/packages/react-native/src/private/webapis/performance/specs/NativePerformance.js b/packages/react-native/src/private/webapis/performance/specs/NativePerformance.js index 85fa3ccd01b354..aa10bbd706c29d 100644 --- a/packages/react-native/src/private/webapis/performance/specs/NativePerformance.js +++ b/packages/react-native/src/private/webapis/performance/specs/NativePerformance.js @@ -46,7 +46,7 @@ export type PerformanceObserverInit = { export interface Spec extends TurboModule { +now?: () => number; // TODO: remove when `markWithResult` is fully rolled out. - +mark?: (name: string, startTime?: number) => void; + +mark?: (name: string, startTime: number) => void; // TODO: remove when `measureWithResult` is fully rolled out. +measure?: ( name: string,