-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: prevent mem leaks by removing unloaded iframes from map #1747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 9cb6057 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds cleanup logic to remove iframe window references from crossOriginIframeMap on iframe unload to address potential memory leaks.
- Wraps existing message listener registration in braces and adds an unload event listener.
- Introduces a changeset entry documenting the patch.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/rrweb/src/record/iframe-manager.ts | Adds unload listener to delete iframe window from tracking map. |
.changeset/shy-carrots-deny.md | Records patch change note about memory leak fix. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
iframeEl.contentWindow?.addEventListener('unload', () => { | ||
this.crossOriginIframeMap.delete(iframeEl.contentWindow!); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unload handler deletes using iframeEl.contentWindow at execution time, which may already point to a new Window after a navigation, leaving the original (unloaded) window object still stored in crossOriginIframeMap. Capture the original window reference before registering the listener and delete that specific reference instead.
iframeEl.contentWindow?.addEventListener('unload', () => { | |
this.crossOriginIframeMap.delete(iframeEl.contentWindow!); | |
}); | |
if (iframeEl.contentWindow) { | |
const win = iframeEl.contentWindow; | |
win.addEventListener('unload', () => { | |
this.crossOriginIframeMap.delete(win); | |
}); | |
} |
Copilot uses AI. Check for mistakes.
13d72bd
to
9cb6057
Compare
No description provided.