Skip to content

Commit

Permalink
Was experiencing an issue where the virtual parent optimization was d…
Browse files Browse the repository at this point in the history
…estroying already applied styles during <head> mutations
  • Loading branch information
eoghanmurray committed Feb 4, 2022
1 parent ef0e331 commit 87f303c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,13 @@ export class Replayer {
/**
* Why !isIframeINode(parent)? If parent element is an iframe, iframe document can't be appended to virtual parent.
* Why !hasIframeChild? If we move iframe elements from dom to fragment document, we will lose the contentDocument of iframe. So we need to disable the virtual dom optimization if a parent node contains iframe elements.
* Why parent.tagName !== 'HEAD'? moving stylesheets out of the <head> element removes the styles from the document (and they don't get replaced at `parent = virtualParent`
*/
if (
useVirtualParent &&
parentInDocument &&
!isIframeINode(parent) &&
parent.tagName !== 'HEAD' &&
!hasIframeChild
) {
const virtualParent = (document.createDocumentFragment() as unknown) as INode;
Expand Down

0 comments on commit 87f303c

Please sign in to comment.