Skip to content

Commit

Permalink
Handle the case when PerformanceObserver.observe is called multiple t…
Browse files Browse the repository at this point in the history
…imes

Summary:
[Changelog][Internal]
Addresses the corresponding TODO in code, to make sure that PerformanceObserver.observe may be called multiple times with different entry types to observe.

Reviewed By: christophpurrer

Differential Revision: D41686237

fbshipit-source-id: 4287f63f7e71e5b1056d30ed616149841ba4f892
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 3, 2022
1 parent 862a99c commit 1c7e678
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Libraries/WebPerformance/PerformanceObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ export default class PerformanceObserver {
(_observedEntryTypeRefCount.get(type) ?? 0) + 1,
);
}
// TODO: Handle correctly the cases when "observe" is called multiple times
// on the same observer (potentially with different entry types)
// The same observer may have "observe" called multiple times,
// with different entry types
const observerData = _observers.get(this);
if (observerData !== undefined) {
entryTypes = new Set([...entryTypes, ...observerData.entryTypes]);
}
_observers.set(this, {entryTypes, callback: this._callback});
}

Expand Down

0 comments on commit 1c7e678

Please sign in to comment.