question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Custom HTML elements attach a Shadow DOM

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lele0108commented, Jul 15, 2022

Is this page using ShadyDOM polyfill?

Check on page: window.ShadyDOM. If object exists, check if settings.force is set to true. If so, even if browser supports Shadow DOM, ShadyDOM is polyfilling it. I have noticed Google web properties like to polyfill Shadow DOMs regardless of native support.

If this is the case, because of the accuracy of the polyfill, rrweb thinks it is a real shadow DOM (even though it is not). Hence, it is being created incorrectly on the viewer as a shadow DOM but in reality there are no shadow doms.

In addition, the polyfill patches Node.childNodes getter and a series of DOM getters that will mess with rrweb’s ability to snapshot and record mutations correctly unless you get original functions from Node’s prototype (luckily it does not patch prototype)

1reaction
Mark-Fenngcommented, Jul 19, 2022

@lele0108 I followed your suggestion on this webpage https://www.partneradvantage.goog/GCPPRM/s/partnerselfregistration?language=en_US. Unfortunately, shadow dom on this site is poly filled but not by shadyDOM. I tracked the source code and found the implementation of shadow dom to be lwc’s synthetic-shadow. https://github.com/salesforce/lwc/blob/master/packages/%40lwc/synthetic-shadow/src/faux-shadow/element.ts#L81-L87 But thanks for your great suggestion! It really helps a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[shadow-dom][web-components] attachedCallback never fired ...
When a custom-element is inside the shadow-root of another custom-element the attached callback never fires. TEST CASE http://jsbin.com/wuwaxe/1/ ...
Read more >
Shadow DOM v1 - Self-Contained Web Components
Shadow DOM is particularly useful when creating custom elements. Use shadow DOM to compartmentalize an element's HTML, CSS, and JS, thus ...
Read more >
'box-shadow' on a custom component with only a shadow root ...
I have a custom component that has only the shadow root attached and no child elements inside it. In Chrome dev tools, hover...
Read more >
Using declarative shadow DOM on an element containing a ...
What steps will reproduce the problem? (1) Create two simple custom elements using the declarative shadow DOM on both. (2) Insert a style...
Read more >
197960 – Implement ElementInternals - WebKit Bugzilla
View All Add an attachment (proposed patch, testcase, etc.) ... wpt/blob/master/shadow-dom/Element-interface-attachShadow-custom-element.html ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found