Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-directives called multiple times #4781

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/compile/render_dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default class Block {
if (this.chunks.mount.length === 0) {
properties.mount = noop;
} else if (this.event_listeners.length === 0) {
properties.mount = x`function #mount(#target, #anchor) {
properties.mount = x`function #mount(#target, #anchor, #remount) {
${this.chunks.mount}
}`;
} else {
Expand Down Expand Up @@ -484,4 +484,4 @@ export default class Block {
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class AwaitBlockWrapper extends Wrapper {
const has_transitions = this.pending.block.has_intro_method || this.pending.block.has_outro_method;

block.chunks.mount.push(b`
${info}.block.m(${initial_mount_node}, ${info}.anchor = ${anchor_node});
${info}.block.m(${initial_mount_node}, ${info}.anchor = ${anchor_node}, #remount);
${info}.mount = () => ${update_mount_node};
${info}.anchor = ${anchor};
`);
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/compile/render_dom/wrappers/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default class EachBlockWrapper extends Wrapper {

block.chunks.mount.push(b`
if (${each_block_else}) {
${each_block_else}.m(${initial_mount_node}, ${initial_anchor_node});
${each_block_else}.m(${initial_mount_node}, ${initial_anchor_node}, #remount);
}
`);

Expand Down Expand Up @@ -417,7 +417,7 @@ export default class EachBlockWrapper extends Wrapper {

block.chunks.mount.push(b`
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node}, #remount);
}
`);

Expand Down Expand Up @@ -509,7 +509,7 @@ export default class EachBlockWrapper extends Wrapper {

block.chunks.mount.push(b`
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node}, #remount);
}
`);

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/compile/render_dom/wrappers/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ export default class IfBlockWrapper extends Wrapper {

if (if_exists_condition) {
block.chunks.mount.push(
b`if (${if_exists_condition}) ${name}.m(${initial_mount_node}, ${anchor_node});`
b`if (${if_exists_condition}) ${name}.m(${initial_mount_node}, ${anchor_node}, #remount);`
);
} else {
block.chunks.mount.push(
b`${name}.m(${initial_mount_node}, ${anchor_node});`
b`${name}.m(${initial_mount_node}, ${anchor_node}, #remount);`
);
}

