Skip to content

Commit dc16668

Browse files
trueadmdummdidummRich-Harris
authored
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 <[email protected]> * changeset --------- Co-authored-by: Simon H <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 965afc5 commit dc16668

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/eighty-lizards-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
chore: improve runtime overhead of creating comment templates

packages/svelte/src/internal/client/dom/template.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,18 @@ export function text(anchor) {
251251
return push_template_node(node);
252252
}
253253

254-
export const comment = template('<!>', TEMPLATE_FRAGMENT | TEMPLATE_USE_IMPORT_NODE);
254+
export function comment() {
255+
// we're not delegating to `template` here for performance reasons
256+
if (hydrating) {
257+
return push_template_node(hydrate_nodes);
258+
}
259+
var frag = document.createDocumentFragment();
260+
var anchor = empty();
261+
frag.append(anchor);
262+
push_template_node([anchor]);
263+
264+
return frag;
265+
}
255266

256267
/**
257268
* Assign the created (or in hydration mode, traversed) dom elements to the current block

0 commit comments

Comments
 (0)