Skip to content

[Bug]: Custom HTML elements attach a Shadow DOM #933

@pavlogavryliuk

Description

@pavlogavryliuk

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

What package is this bug report for?

rrweb-snapshot

Expected Behavior

Looks like rrweb is processing incorrectly custom elements.

Custom elements are not a part of Shadow DOM, but during recording, all these elements receive the following options: isShadow and isShadowHost. In some cases it may break replay.

Actual Behavior

Recording

Custom elements receive isShadow and isShadowHost options.

Custom HTML element:
<community_navigation-global-navigation-trigger className="cAltToggleNav slds-icon_x-small" data-aura-rendered-by="367:0"> <lightning-button-icon></lightning-button-icon> <community_navigation-back-navigation-button></community_navigation-back-navigation-button> </community_navigation-global-navigation-trigger>

The same elements at snapshot:
{"type": 2, "tagName": "community_navigation-global-navigation-trigger", "attributes": { "class": "cAltToggleNav slds-icon_x-small", "data-aura-rendered-by": "367:0" }, "childNodes": [{ "type": 2, "tagName": "lightning-button-icon", "attributes": {}, "childNodes": [], "id": 167, "isShadowHost": true, "isShadow": true }, { "type": 2, "tagName": "community_navigation-back-navigation-button", "attributes": {}, "childNodes": [], "id": 175, "**isShadowHost**": true, "isShadow": true }], "id": 166, "isShadowHost": true }

Replay

On investigate how Replayer handle isShadowHost and isShadow options i came across a next comment in the code:

Since node is newly rebuilt, it should be a normal element without shadowRoot. But if there are some weird situations that has defined custom element in the scope before we rebuild node, it may register the shadowRoot earlier. The logic in the 'else' block is just a try-my-best solution for the corner case, please let we know if it is wrong and we can remove it.

if (n.isShadowHost) { if (!node.shadowRoot) { node.attachShadow({ mode: 'open' }); } else { while (node.shadowRoot.firstChild) { node.shadowRoot.removeChild(node.shadowRoot.firstChild); } } }

Testcase Gist URL

No response

Additional Information

Replay where custom elements have isShadowHost and isShadow options:

image

Replay without those options:

image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions