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] ShadowRootRenderer - Removes unassigned text nodes

See original GitHub issue

Hey there,

I’ve noticed that the server-renderer removes the perfectly valid simple textNode type children of a custom element. https://github.com/capricorn86/happy-dom/blob/7f03049c01f6c50b8cead43706c32496675120b3/packages/server-rendering/src/renderer/shadow-root/ShadowRootRenderer.ts#L77

Example:

class SimpleStyler extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({mode: 'open'}).innerHTML = '<style>color: "red";</style>';
  }
}

customElements.define('simple-styler', SimpleStyler);
<simple-styler>Text node should not be removed</simple-styler>

The above example fails to render correctly by HappyDOMServerRenderer even if the web component has a default slot as the textNode is not listed by element.children https://github.com/capricorn86/happy-dom/blob/7f03049c01f6c50b8cead43706c32496675120b3/packages/server-rendering/src/renderer/shadow-root/ShadowRootRenderer.ts#L56

Output will be:

<simple-styler><style>color: "red";</style></simple-styler>

Expected output:

<simple-styler><style>color: "red";</style>Text node should not be removed</simple-styler>

Let me know if you’d prefer me to create a PR. Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
capricorn86commented, Mar 15, 2022

@itutto the problem should now be fixed.

You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v2.47.1

1reaction
capricorn86commented, Mar 14, 2022

@itutto you are right. It seems like there is a bug where custom elements aren’t loaded when defined. They have to be defined before the HTML is rendered.

I have created a new bug for it: https://github.com/capricorn86/happy-dom/issues/404

Read more comments on GitHub >

github_iconTop Results From Across the Web

remove() does not remove slots from a shadow root #83 - GitHub
It seems .remove() is not covered by ShadyDOM polyfill. Removing a slot from shadow root, does nothing. <div id="shadowHost"></div> <script> shadowHost.
Read more >
How to remove a shadow root from an HTML element adorned ...
So it seems like the answer of replacing the shadow root with a new blank shadow root is not valid anymore.
Read more >
61245 – When removing a shadow root from DOM, also remove it ...
I have diagnosed the cause of the crashes discussed in bug 59571 as a shadow root remaining in the render tree after it...
Read more >
Removing Useless Nodes From the DOM - SitePoint
The function is called clean() , and its purpose is to remove comments and whitespace-only text nodes.
Read more >
Scheduler - Change Log - Bryntum
Calling it should no longer be necessary; Removed the removeUnassignedEvent config from Scheduler. It was moved to EventStore back in 4.0 and was...
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