Merge branch 'main' into blockless

blockless
Rich Harris 10 months ago
commit 5ae93dba79

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve ssr output of dynamic textarea elements

@ -609,6 +609,22 @@ const validation = {
error(arg, 'invalid-render-spread-argument');
}
}
const is_inside_textarea = context.path.find((n) => {
return (
n.type === 'SvelteElement' &&
n.name === 'svelte:element' &&
n.tag.type === 'Literal' &&
n.tag.value === 'textarea'
);
});
if (is_inside_textarea) {
error(
node,
'invalid-tag-placement',
'inside <textarea> or <svelte:element this="textarea">',
node.expression.name
);
}
},
SvelteHead(node) {
const attribute = node.attributes[0];

@ -1274,36 +1274,32 @@ const template_visitors = {
context.state.init.push(el_anchor);
context.state.template.push(t_expression(anchor_id));
const [inner_anchor, inner_id] = serialize_anchor(context.state);
inner_context.state.init.push(inner_anchor);
inner_context.state.template.push(t_string('<'), t_expression(tag));
serialize_element_attributes(node, inner_context);
inner_context.state.template.push(t_string('>'));
const before = serialize_template(inner_context.state.template);
const main = create_block(node, node.fragment.nodes, {
...context,
state: { ...context.state, metadata }
});
const after = serialize_template([
t_expression(inner_id),
t_string('</'),
t_expression(tag),
t_string('>')
]);
serialize_element_attributes(node, inner_context);
context.state.template.push(
t_statement(
b.if(
tag,
b.block([
...inner_context.state.init,
...before,
b.if(
b.unary('!', b.call('$.VoidElements.has', tag)),
b.block([...serialize_template([t_expression(inner_id)]), ...main, ...after])
b.stmt(
b.call(
'$.element',
b.id('$$payload'),
tag,
b.thunk(
b.block([
...inner_context.state.init,
...serialize_template(inner_context.state.template)
])
),
b.thunk(b.block(main))
)
])
)
)
),
t_expression(anchor_id)

@ -79,6 +79,31 @@ export function assign_payload(p1, p2) {
p1.anchor = p2.anchor;
}
/**
* @param {Payload} payload
* @param {string} tag
* @param {() => void} attributes_fn
* @param {() => void} children_fn
* @returns {void}
*/
export function element(payload, tag, attributes_fn, children_fn) {
payload.out += `<${tag} `;
attributes_fn();
payload.out += `>`;
if (!VoidElements.has(tag)) {
const anchor = tag !== 'textarea' ? create_anchor(payload) : null;
if (anchor !== null) {
payload.out += anchor;
}
children_fn();
if (anchor !== null) {
payload.out += anchor;
}
payload.out += `</${tag}>`;
}
}
/**
* Array of `onDestroy` callbacks that should be called at the end of the server render function
* @type {Function[]}

@ -0,0 +1,14 @@
import { test } from '../../test';
export default test({
html: '<textarea></textarea>',
test({ assert, target }) {
assert.htmlEqual(
target.innerHTML,
`
<textarea></textarea>
`
);
}
});

@ -1,12 +1,12 @@
<script>
import { Date } from 'svelte/reactivity';
let date = new Date('2024/02/23 15:00:00');
let date = new Date('2024-02-23T15:00:00Z');
</script>
<div>getSeconds: {date.getSeconds()}</div>
<div>getMinutes: {date.getMinutes()}</div>
<div>getHours: {date.getHours()}</div>
<div>getSeconds: {date.getUTCSeconds()}</div>
<div>getMinutes: {date.getUTCMinutes()}</div>
<div>getHours: {date.getUTCHours()}</div>
<div>getTime: {date.getTime()}</div>
<div>toDateString: {date.toDateString()}</div>

@ -1,4 +1,4 @@
/* index.svelte.js generated by Svelte VERSION */
import * as $ from "svelte/internal";
export const object = $.proxy({ ok: true });
export const object = $.proxy({ ok: true });

@ -1,4 +1,4 @@
/* index.svelte.js generated by Svelte VERSION */
import * as $ from "svelte/internal/server";
export const object = { ok: true };
export const object = { ok: true };

@ -9,18 +9,7 @@ export default function Svelte_element($$payload, $$props) {
const anchor = $.create_anchor($$payload);
$$payload.out += `${anchor}`;
if (tag) {
const anchor_1 = $.create_anchor($$payload);
$$payload.out += `<${tag}>`;
if (!$.VoidElements.has(tag)) {
$$payload.out += `${anchor_1}`;
$$payload.out += `${anchor_1}</${tag}>`;
}
}
if (tag) $.element($$payload, tag, () => {}, () => {});
$$payload.out += `${anchor}`;
$.bind_props($$props, { tag });
$.pop();

Loading…
Cancel
Save