From 14bbb87516779942a2ecf7c0c208f30f2fd1a689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 17 Oct 2024 13:05:01 -0700 Subject: [PATCH] Fix incorrect type being passed to NativePerformance.mark (#47102) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47102 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, which isn't compatible with the previous native API. This fixes the issue by reverting the type back to being required and always passing it from the JS API. Differential Revision: D64557467 fbshipit-source-id: 3ade4271622ac6213fd4c2d4948c7d40e4abe715 --- .../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 2447879e619..8ac0054fd0a 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 85fa3ccd01b..aa10bbd706c 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,