Skip to content

Commit 28ebd6d

Browse files
committed
simplify
1 parent 61f0793 commit 28ebd6d

File tree

5 files changed

+7
-24
lines changed

5 files changed

+7
-24
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,12 +1088,6 @@ function create_block(parent, name, nodes, context) {
10881088
// It's important that close is the last statement in the block, as any previous statements
10891089
// could contain element insertions into the template, which the close statement needs to
10901090
// know of when constructing the list of current inner elements.
1091-
1092-
if (context.path.length > 0) {
1093-
// this is a block — return DOM so it can be attached directly to the effect
1094-
close = b.return(close.expression);
1095-
}
1096-
10971091
body.push(close);
10981092
}
10991093

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { render_effect } from '../../reactivity/effects.js';
2-
import { remove } from '../reconciler.js';
3-
import { untrack } from '../../runtime.js';
1+
import { branch, render_effect } from '../../reactivity/effects.js';
42

53
/**
64
* @template {(node: import('#client').TemplateNode, ...args: any[]) => import('#client').Dom} SnippetFn
@@ -11,19 +9,13 @@ import { untrack } from '../../runtime.js';
119
*/
1210
export function snippet(get_snippet, node, ...args) {
1311
/** @type {SnippetFn | null | undefined} */
14-
var snippet_fn;
12+
var snippet;
1513

1614
render_effect(() => {
17-
if (snippet_fn === (snippet_fn = get_snippet())) return;
15+
if (snippet === (snippet = get_snippet())) return;
1816

19-
if (snippet_fn) {
20-
// Untrack so we only rerender when the snippet function itself changes,
21-
// not when an eagerly-read prop inside the snippet function changes
22-
var dom = untrack(() => /** @type {SnippetFn} */ (snippet_fn)(node, ...args));
23-
24-
if (dom !== undefined) {
25-
return () => remove(dom);
26-
}
17+
if (snippet) {
18+
branch(() => /** @type {SnippetFn} */ (snippet)(node, ...args));
2719
}
2820
});
2921
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export const comment = template('<!>', TEMPLATE_FRAGMENT);
157157
* and insert the elements into the dom (in client mode).
158158
* @param {Text | Comment | Element} anchor
159159
* @param {import('#client').Dom} dom
160-
* @returns {import('#client').Dom}
161160
*/
162161
export function append(anchor, dom) {
163162
var current = dom;
@@ -175,6 +174,4 @@ export function append(anchor, dom) {
175174
}
176175

177176
/** @type {import('#client').Effect} */ (current_effect).dom = current;
178-
179-
return current;
180177
}

packages/svelte/tests/snapshot/samples/each-string-template/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function Each_string_template($$anchor, $$props) {
1414
var text = $.text($$anchor);
1515

1616
$.render_effect(() => $.set_text(text, `${$.stringify($.unwrap(thing))}, `));
17-
return $.append($$anchor, text);
17+
$.append($$anchor, text);
1818
});
1919

2020
$.append($$anchor, fragment);

packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function Function_prop_no_getter($$anchor, $$props) {
2424
var text = $.text($$anchor);
2525

2626
$.render_effect(() => $.set_text(text, `clicks: ${$.stringify($.get(count))}`));
27-
return $.append($$anchor, text);
27+
$.append($$anchor, text);
2828
}
2929
});
3030

0 commit comments

Comments
 (0)