reset more conservatively

pull/12335/head
Rich Harris 2 years ago
parent 1d9fd22924
commit 56d87083a4

@ -2189,8 +2189,11 @@ export const template_visitors = {
{ ...context, state: child_state }
);
// TODO only do this when necessary
child_state.init.push(b.stmt(b.call('$.reset', context.state.node)));
// If `hydrate_node` is set inside the element, we need to reset it
// after the element has been hydrated
if (trimmed.some((node) => node.type !== 'Text')) {
child_state.init.push(b.stmt(b.call('$.reset', context.state.node)));
}
if (has_declaration) {
context.state.init.push(

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

@ -6,6 +6,5 @@ var root = $.template(`<h1>hello world</h1>`);
export default function Hello_world($$anchor) {
var h1 = root();
$.reset(h1);
$.append($$anchor, h1);
}

@ -6,7 +6,6 @@ var root = $.template(`<h1>hello world</h1>`);
function Hmr($$anchor) {
var h1 = root();
$.reset(h1);
$.append($$anchor, h1);
}

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

Loading…
Cancel
Save