diff --git a/.changeset/eighty-lizards-notice.md b/.changeset/eighty-lizards-notice.md new file mode 100644 index 0000000000..507d66e3cb --- /dev/null +++ b/.changeset/eighty-lizards-notice.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +chore: improve runtime overhead of creating comment templates diff --git a/packages/svelte/src/internal/client/dom/template.js b/packages/svelte/src/internal/client/dom/template.js index 287fba88b8..8f754248e7 100644 --- a/packages/svelte/src/internal/client/dom/template.js +++ b/packages/svelte/src/internal/client/dom/template.js @@ -251,7 +251,18 @@ export function text(anchor) { return push_template_node(node); } -export const comment = template('', TEMPLATE_FRAGMENT | TEMPLATE_USE_IMPORT_NODE); +export function comment() { + // we're not delegating to `template` here for performance reasons + if (hydrating) { + return push_template_node(hydrate_nodes); + } + var frag = document.createDocumentFragment(); + var anchor = empty(); + frag.append(anchor); + push_template_node([anchor]); + + return frag; +} /** * Assign the created (or in hydration mode, traversed) dom elements to the current block