fix : no update() when tag is non-dynamic

pull/7949/head
adiguba 4 years ago
parent 7a1631843e
commit 4468e1515f

@ -280,9 +280,7 @@ export default class ElementWrapper extends Wrapper {
(x`#nodes` as unknown) as Identifier (x`#nodes` as unknown) as Identifier
); );
const previous_tag = block.get_unique_name('previous_tag');
const tag = this.node.tag_expr.manipulate(block); const tag = this.node.tag_expr.manipulate(block);
block.add_variable(previous_tag, tag);
block.chunks.init.push(b` block.chunks.init.push(b`
${this.renderer.options.dev && b`@validate_dynamic_element(${tag});`} ${this.renderer.options.dev && b`@validate_dynamic_element(${tag});`}
@ -304,63 +302,68 @@ export default class ElementWrapper extends Wrapper {
if (${this.var}) ${this.var}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'}); if (${this.var}) ${this.var}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
`); `);
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes); if (this.node.tag_expr.dynamic_dependencies().length == 0) {
const has_transitions = !!(this.node.intro || this.node.outro); block.chunks.update.push(b`if (${this.var}) ${this.var}.p(#ctx, #dirty)`);
const not_equal = this.renderer.component.component_options.immutable ? x`@not_equal` : x`@safe_not_equal`; } else {
const previous_tag = block.get_unique_name('previous_tag');
const tag_will_be_removed = block.get_unique_name('tag_will_be_removed'); block.add_variable(previous_tag, tag);
if (has_transitions) { const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
block.add_variable(tag_will_be_removed, x`false`); const has_transitions = !!(this.node.intro || this.node.outro);
} const not_equal = this.renderer.component.component_options.immutable ? x`@not_equal` : x`@safe_not_equal`;
block.chunks.update.push(b` const tag_will_be_removed = block.get_unique_name('tag_will_be_removed');
if (${tag}) { if (has_transitions) {
if (!${previous_tag}) { block.add_variable(tag_will_be_removed, x`false`);
${this.var} = ${this.child_dynamic_element_block.name}(#ctx); }
${previous_tag} = ${tag}; block.chunks.update.push(b`
${this.var}.c(); if (${tag}) {
${has_transitions && b`@transition_in(${this.var})`} if (!${previous_tag}) {
${this.var}.m(${this.get_update_mount_node(anchor)}, ${anchor}); ${this.var} = ${this.child_dynamic_element_block.name}(#ctx);
} else if (${not_equal}(${previous_tag}, ${tag})) { ${previous_tag} = ${tag};
${this.var}.d(1); ${this.var}.c();
${this.renderer.options.dev && b`@validate_dynamic_element(${tag});`} ${has_transitions && b`@transition_in(${this.var})`}
${this.renderer.options.dev && this.node.children.length > 0 && b`@validate_void_dynamic_element(${tag});`} ${this.var}.m(${this.get_update_mount_node(anchor)}, ${anchor});
${this.var} = ${this.child_dynamic_element_block.name}(#ctx); } else if (${not_equal}(${previous_tag}, ${tag})) {
${previous_tag} = ${tag}; ${this.var}.d(1);
${this.var}.c(); ${this.renderer.options.dev && b`@validate_dynamic_element(${tag});`}
${has_transitions && b`if (${tag_will_be_removed}) { ${this.renderer.options.dev && this.node.children.length > 0 && b`@validate_void_dynamic_element(${tag});`}
${tag_will_be_removed} = false; ${this.var} = ${this.child_dynamic_element_block.name}(#ctx);
@transition_in(${this.var}) ${previous_tag} = ${tag};
}`} ${this.var}.c();
${this.var}.m(${this.get_update_mount_node(anchor)}, ${anchor}); ${has_transitions && b`if (${tag_will_be_removed}) {
} else { ${tag_will_be_removed} = false;
${has_transitions && b`if (${tag_will_be_removed}) { @transition_in(${this.var})
${tag_will_be_removed} = false; }`}
@transition_in(${this.var}) ${this.var}.m(${this.get_update_mount_node(anchor)}, ${anchor});
}`} } else {
${this.var}.p(#ctx, #dirty); ${has_transitions && b`if (${tag_will_be_removed}) {
} ${tag_will_be_removed} = false;
} else if (${previous_tag}) { @transition_in(${this.var})
${ }`}
has_transitions ${this.var}.p(#ctx, #dirty);
? b` }
${tag_will_be_removed} = true; } else if (${previous_tag}) {
@group_outros(); ${
@transition_out(${this.var}, 1, 1, () => { has_transitions
? b`
${tag_will_be_removed} = true;
@group_outros();
@transition_out(${this.var}, 1, 1, () => {
${this.var} = null;
${previous_tag} = ${tag};
${tag_will_be_removed} = false;
});
@check_outros();
`
: b`
${this.var}.d(1);
${this.var} = null; ${this.var} = null;
${previous_tag} = ${tag}; ${previous_tag} = ${tag};
${tag_will_be_removed} = false; `
}); }
@check_outros();
`
: b`
${this.var}.d(1);
${this.var} = null;
${previous_tag} = ${tag};
`
} }
} `);
`); }
if (this.child_dynamic_element_block.has_intros) { if (this.child_dynamic_element_block.has_intros) {
block.chunks.intro.push(b`@transition_in(${this.var});`); block.chunks.intro.push(b`@transition_in(${this.var});`);

@ -4,7 +4,6 @@ import {
append, append,
assign, assign,
detach, detach,
empty,
get_spread_update, get_spread_update,
init, init,
insert, insert,
@ -60,44 +59,21 @@ function create_dynamic_element(ctx) {
} }
function create_fragment(ctx) { function create_fragment(ctx) {
let previous_tag = "svg";
let svelte_element1_anchor;
let svelte_element1 = "svg" && create_dynamic_element(ctx); let svelte_element1 = "svg" && create_dynamic_element(ctx);
return { return {
c() { c() {
if (svelte_element1) svelte_element1.c(); if (svelte_element1) svelte_element1.c();
svelte_element1_anchor = empty();
}, },
m(target, anchor) { m(target, anchor) {
if (svelte_element1) svelte_element1.m(target, anchor); if (svelte_element1) svelte_element1.m(target, anchor);
insert(target, svelte_element1_anchor, anchor);
}, },
p(ctx, [dirty]) { p(ctx, [dirty]) {
if ("svg") { if (svelte_element1) svelte_element1.p(ctx, dirty);
if (!previous_tag) {
svelte_element1 = create_dynamic_element(ctx);
svelte_element1.c();
svelte_element1.m(svelte_element1_anchor.parentNode, svelte_element1_anchor);
} else if (safe_not_equal(previous_tag, "svg")) {
svelte_element1.d(1);
svelte_element1 = create_dynamic_element(ctx);
svelte_element1.c();
svelte_element1.m(svelte_element1_anchor.parentNode, svelte_element1_anchor);
} else {
svelte_element1.p(ctx, dirty);
}
} else if (previous_tag) {
svelte_element1.d(1);
svelte_element1 = null;
}
previous_tag = "svg";
}, },
i: noop, i: noop,
o: noop, o: noop,
d(detaching) { d(detaching) {
if (detaching) detach(svelte_element1_anchor);
if (svelte_element1) svelte_element1.d(detaching); if (svelte_element1) svelte_element1.d(detaching);
} }
}; };

Loading…
Cancel
Save