Skip to content

Conversation

@tunetheweb
Copy link
Member

Fixes #622

@tunetheweb tunetheweb requested a review from philipwalton May 31, 2025 13:50
@leoswing
Copy link

leoswing commented Jun 3, 2025

Could anyone help to approved this PR and publish a new version? Same issue occured and needs to fix.

@tunetheweb
Copy link
Member Author

@leoswing can you explain the urgency? Our understand and external analysis in #622 (comment) suggests the impact is minimal. But yes I'd still like to fix this and release a new version soon.

@leoswing
Copy link

leoswing commented Jun 4, 2025

@leoswing can you explain the urgency? Our understand and external analysis in #622 (comment) suggests the impact is minimal. But yes I'd still like to fix this and release a new version soon.

@tunetheweb hi, in our scenario,the application of micro-frontend seems encountered the serious memory leak problems. So much appreciated if a fix version could be released soon in these days. Thanks a lot ~

@M-ZubairAhmed
Copy link

@tunetheweb happens in our Mattermost app as well

@tunetheweb
Copy link
Member Author

I agree it's happening. What is not so clear is if this is causing problems as per previous comments.

So you're saying you upgraded to v5 and started experiencing serious memory leak problems you did not see in v4.2.4.?

cb();
// Remove the above event listener since no longer required.
// See: https://github.com/GoogleChrome/web-vitals/issues/622
document.removeEventListener('visibilitychange', cb);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document.removeEventListener('visibilitychange', cb);
document.removeEventListener('visibilitychange', cb, {once: true});

I think you might need to make the signature exactly the same in order for the listener ti get removed. Can you confirm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried and it seems to work both ways, so LGTM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeEventListener doesn't have the once option and when I tried this originally I got an error. Doing it without seemed to work fine.

@tunetheweb tunetheweb merged commit e22d23b into main Jun 11, 2025
9 checks passed
@tunetheweb tunetheweb deleted the cancel-visibilitychange-eventlisteners branch June 11, 2025 18:32
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Nov 18, 2025
Bumps the vendored-in web vitals library to include the changes between
`5.0.2` <-> `5.1.0` from upstream

#### Changes from upstream

- Remove `visibilitychange` event listeners when no longer required
[#627](GoogleChrome/web-vitals#627)
- Register visibility-change early
[#637](GoogleChrome/web-vitals#637)
- Only finalize LCP on user events (isTrusted=true)
[#635](GoogleChrome/web-vitals#635)
- Fallback to default getSelector if custom function is null or
undefined [#634](GoogleChrome/web-vitals#634)

#### Our own Changes

- Added `addPageListener` and `removePageListener` utilities because the
upstream package changed the listeners to be added on `window` instead
of `document`, so I added those utilities to avoid having to check for
window every time we try to add a listener.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large number of visibilitychange handlers

4 participants