Skip to content

Commit

Permalink
Fix durability of PerformanceObserver mark/measure example
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rozele authored and facebook-github-bot committed Jan 24, 2025
1 parent 73968dc commit 05fdfad
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']});
Expand Down

0 comments on commit 05fdfad

Please sign in to comment.