Skip to content

Commit a422d2a

Browse files
tanhauhauConduitry
authored andcommitted
fix actions having no access to parent nodes (#4252)
1 parent 3d9655a commit a422d2a

File tree

29 files changed

+88
-72
lines changed

29 files changed

+88
-72
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Prevent text input cursor jumping in Safari with one-way binding ([#3449](https://github.com/sveltejs/svelte/issues/3449))
66
* Expose compiler version in dev events ([#4047](https://github.com/sveltejs/svelte/issues/4047))
7+
* Don't run actions before their element is in the document ([#4166](https://github.com/sveltejs/svelte/issues/4166))
78
* Fix reactive assignments with destructuring and stores where the destructured value should be undefined ([#4170](https://github.com/sveltejs/svelte/issues/4170))
89
* Do not automatically declare variables in reactive declarations when assigning to a member expression ([#4212](https://github.com/sveltejs/svelte/issues/4212))
910

src/compiler/compile/render_dom/Block.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ export default class Block {
450450
this.add_variable(dispose);
451451

452452
if (this.event_listeners.length === 1) {
453-
this.chunks.hydrate.push(
453+
this.chunks.mount.push(
454454
b`${dispose} = ${this.event_listeners[0]};`
455455
);
456456

457457
this.chunks.destroy.push(
458458
b`${dispose}();`
459459
);
460460
} else {
461-
this.chunks.hydrate.push(b`
461+
this.chunks.mount.push(b`
462462
${dispose} = [
463463
${this.event_listeners}
464464
];

test/js/samples/action-custom-event-handler/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function create_fragment(ctx) {
2020
c() {
2121
button = element("button");
2222
button.textContent = "foo";
23-
dispose = action_destroyer(foo_action = foo.call(null, button, /*foo_function*/ ctx[1]));
2423
},
2524
m(target, anchor) {
2625
insert(target, button, anchor);
26+
dispose = action_destroyer(foo_action = foo.call(null, button, /*foo_function*/ ctx[1]));
2727
},
2828
p(ctx, [dirty]) {
2929
if (foo_action && is_function(foo_action.update) && dirty & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
@@ -42,7 +42,7 @@ function handleFoo(bar) {
4242
}
4343

4444
function foo(node, callback) {
45-
45+
4646
}
4747

4848
function instance($$self, $$props, $$invalidate) {

test/js/samples/action/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function create_fragment(ctx) {
2121
a = element("a");
2222
a.textContent = "Test";
2323
attr(a, "href", "#");
24-
dispose = action_destroyer(link_action = link.call(null, a));
2524
},
2625
m(target, anchor) {
2726
insert(target, a, anchor);
27+
dispose = action_destroyer(link_action = link.call(null, a));
2828
},
2929
p: noop,
3030
i: noop,

test/js/samples/bind-online/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ function create_fragment(ctx) {
1414
add_render_callback(/*onlinestatuschanged*/ ctx[1]);
1515

1616
return {
17-
c() {
17+
c: noop,
18+
m(target, anchor) {
1819
dispose = [
1920
listen(window, "online", /*onlinestatuschanged*/ ctx[1]),
2021
listen(window, "offline", /*onlinestatuschanged*/ ctx[1])
2122
];
2223
},
23-
m: noop,
2424
p: noop,
2525
i: noop,
2626
o: noop,

test/js/samples/bind-open/expected.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ function create_fragment(ctx) {
2020

2121
details.innerHTML = `<summary>summary</summary>content
2222
`;
23-
24-
dispose = listen(details, "toggle", /*details_toggle_handler*/ ctx[1]);
2523
},
2624
m(target, anchor) {
2725
insert(target, details, anchor);
2826
details.open = /*open*/ ctx[0];
27+
dispose = listen(details, "toggle", /*details_toggle_handler*/ ctx[1]);
2928
},
3029
p(ctx, [dirty]) {
3130
if (dirty & /*open*/ 1) {

test/js/samples/bindings-readonly-order/expected.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ function create_fragment(ctx) {
2626
input1 = element("input");
2727
attr(input0, "type", "file");
2828
attr(input1, "type", "file");
29-
30-
dispose = [
31-
listen(input0, "change", /*input0_change_handler*/ ctx[1]),
32-
listen(input1, "change", /*input1_change_handler*/ ctx[2])
33-
];
3429
},
3530
m(target, anchor) {
3631
insert(target, input0, anchor);
3732
insert(target, t, anchor);
3833
insert(target, input1, anchor);
34+
35+
dispose = [
36+
listen(input0, "change", /*input0_change_handler*/ ctx[1]),
37+
listen(input1, "change", /*input1_change_handler*/ ctx[2])
38+
];
3939
},
4040
p: noop,
4141
i: noop,

test/js/samples/capture-inject-dev-only/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ function create_fragment(ctx) {
2828
t0 = text(/*foo*/ ctx[0]);
2929
t1 = space();
3030
input = element("input");
31-
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
3231
},
3332
m(target, anchor) {
3433
insert(target, p, anchor);
3534
append(p, t0);
3635
insert(target, t1, anchor);
3736
insert(target, input, anchor);
3837
set_input_value(input, /*foo*/ ctx[0]);
38+
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
3939
},
4040
p(ctx, [dirty]) {
4141
if (dirty & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);

test/js/samples/component-static-var/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function create_fragment(ctx) {
3535
create_component(bar.$$.fragment);
3636
t1 = space();
3737
input = element("input");
38-
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
3938
},
4039
m(target, anchor) {
4140
mount_component(foo, target, anchor);
@@ -45,6 +44,7 @@ function create_fragment(ctx) {
4544
insert(target, input, anchor);
4645
set_input_value(input, /*z*/ ctx[0]);
4746
current = true;
47+
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
4848
},
4949
p(ctx, [dirty]) {
5050
const bar_changes = {};

test/js/samples/component-store-reassign-invalidate/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ function create_fragment(ctx) {
3131
t1 = space();
3232
button = element("button");
3333
button.textContent = "reset";
34-
dispose = listen(button, "click", /*click_handler*/ ctx[2]);
3534
},
3635
m(target, anchor) {
3736
insert(target, h1, anchor);
3837
append(h1, t0);
3938
insert(target, t1, anchor);
4039
insert(target, button, anchor);
40+
dispose = listen(button, "click", /*click_handler*/ ctx[2]);
4141
},
4242
p(ctx, [dirty]) {
4343
if (dirty & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);

test/js/samples/dont-invalidate-this/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function create_fragment(ctx) {
1717
return {
1818
c() {
1919
input = element("input");
20-
dispose = listen(input, "input", make_uppercase);
2120
},
2221
m(target, anchor) {
2322
insert(target, input, anchor);
23+
dispose = listen(input, "input", make_uppercase);
2424
},
2525
p: noop,
2626
i: noop,

test/js/samples/event-handler-dynamic/expected.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ function create_fragment(ctx) {
4242
t5 = space();
4343
button2 = element("button");
4444
button2.textContent = "click";
45-
46-
dispose = [
47-
listen(button0, "click", /*updateHandler1*/ ctx[2]),
48-
listen(button1, "click", /*updateHandler2*/ ctx[3]),
49-
listen(button2, "click", function () {
50-
if (is_function(/*clickHandler*/ ctx[0])) /*clickHandler*/ ctx[0].apply(this, arguments);
51-
})
52-
];
5345
},
5446
m(target, anchor) {
5547
insert(target, p0, anchor);
@@ -61,6 +53,14 @@ function create_fragment(ctx) {
6153
append(p1, t4);
6254
insert(target, t5, anchor);
6355
insert(target, button2, anchor);
56+
57+
dispose = [
58+
listen(button0, "click", /*updateHandler1*/ ctx[2]),
59+
listen(button1, "click", /*updateHandler2*/ ctx[3]),
60+
listen(button2, "click", function () {
61+
if (is_function(/*clickHandler*/ ctx[0])) /*clickHandler*/ ctx[0].apply(this, arguments);
62+
})
63+
];
6464
},
6565
p(new_ctx, [dirty]) {
6666
ctx = new_ctx;

test/js/samples/event-handler-no-passive/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function create_fragment(ctx) {
2020
a = element("a");
2121
a.textContent = "this should not navigate to example.com";
2222
attr(a, "href", "https://example.com");
23-
dispose = listen(a, "touchstart", touchstart_handler);
2423
},
2524
m(target, anchor) {
2625
insert(target, a, anchor);
26+
dispose = listen(a, "touchstart", touchstart_handler);
2727
},
2828
p: noop,
2929
i: noop,

test/js/samples/event-modifiers/expected.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ function create_fragment(ctx) {
3535
t3 = space();
3636
button2 = element("button");
3737
button2.textContent = "or me!";
38-
39-
dispose = [
40-
listen(button0, "click", stop_propagation(prevent_default(handleClick))),
41-
listen(button1, "click", handleClick, { once: true, capture: true }),
42-
listen(button2, "click", handleClick, true),
43-
listen(div, "touchstart", handleTouchstart, { passive: true })
44-
];
4538
},
4639
m(target, anchor) {
4740
insert(target, div, anchor);
@@ -50,6 +43,13 @@ function create_fragment(ctx) {
5043
append(div, button1);
5144
append(div, t3);
5245
append(div, button2);
46+
47+
dispose = [
48+
listen(button0, "click", stop_propagation(prevent_default(handleClick))),
49+
listen(button1, "click", handleClick, { once: true, capture: true }),
50+
listen(button2, "click", handleClick, true),
51+
listen(div, "touchstart", handleTouchstart, { passive: true })
52+
];
5353
},
5454
p: noop,
5555
i: noop,

test/js/samples/input-files/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function create_fragment(ctx) {
2020
input = element("input");
2121
attr(input, "type", "file");
2222
input.multiple = true;
23-
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
2423
},
2524
m(target, anchor) {
2625
insert(target, input, anchor);
26+
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
2727
},
2828
p: noop,
2929
i: noop,

test/js/samples/input-no-initial-value/expected.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ function create_fragment(ctx) {
3131
button.textContent = "Store";
3232
attr(input, "type", "text");
3333
input.required = true;
34-
35-
dispose = [
36-
listen(input, "input", /*input_input_handler*/ ctx[2]),
37-
listen(form, "submit", /*handleSubmit*/ ctx[1])
38-
];
3934
},
4035
m(target, anchor) {
4136
insert(target, form, anchor);
4237
append(form, input);
4338
set_input_value(input, /*test*/ ctx[0]);
4439
append(form, t0);
4540
append(form, button);
41+
42+
dispose = [
43+
listen(input, "input", /*input_input_handler*/ ctx[2]),
44+
listen(form, "submit", /*handleSubmit*/ ctx[1])
45+
];
4646
},
4747
p(ctx, [dirty]) {
4848
if (dirty & /*test*/ 1 && input.value !== /*test*/ ctx[0]) {

test/js/samples/input-range/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ function create_fragment(ctx) {
2222
c() {
2323
input = element("input");
2424
attr(input, "type", "range");
25+
},
26+
m(target, anchor) {
27+
insert(target, input, anchor);
28+
set_input_value(input, /*value*/ ctx[0]);
2529

2630
dispose = [
2731
listen(input, "change", /*input_change_input_handler*/ ctx[1]),
2832
listen(input, "input", /*input_change_input_handler*/ ctx[1])
2933
];
3034
},
31-
m(target, anchor) {
32-
insert(target, input, anchor);
33-
set_input_value(input, /*value*/ ctx[0]);
34-
},
3535
p(ctx, [dirty]) {
3636
if (dirty & /*value*/ 1) {
3737
set_input_value(input, /*value*/ ctx[0]);

test/js/samples/input-value/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ function create_fragment(ctx) {
3030
t1 = text(/*name*/ ctx[0]);
3131
t2 = text("!");
3232
input.value = /*name*/ ctx[0];
33-
dispose = listen(input, "input", /*onInput*/ ctx[1]);
3433
},
3534
m(target, anchor) {
3635
insert(target, input, anchor);
3736
insert(target, t0, anchor);
3837
insert(target, h1, anchor);
3938
append(h1, t1);
4039
append(h1, t2);
40+
dispose = listen(input, "input", /*onInput*/ ctx[1]);
4141
},
4242
p(ctx, [dirty]) {
4343
if (dirty & /*name*/ 1 && input.value !== /*name*/ ctx[0]) {

test/js/samples/input-without-blowback-guard/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function create_fragment(ctx) {
1919
c() {
2020
input = element("input");
2121
attr(input, "type", "checkbox");
22-
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
2322
},
2423
m(target, anchor) {
2524
insert(target, input, anchor);
2625
input.checked = /*foo*/ ctx[0];
26+
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
2727
},
2828
p(ctx, [dirty]) {
2929
if (dirty & /*foo*/ 1) {

test/js/samples/instrumentation-script-if-no-block/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ function create_fragment(ctx) {
3030
p = element("p");
3131
t2 = text("x: ");
3232
t3 = text(/*x*/ ctx[0]);
33-
dispose = listen(button, "click", /*foo*/ ctx[1]);
3433
},
3534
m(target, anchor) {
3635
insert(target, button, anchor);
3736
insert(target, t1, anchor);
3837
insert(target, p, anchor);
3938
append(p, t2);
4039
append(p, t3);
40+
dispose = listen(button, "click", /*foo*/ ctx[1]);
4141
},
4242
p(ctx, [dirty]) {
4343
if (dirty & /*x*/ 1) set_data(t3, /*x*/ ctx[0]);

test/js/samples/instrumentation-script-x-equals-x/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ function create_fragment(ctx) {
3131
p = element("p");
3232
t2 = text("number of things: ");
3333
t3 = text(t3_value);
34-
dispose = listen(button, "click", /*foo*/ ctx[1]);
3534
},
3635
m(target, anchor) {
3736
insert(target, button, anchor);
3837
insert(target, t1, anchor);
3938
insert(target, p, anchor);
4039
append(p, t2);
4140
append(p, t3);
41+
dispose = listen(button, "click", /*foo*/ ctx[1]);
4242
},
4343
p(ctx, [dirty]) {
4444
if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value);

test/js/samples/instrumentation-template-if-no-block/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ function create_fragment(ctx) {
3030
p = element("p");
3131
t2 = text("x: ");
3232
t3 = text(/*x*/ ctx[0]);
33-
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
3433
},
3534
m(target, anchor) {
3635
insert(target, button, anchor);
3736
insert(target, t1, anchor);
3837
insert(target, p, anchor);
3938
append(p, t2);
4039
append(p, t3);
40+
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
4141
},
4242
p(ctx, [dirty]) {
4343
if (dirty & /*x*/ 1) set_data(t3, /*x*/ ctx[0]);

test/js/samples/instrumentation-template-x-equals-x/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ function create_fragment(ctx) {
3131
p = element("p");
3232
t2 = text("number of things: ");
3333
t3 = text(t3_value);
34-
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
3534
},
3635
m(target, anchor) {
3736
insert(target, button, anchor);
3837
insert(target, t1, anchor);
3938
insert(target, p, anchor);
4039
append(p, t2);
4140
append(p, t3);
41+
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
4242
},
4343
p(ctx, [dirty]) {
4444
if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value);

0 commit comments

Comments
 (0)