From dc166687731d1019f90674936e972ac9a2259262 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 13 May 2024 17:12:07 +0100 Subject: [PATCH] chore: improve runtime overhead of creating comment templates (#11591) * chore: improve runtime overhead of creating comment templates * Update packages/svelte/src/internal/client/dom/template.js Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * changeset --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Rich Harris --- .changeset/eighty-lizards-notice.md | 5 +++++ packages/svelte/src/internal/client/dom/template.js | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/eighty-lizards-notice.md 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