From 05fdfad148615eaf458d800b15e080c92f0f27dd Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Fri, 24 Jan 2025 12:02:04 -0800 Subject: [PATCH] Fix durability of PerformanceObserver mark/measure example Summary: The PerformanceObserver (marks and measures) example clears it's output each time a new PerformanceObserver event fires, which makes it not particularly useful. This change makes it so the output is only updated if a non-empty list of performance events is observed. Differential Revision: D68634361 --- .../js/examples/Performance/PerformanceApiExample.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js index 827c2819e8f66a..9e9576ef3e6884 100644 --- a/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js +++ b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js @@ -95,9 +95,12 @@ function PerformanceObserverUserTimingExample(): React.Node { useEffect(() => { const observer = new PerformanceObserver(list => { - setEntries( - list.getEntries().filter(entry => entry.name.startsWith('rntester-')), - ); + const newEntries = list + .getEntries() + .filter(entry => entry.name.startsWith('rntester-')); + if (newEntries.length > 0) { + setEntries(newEntries); + } }); observer.observe({entryTypes: ['mark', 'measure']});