feat: more efficient checking for missing SSR text node (#12891)

* feat: more efficient checking for missing SSR text node

* update tests
pull/12897/head
Rich Harris 4 months ago committed by GitHub
parent b41300d58a
commit 1f99935b99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: more efficient checking for missing SSR text node

@ -30,13 +30,16 @@ export function process_children(nodes, expression, is_element, { visit, state }
if (node.type === 'Text') {
let prev = expression;
expression = () => b.call('$.sibling', prev(true));
expression = () => b.call('$.sibling', prev(false));
state.template.push(node.raw);
return;
}
}
const id = get_node_id(expression(true), state, 'text');
// if this is a standalone `{expression}`, make sure we handle the case where
// no text node was created because the expression was empty during SSR
const needs_hydration_check = sequence.length === 1;
const id = get_node_id(expression(needs_hydration_check), state, 'text');
state.template.push(' ');

@ -27,7 +27,7 @@ export default function Bind_component_snippet($$anchor) {
}
});
var text_1 = $.sibling(node, true);
var text_1 = $.sibling(node);
$.template_effect(() => $.set_text(text_1, ` value: ${$.get(value) ?? ""}`));
$.append($$anchor, fragment);

@ -9,17 +9,17 @@ export default function Main($$anchor) {
let y = () => 'test';
var fragment = root();
var div = $.first_child(fragment);
var svg = $.sibling($.sibling(div, true));
var custom_element = $.sibling($.sibling(svg, true));
var div_1 = $.sibling($.sibling(custom_element, true));
var svg = $.sibling($.sibling(div));
var custom_element = $.sibling($.sibling(svg));
var div_1 = $.sibling($.sibling(custom_element));
$.template_effect(() => $.set_attribute(div_1, "foobar", y()));
var svg_1 = $.sibling($.sibling(div_1, true));
var svg_1 = $.sibling($.sibling(div_1));
$.template_effect(() => $.set_attribute(svg_1, "viewBox", y()));
var custom_element_1 = $.sibling($.sibling(svg_1, true));
var custom_element_1 = $.sibling($.sibling(svg_1));
$.template_effect(() => $.set_custom_element_data(custom_element_1, "fooBar", y()));

@ -13,11 +13,11 @@ export default function Purity($$anchor) {
p.textContent = Math.max(min, Math.min(max, number));
var p_1 = $.sibling($.sibling(p, true));
var p_1 = $.sibling($.sibling(p));
p_1.textContent = location.href;
var node = $.sibling($.sibling(p_1, true));
var node = $.sibling($.sibling(p_1));
Child(node, { prop: encodeURIComponent(value) });
$.append($$anchor, fragment);

@ -18,11 +18,11 @@ export default function State_proxy_literal($$anchor) {
$.remove_input_defaults(input);
var input_1 = $.sibling($.sibling(input, true));
var input_1 = $.sibling($.sibling(input));
$.remove_input_defaults(input_1);
var button = $.sibling($.sibling(input_1, true));
var button = $.sibling($.sibling(input_1));
button.__click = [reset, str, tpl];
$.bind_value(input, () => $.get(str), ($$value) => $.set(str, $$value));

Loading…
Cancel
Save