🐛 fix resource timing buffer listener not stopped on cleanup#4360
🐛 fix resource timing buffer listener not stopped on cleanup#4360thomas-lebeau wants to merge 1 commit intomainfrom
Conversation
- Call stopManageResourceTimingBufferFull() in the observable teardown - Reset resourceTimingBufferFullListener to undefined after stopping to avoid stale references - Type the module-level variable as optional (| undefined) to reflect its possible absent state
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13ebe8cc40
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| return () => { | ||
| observer.disconnect() | ||
| stopManageResourceTimingBufferFull() |
There was a problem hiding this comment.
Keep shared resource buffer listener alive across observables
Calling stopManageResourceTimingBufferFull() in every createPerformanceObservable cleanup removes the single module-level resourcetimingbufferfull listener even when other performance observables are still subscribed. This is reachable with short-lived subscriptions like createPageActivityObservable (unsubscribed when waitPageActivityEnd completes), while long-lived resource collection remains active, so the resource timing buffer is no longer cleared and later resource entries can be dropped once full. The cleanup needs ref-counting (or equivalent) so the shared listener is only removed when the last dependent observable stops.
Useful? React with 👍 / 👎.
Motivation
The
manageResourceTimingBufferFullfunction registers a listener for theresourcetimingbufferfullevent on theperformanceobject. However, the return value (a cleanup function) was not being captured or called when thePerformanceObservablewas cleaned up, causing the listener to remain active after the observer was disconnected.Additionally,
resourceTimingBufferFullListenerwas typed as non-nullable, which prevented proper cleanup and reset of the module-level variable.Changes
manageResourceTimingBufferFulland call it in the cleanup callback ofcreatePerformanceObservableresourceTimingBufferFullListenertoundefinedafter stopping it, so subsequent calls can re-register the listener if neededresourceTimingBufferFullListenerto| undefinedto reflect its actual nullable stateTest instructions
resourcetimingbufferfullevent listeners remain on theperformanceobjectChecklist