-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: clear mutation buffer and remove mirror node on iframe pagehide event #1755
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…event
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "rrweb": patch | ||
| --- | ||
|
|
||
| To prevent mem leak, reset and clear mutation buffers and remove iframe node from mirror on iframes pagehide event |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||
| type SlimDOMOptions, | ||||||||||
| createMirror, | ||||||||||
| } from 'rrweb-snapshot'; | ||||||||||
| import { initObservers, mutationBuffers } from './observer'; | ||||||||||
| import { initObservers, mutationBuffers, findAndRemoveIframeBuffer } from './observer'; | ||||||||||
| import { | ||||||||||
| on, | ||||||||||
| getWindowWidth, | ||||||||||
|
|
@@ -437,6 +437,10 @@ | |||||||||
|
|
||||||||||
| try { | ||||||||||
| const handlers: listenerHandler[] = []; | ||||||||||
| const iframeHandlersMap = new Map< | ||||||||||
| HTMLIFrameElement, | ||||||||||
| listenerHandler | ||||||||||
| >(); | ||||||||||
|
|
||||||||||
| const observe = (doc: Document) => { | ||||||||||
| return callbackWrapper(initObservers)( | ||||||||||
|
|
@@ -557,7 +561,7 @@ | |||||||||
| plugins | ||||||||||
| ?.filter((p) => p.observer) | ||||||||||
| ?.map((p) => ({ | ||||||||||
| observer: p.observer!, | ||||||||||
| options: p.options, | ||||||||||
| callback: (payload: object) => | ||||||||||
| wrappedEmit({ | ||||||||||
|
|
@@ -575,13 +579,22 @@ | |||||||||
|
|
||||||||||
| iframeManager.addLoadListener((iframeEl) => { | ||||||||||
| try { | ||||||||||
| handlers.push(observe(iframeEl.contentDocument!)); | ||||||||||
| iframeHandlersMap.set(iframeEl, observe(iframeEl.contentDocument!)); | ||||||||||
|
||||||||||
| iframeHandlersMap.set(iframeEl, observe(iframeEl.contentDocument!)); | |
| const handler = observe(iframeEl.contentDocument!); | |
| iframeHandlersMap.set(iframeEl, handler); | |
| handlers.push(handler); |
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
pagehideevent listener is added but never removed, which could cause memory leaks if the iframe element is reused or if the manager is disposed. Consider storing the listener function reference and providing a cleanup mechanism to remove it when the iframe is detached.