Skip to content

Commit 07fc7d7

Browse files
committed
omit props from SSR output, fix now-erroneous warning
1 parent 58f0029 commit 07fc7d7

File tree

7 files changed

+28
-38
lines changed

7 files changed

+28
-38
lines changed

packages/svelte/messages/compile-warnings/template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
## attribute_quoted
1818

19-
> Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes
19+
> Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes
2020
2121
## bind_invalid_each_rest
2222

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/attribute.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export function validate_attribute(attribute, parent) {
3131
attribute.value[0].type === 'ExpressionTag' &&
3232
(parent.type === 'Component' ||
3333
parent.type === 'SvelteComponent' ||
34-
parent.type === 'SvelteSelf' ||
35-
(parent.type === 'RegularElement' && is_custom_element_node(parent)))
34+
parent.type === 'SvelteSelf')
3635
) {
3736
w.attribute_quoted(attribute);
3837
}

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
is_content_editable_binding,
2525
is_load_error_element
2626
} from '../../../../../../utils.js';
27+
import { is_array } from '../../../../../../internal/shared/utils.js';
2728

2829
const WHITESPACE_INSENSITIVE_ATTRIBUTES = ['class', 'style'];
2930

@@ -239,16 +240,18 @@ export function build_element_attributes(node, context) {
239240
continue;
240241
}
241242

242-
const name = get_attribute_name(node, attribute, context);
243-
const value = build_attribute_value(
244-
attribute.value,
245-
context,
246-
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
247-
);
243+
if (is_array(attribute.value) || !node.name.includes('-')) {
244+
const name = get_attribute_name(node, attribute, context);
245+
const value = build_attribute_value(
246+
attribute.value,
247+
context,
248+
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
249+
);
248250

249-
context.state.template.push(
250-
b.call('$.attr', b.literal(name), value, is_boolean_attribute(name) && b.true)
251-
);
251+
context.state.template.push(
252+
b.call('$.attr', b.literal(name), value, is_boolean_attribute(name) && b.true)
253+
);
254+
}
252255
}
253256
}
254257

packages/svelte/src/compiler/warnings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,11 @@ export function attribute_invalid_property_name(node, wrong, right) {
701701
}
702702

703703
/**
704-
* Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes
704+
* Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes
705705
* @param {null | NodeLike} node
706706
*/
707707
export function attribute_quoted(node) {
708-
w(node, "attribute_quoted", "Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes");
708+
w(node, "attribute_quoted", "Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes");
709709
}
710710

711711
/**

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export default function Main($$anchor) {
2121

2222
var custom_element_1 = $.sibling(svg_1, 2);
2323

24-
$.template_effect(() => custom_element_1.fooBar = y());
24+
$.template_effect(() => $.set_attribute(custom_element_1, "fooBar", y()));
2525

2626
$.template_effect(() => {
2727
$.set_attribute(div, "foobar", x);
2828
$.set_attribute(svg, "viewBox", x);
29-
custom_element.fooBar = x;
29+
$.set_attribute(custom_element, "fooBar", x);
3030
});
3131

3232
$.append($$anchor, fragment);
33-
}
33+
}

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/main.svelte

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
let y = $state(() => 'test');
55
</script>
66

7-
<div fooBar={x}></div>
8-
<svg viewBox={x}></svg>
9-
<custom-element fooBar={x}></custom-element>
7+
<div fooBar="{x}"></div>
8+
<svg viewBox="{x}"></svg>
9+
<custom-element fooBar="{x}"></custom-element>
1010

1111
<!-- force them into singular render effects by using function invocations -->
12-
<div fooBar={y()}></div>
13-
<svg viewBox={y()} ></svg>
14-
<custom-element fooBar={y()}></custom-element>
12+
<div fooBar="{y()}"></div>
13+
<svg viewBox="{y()}" ></svg>
14+
<custom-element fooBar="{y()}"></custom-element>

packages/svelte/tests/validator/samples/attribute-quoted/warnings.json

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"code": "attribute_quoted",
4-
"message": "Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
4+
"message": "Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
55
"start": {
66
"column": 11,
77
"line": 13
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"code": "attribute_quoted",
28-
"message": "Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
28+
"message": "Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
2929
"start": {
3030
"column": 29,
3131
"line": 15
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"code": "attribute_quoted",
40-
"message": "Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
40+
"message": "Quoted properties on components will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
4141
"start": {
4242
"column": 14,
4343
"line": 18
@@ -46,17 +46,5 @@
4646
"column": 27,
4747
"line": 18
4848
}
49-
},
50-
{
51-
"code": "attribute_quoted",
52-
"message": "Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes",
53-
"start": {
54-
"column": 16,
55-
"line": 21
56-
},
57-
"end": {
58-
"column": 29,
59-
"line": 21
60-
}
6149
}
6250
]

0 commit comments

Comments
 (0)