Fix issue with creating table row elements
authorMarcel Werk <burntime@woltlab.com>
Tue, 17 Dec 2024 13:29:21 +0000 (14:29 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 17 Dec 2024 13:29:21 +0000 (14:29 +0100)
ts/WoltLabSuite/Core/Dom/Util.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js

index a3469471005feb180d871186dbea4e6d8587ec67..8a4ec354b7f54e23def97f7f505ca9773deef53d 100644 (file)
@@ -43,13 +43,11 @@ const DomUtil = {
    * Returns a DocumentFragment containing the provided HTML string as DOM nodes.
    */
   createFragmentFromHtml(html: string): DocumentFragment {
-    const tmp = document.createElement("div");
-    DomUtil.setInnerHtml(tmp, html);
+    const template = document.createElement("template");
+    DomUtil.setInnerHtml(template, html);
 
     const fragment = document.createDocumentFragment();
-    while (tmp.childNodes.length) {
-      fragment.appendChild(tmp.childNodes[0]);
-    }
+    fragment.append(template.content.cloneNode(true));
 
     return fragment;
   },
index c5a472f2b542f421832e99288ddde19e7b5fb855..2903284b3e86459d5e4a53e67ffbd764f034fa98 100644 (file)
@@ -38,12 +38,10 @@ define(["require", "exports", "tslib", "../StringUtil"], function (require, expo
          * Returns a DocumentFragment containing the provided HTML string as DOM nodes.
          */
         createFragmentFromHtml(html) {
-            const tmp = document.createElement("div");
-            DomUtil.setInnerHtml(tmp, html);
+            const template = document.createElement("template");
+            DomUtil.setInnerHtml(template, html);
             const fragment = document.createDocumentFragment();
-            while (tmp.childNodes.length) {
-                fragment.appendChild(tmp.childNodes[0]);
-            }
+            fragment.append(template.content.cloneNode(true));
             return fragment;
         },
         /**