Expand Down Expand Up @@ -427,7 +427,7 @@ export default class IfBlockWrapper extends Wrapper {

block.chunks.mount.push(
if_current_block_type_index(
b`${if_blocks}[${current_block_type_index}].m(${initial_mount_node}, ${anchor_node});`
b`${if_blocks}[${current_block_type_index}].m(${initial_mount_node}, ${anchor_node}, #remount);`
)
);

Expand Down Expand Up @@ -522,7 +522,7 @@ export default class IfBlockWrapper extends Wrapper {
const anchor_node = parent_node ? 'null' : '#anchor';

block.chunks.mount.push(
b`if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node});`
b`if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node}, #remount);`
);

if (branch.dependencies.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export default class InlineComponentWrapper extends Wrapper {

block.chunks.mount.push(b`
if (${name}) {
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'}, #remount);
}
`);

Expand Down Expand Up @@ -509,7 +509,7 @@ export default class InlineComponentWrapper extends Wrapper {
}

block.chunks.mount.push(
b`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});`
b`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'}, #remount);`
);

block.chunks.intro.push(b`
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export function claim_component(block, parent_nodes) {
block && block.l(parent_nodes);
}

export function mount_component(component, target, anchor) {
export function mount_component(component, target, anchor, remount=false) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;

fragment && fragment.m(target, anchor);
fragment && fragment.m(target, anchor, remount);

// onMount happens before the initial afterUpdate
add_render_callback(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/bind-width-height/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function create_fragment(ctx) {
div.textContent = "some content";
add_render_callback(() => /*div_elementresize_handler*/ ctx[2].call(div));
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, div, anchor);
div_resize_listener = add_resize_listener(div, /*div_elementresize_handler*/ ctx[2].bind(div));
},
Expand Down Expand Up @@ -61,4 +61,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/capture-inject-state/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function create_fragment(ctx) {
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
insert_dev(target, p, anchor);
append_dev(p, t0);
append_dev(p, t1);
Expand Down Expand Up @@ -198,4 +198,4 @@ class Component extends SvelteComponentDev {
}

export default Component;
export { moduleLiveBinding, moduleContantProps };
export { moduleLiveBinding, moduleContantProps };
4 changes: 2 additions & 2 deletions test/js/samples/collapses-text-around-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function create_fragment(ctx) {
t = text(/*foo*/ ctx[0]);
attr(p, "class", "svelte-1a7i8ec");
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, p, anchor);
append(p, t);
},
Expand Down Expand Up @@ -63,4 +63,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
6 changes: 3 additions & 3 deletions test/js/samples/component-static-array/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function create_fragment(ctx) {
c() {
create_component(nested.$$.fragment);
},
m(target, anchor) {
mount_component(nested, target, anchor);
m(target, anchor, remount) {
mount_component(nested, target, anchor, remount);
current = true;
},
p: noop,
Expand Down Expand Up @@ -51,4 +51,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
6 changes: 3 additions & 3 deletions test/js/samples/component-static-immutable/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function create_fragment(ctx) {
c() {
create_component(nested.$$.fragment);
},
m(target, anchor) {
mount_component(nested, target, anchor);
m(target, anchor, remount) {
mount_component(nested, target, anchor, remount);
current = true;
},
p: noop,
Expand Down Expand Up @@ -51,4 +51,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
6 changes: 3 additions & 3 deletions test/js/samples/component-static-immutable2/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function create_fragment(ctx) {
c() {
create_component(nested.$$.fragment);
},
m(target, anchor) {
mount_component(nested, target, anchor);
m(target, anchor, remount) {
mount_component(nested, target, anchor, remount);
current = true;
},
p: noop,
Expand Down Expand Up @@ -51,4 +51,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
6 changes: 3 additions & 3 deletions test/js/samples/component-static-var/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function create_fragment(ctx) {
input = element("input");
},
m(target, anchor, remount) {
mount_component(foo, target, anchor);
mount_component(foo, target, anchor, remount);
insert(target, t0, anchor);
mount_component(bar, target, anchor);
mount_component(bar, target, anchor, remount);
insert(target, t1, anchor);
insert(target, input, anchor);
set_input_value(input, /*z*/ ctx[0]);
Expand Down Expand Up @@ -98,4 +98,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
6 changes: 3 additions & 3 deletions test/js/samples/component-static/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function create_fragment(ctx) {
c() {
create_component(nested.$$.fragment);
},
m(target, anchor) {
mount_component(nested, target, anchor);
m(target, anchor, remount) {
mount_component(nested, target, anchor, remount);
current = true;
},
p: noop,
Expand Down Expand Up @@ -51,4 +51,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/component-store-access-invalidate/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function create_fragment(ctx) {
h1 = element("h1");
t = text(/*$foo*/ ctx[0]);
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, h1, anchor);
append(h1, t);
},
Expand Down Expand Up @@ -53,4 +53,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/css-media-query/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function create_fragment(ctx) {
div = element("div");
attr(div, "class", "svelte-1slhpfn");
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, div, anchor);
},
p: noop,
Expand All @@ -46,4 +46,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/css-shadow-dom-keyframes/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function create_fragment(ctx) {
div.textContent = "fades in";
this.c = noop;
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, div, anchor);
},
p: noop,
Expand All @@ -45,4 +45,4 @@ class Component extends SvelteElement {
}

customElements.define("custom-element", Component);
export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/data-attribute/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function create_fragment(ctx) {
attr(div0, "data-foo", "bar");
attr(div1, "data-foo", /*bar*/ ctx[0]);
},
m(target, anchor) {
m(target, anchor, remount) {
insert(target, div0, anchor);
insert(target, t, anchor);
insert(target, div1, anchor);
Expand Down Expand Up @@ -61,4 +61,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
4 changes: 2 additions & 2 deletions test/js/samples/debug-empty/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function create_fragment(ctx) {
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
insert_dev(target, h1, anchor);
append_dev(h1, t0);
append_dev(h1, t1);
Expand Down Expand Up @@ -125,4 +125,4 @@ class Component extends SvelteComponentDev {
}
}

export default Component;
export default Component;
8 changes: 4 additions & 4 deletions test/js/samples/debug-foo-bar-baz-things/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function create_each_block(ctx) {

add_location(span, file, 8, 1, 116);
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
insert_dev(target, span, anchor);
append_dev(span, t0);
insert_dev(target, t1, anchor);
Expand Down Expand Up @@ -112,9 +112,9 @@ function create_fragment(ctx) {
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
each_blocks[i].m(target, anchor, remount);
}

insert_dev(target, t0, anchor);
Expand Down Expand Up @@ -271,4 +271,4 @@ class Component extends SvelteComponentDev {
}
}

export default Component;
export default Component;
8 changes: 4 additions & 4 deletions test/js/samples/debug-foo/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function create_each_block(ctx) {

add_location(span, file, 6, 1, 82);
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
insert_dev(target, span, anchor);
append_dev(span, t0);
insert_dev(target, t1, anchor);
Expand Down Expand Up @@ -106,9 +106,9 @@ function create_fragment(ctx) {
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
m: function mount(target, anchor, remount) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
each_blocks[i].m(target, anchor, remount);
}

insert_dev(target, t0, anchor);
Expand Down Expand Up @@ -235,4 +235,4 @@ class Component extends SvelteComponentDev {
}
}

export default Component;
export default Component;
Loading