Skip to content

Commit 1bdf919

Browse files
committed
fix, different approach without needing symbol
1 parent daf8a70 commit 1bdf919

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ function serialize_inline_component(node, component_name, context) {
840840
push_prop(
841841
b.init('children', context.state.options.dev ? b.call('$.wrap_snippet', slot_fn) : slot_fn)
842842
);
843+
// We additionally add the default slot as a boolean, so that the slot render function on the other
844+
// side knows it should get the content to render from $$props.children
845+
serialized_slots.push(b.init(slot_name, b.true));
843846
} else {
844847
serialized_slots.push(b.init(slot_name, slot_fn));
845848
}

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,16 @@ function serialize_inline_component(node, component_name, context) {
10841084
);
10851085

10861086
if (slot_name === 'default' && !has_children_prop) {
1087-
push_prop(b.prop('init', b.id('children'), b.call('$.add_snippet_symbol', slot_fn)));
1087+
push_prop(
1088+
b.prop(
1089+
'init',
1090+
b.id('children'),
1091+
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
1092+
)
1093+
);
1094+
// We additionally add the default slot as a boolean, so that the slot render function on the other
1095+
// side knows it should get the content to render from $$props.children
1096+
serialized_slots.push(b.init('default', b.true));
10881097
} else {
10891098
const slot = b.prop('init', b.literal(slot_name), slot_fn);
10901099
serialized_slots.push(slot);
@@ -1619,7 +1628,9 @@ const template_visitors = {
16191628
// TODO hoist where possible
16201629
context.state.init.push(fn);
16211630

1622-
context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
1631+
if (context.state.options.dev) {
1632+
context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
1633+
}
16231634
},
16241635
Component(node, context) {
16251636
const state = context.state;

packages/svelte/src/internal/client/dom/elements/custom-element.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createClassComponent } from '../../../../legacy/legacy-client.js';
22
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
3-
import { add_snippet_symbol } from '../blocks/snippet.js';
43
import { append } from '../template.js';
54
import { define_property, object_keys } from '../../utils.js';
65

@@ -111,7 +110,8 @@ if (typeof HTMLElement === 'function') {
111110
for (const name of this.$$s) {
112111
if (name in existing_slots) {
113112
if (name === 'default' && !this.$$d.children) {
114-
this.$$d.children = add_snippet_symbol(create_slot(name));
113+
this.$$d.children = create_slot(name);
114+
$$slots.default = true;
115115
} else {
116116
$$slots[name] = create_slot(name);
117117
}

packages/svelte/src/internal/client/validate.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { is_snippet } from './dom/blocks/snippet.js';
21
import { untrack } from './runtime.js';
32
import { get_descriptor, is_array } from './utils.js';
43
import * as e from './errors.js';

packages/svelte/src/internal/server/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import {
1010
} from '../../constants.js';
1111
import { escape_html } from '../../escaping.js';
1212
import { DEV } from 'esm-env';
13-
14-
export * from '../client/validate.js';
15-
export { add_snippet_symbol } from '../client/dom/blocks/snippet.js';
16-
export { default_slot } from '../client/dom/legacy/misc.js';
1713
import { current_component, pop, push } from './context.js';
1814
import { BLOCK_CLOSE, BLOCK_OPEN } from './hydration.js';
1915
import { validate_store } from '../shared/validate.js';
@@ -280,8 +276,9 @@ export function spread_attributes(attrs, lowercase_attributes, is_html, class_ha
280276
for (let i = 0; i < attrs.length; i++) {
281277
const obj = attrs[i];
282278
for (key in obj) {
283-
// omit functions
284-
if (typeof obj[key] !== 'function') {
279+
// omit functions and internal svelte properties
280+
const prefix = key[0] + key[1]; // this is faster than key.slice(0, 2)
281+
if (typeof obj[key] !== 'function' && prefix !== '$$') {
285282
merged_attrs[key] = obj[key];
286283
}
287284
}
@@ -626,10 +623,13 @@ export function once(get_value) {
626623
export { push, pop } from './context.js';
627624

628625
export {
626+
add_snippet_symbol,
629627
validate_component,
630628
validate_dynamic_element_tag,
631629
validate_snippet,
632630
validate_void_dynamic_element
633631
} from '../shared/validate.js';
634632

635633
export { escape_html as escape };
634+
635+
export { default_slot } from '../client/dom/legacy/misc.js';

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ export default function Function_prop_no_getter($$anchor) {
1616
onmousedown: () => $.set(count, $.get(count) + 1),
1717
onmouseup,
1818
onmouseenter: () => $.set(count, $.proxy(plusOne($.get(count)))),
19-
children: $.add_snippet_symbol(($$anchor, $$slotProps) => {
19+
children: ($$anchor, $$slotProps) => {
2020
var text = $.text($$anchor);
2121

2222
$.template_effect(() => $.set_text(text, `clicks: ${$.stringify($.get(count))}`));
2323
$.append($$anchor, text);
24-
})
24+
},
25+
$$slots: { default: true }
2526
});
2627

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

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export default function Function_prop_no_getter($$payload, $$props) {
1717
onmousedown: () => count += 1,
1818
onmouseup,
1919
onmouseenter: () => count = plusOne(count),
20-
children: $.add_snippet_symbol(($$payload, $$slotProps) => {
20+
children: ($$payload, $$slotProps) => {
2121
$$payload.out += `clicks: ${$.escape(count)}`;
22-
})
22+
},
23+
$$slots: { default: true }
2324
});
2425

2526
$$payload.out += `<!--]-->`;

0 commit comments

Comments
 (0)