[BUG] ShadowRootRenderer - Removes unassigned text nodes
See original GitHub issueHey 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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
@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