From 34201d8387a6f126dd14aa849e988de6d044b2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 7 Jul 2025 06:42:23 -0700 Subject: [PATCH] Fix Flow types for performance.measure (#52431) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52431 Changelog: [internal] `performance.measure` supports passing mark names as `start` and `end` options, so this fixes the Flow type before fixing the actual implementation. It also makes it so you can't specify both `end` and `duration`, enforced by the type system. Reviewed By: huntie Differential Revision: D77795991 fbshipit-source-id: e89f509c7efc2fa49d17d79bc19bc1d14e007871 --- .../private/webapis/performance/Performance.js | 17 +++++++++++------ .../performance/__tests__/Performance-itest.js | 7 ------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/react-native/src/private/webapis/performance/Performance.js b/packages/react-native/src/private/webapis/performance/Performance.js index bb14a9ef2af..337d609f948 100644 --- a/packages/react-native/src/private/webapis/performance/Performance.js +++ b/packages/react-native/src/private/webapis/performance/Performance.js @@ -38,12 +38,17 @@ declare var global: { const getCurrentTimeStamp: () => DOMHighResTimeStamp = NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now()); -export type PerformanceMeasureOptions = { - detail?: DetailType, - start?: DOMHighResTimeStamp, - duration?: DOMHighResTimeStamp, - end?: DOMHighResTimeStamp, -}; +export type PerformanceMeasureOptions = + | { + detail?: DetailType, + start?: DOMHighResTimeStamp | string, + duration?: DOMHighResTimeStamp, + } + | { + detail?: DetailType, + start?: DOMHighResTimeStamp | string, + end?: DOMHighResTimeStamp | string, + }; const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray = ['mark', 'measure']; diff --git a/packages/react-native/src/private/webapis/performance/__tests__/Performance-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/Performance-itest.js index 95855a3e467..18f6f3ecf54 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/Performance-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/Performance-itest.js @@ -159,7 +159,6 @@ describe('Performance', () => { startTime: 10, }); - // $FlowFixMe[incompatible-call] const measure = performance.measure('measure-with-start-mark', { start: 'start-mark', }); @@ -179,7 +178,6 @@ describe('Performance', () => { startTime: 50, }); - // $FlowFixMe[incompatible-call] const measure = performance.measure('measure-with-end-mark', { end: 'end-mark', }); @@ -205,7 +203,6 @@ describe('Performance', () => { const measure = performance.measure( 'measure-with-start-mark-and-end-mark', - // $FlowFixMe[incompatible-call] { start: 'start-mark', end: 'end-mark', @@ -263,7 +260,6 @@ describe('Performance', () => { const measure = performance.measure( 'measure-with-start-mark-and-duration', - // $FlowFixMe[incompatible-call] { start: 'start-mark', duration: 30, @@ -281,7 +277,6 @@ describe('Performance', () => { it('throws if the specified mark does NOT exist', () => { const missingStartMarkError = ensureInstance( getThrownError(() => { - // $FlowFixMe[incompatible-call] performance.measure('measure', { start: 'start', end: 'end', @@ -299,7 +294,6 @@ describe('Performance', () => { const missingEndMarkError = ensureInstance( getThrownError(() => { - // $FlowFixMe[incompatible-call] performance.measure('measure', { start: 'start', end: 'end', @@ -314,7 +308,6 @@ describe('Performance', () => { performance.mark('end'); expect(() => { - // $FlowFixMe[incompatible-call] performance.measure('measure', { start: 'start', end: 'end',