Skip to content

fix actions has no access to parent nodes #4252

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

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Expand Down
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 @@ -450,15 +450,15 @@ export default class Block {
this.add_variable(dispose);

if (this.event_listeners.length === 1) {
this.chunks.hydrate.push(
this.chunks.mount.push(
b`${dispose} = ${this.event_listeners[0]};`
);

this.chunks.destroy.push(
b`${dispose}();`
);
} else {
this.chunks.hydrate.push(b`
this.chunks.mount.push(b`
${dispose} = [
${this.event_listeners}
];
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/action-custom-event-handler/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function create_fragment(ctx) {
c() {
button = element("button");
button.textContent = "foo";
dispose = action_destroyer(foo_action = foo.call(null, button, /*foo_function*/ ctx[1]));
},
m(target, anchor) {
insert(target, button, anchor);
dispose = action_destroyer(foo_action = foo.call(null, button, /*foo_function*/ ctx[1]));
},
p(ctx, [dirty]) {
if (foo_action && is_function(foo_action.update) && dirty & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
Expand All @@ -42,7 +42,7 @@ function handleFoo(bar) {
}

function foo(node, callback) {

}

function instance($$self, $$props, $$invalidate) {
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/action/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ function create_fragment(ctx) {
a = element("a");
a.textContent = "Test";
attr(a, "href", "#");
dispose = action_destroyer(link_action = link.call(null, a));
},
m(target, anchor) {
insert(target, a, anchor);
dispose = action_destroyer(link_action = link.call(null, a));
},
p: noop,
i: noop,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/bind-online/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ function create_fragment(ctx) {
add_render_callback(/*onlinestatuschanged*/ ctx[1]);

return {
c() {
c: noop,
m(target, anchor) {
dispose = [
listen(window, "online", /*onlinestatuschanged*/ ctx[1]),
listen(window, "offline", /*onlinestatuschanged*/ ctx[1])
];
},
m: noop,
p: noop,
i: noop,
o: noop,
Expand Down
3 changes: 1 addition & 2 deletions test/js/samples/bind-open/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ function create_fragment(ctx) {

details.innerHTML = `<summary>summary</summary>content
`;

dispose = listen(details, "toggle", /*details_toggle_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, details, anchor);
details.open = /*open*/ ctx[0];
dispose = listen(details, "toggle", /*details_toggle_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*open*/ 1) {
Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/bindings-readonly-order/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ function create_fragment(ctx) {
input1 = element("input");
attr(input0, "type", "file");
attr(input1, "type", "file");

dispose = [
listen(input0, "change", /*input0_change_handler*/ ctx[1]),
listen(input1, "change", /*input1_change_handler*/ ctx[2])
];
},
m(target, anchor) {
insert(target, input0, anchor);
insert(target, t, anchor);
insert(target, input1, anchor);

dispose = [
listen(input0, "change", /*input0_change_handler*/ ctx[1]),
listen(input1, "change", /*input1_change_handler*/ ctx[2])
];
},
p: noop,
i: noop,
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/capture-inject-dev-only/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function create_fragment(ctx) {
t0 = text(/*foo*/ ctx[0]);
t1 = space();
input = element("input");
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, p, anchor);
append(p, t0);
insert(target, t1, anchor);
insert(target, input, anchor);
set_input_value(input, /*foo*/ ctx[0]);
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/component-static-var/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function create_fragment(ctx) {
create_component(bar.$$.fragment);
t1 = space();
input = element("input");
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
},
m(target, anchor) {
mount_component(foo, target, anchor);
Expand All @@ -45,6 +44,7 @@ function create_fragment(ctx) {
insert(target, input, anchor);
set_input_value(input, /*z*/ ctx[0]);
current = true;
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
const bar_changes = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function create_fragment(ctx) {
t1 = space();
button = element("button");
button.textContent = "reset";
dispose = listen(button, "click", /*click_handler*/ ctx[2]);
},
m(target, anchor) {
insert(target, h1, anchor);
append(h1, t0);
insert(target, t1, anchor);
insert(target, button, anchor);
dispose = listen(button, "click", /*click_handler*/ ctx[2]);
},
p(ctx, [dirty]) {
if (dirty & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/dont-invalidate-this/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function create_fragment(ctx) {
return {
c() {
input = element("input");
dispose = listen(input, "input", make_uppercase);
},
m(target, anchor) {
insert(target, input, anchor);
dispose = listen(input, "input", make_uppercase);
},
p: noop,
i: noop,
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/event-handler-dynamic/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ function create_fragment(ctx) {
t5 = space();
button2 = element("button");
button2.textContent = "click";

dispose = [
listen(button0, "click", /*updateHandler1*/ ctx[2]),
listen(button1, "click", /*updateHandler2*/ ctx[3]),
listen(button2, "click", function () {
if (is_function(/*clickHandler*/ ctx[0])) /*clickHandler*/ ctx[0].apply(this, arguments);
})
];
},
m(target, anchor) {
insert(target, p0, anchor);
Expand All @@ -61,6 +53,14 @@ function create_fragment(ctx) {
append(p1, t4);
insert(target, t5, anchor);
insert(target, button2, anchor);

dispose = [
listen(button0, "click", /*updateHandler1*/ ctx[2]),
listen(button1, "click", /*updateHandler2*/ ctx[3]),
listen(button2, "click", function () {
if (is_function(/*clickHandler*/ ctx[0])) /*clickHandler*/ ctx[0].apply(this, arguments);
})
];
},
p(new_ctx, [dirty]) {
ctx = new_ctx;
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/event-handler-no-passive/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function create_fragment(ctx) {
a = element("a");
a.textContent = "this should not navigate to example.com";
attr(a, "href", "https://example.com");
dispose = listen(a, "touchstart", touchstart_handler);
},
m(target, anchor) {
insert(target, a, anchor);
dispose = listen(a, "touchstart", touchstart_handler);
},
p: noop,
i: noop,
Expand Down
14 changes: 7 additions & 7 deletions test/js/samples/event-modifiers/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ function create_fragment(ctx) {
t3 = space();
button2 = element("button");
button2.textContent = "or me!";

dispose = [
listen(button0, "click", stop_propagation(prevent_default(handleClick))),
listen(button1, "click", handleClick, { once: true, capture: true }),
listen(button2, "click", handleClick, true),
listen(div, "touchstart", handleTouchstart, { passive: true })
];
},
m(target, anchor) {
insert(target, div, anchor);
Expand All @@ -50,6 +43,13 @@ function create_fragment(ctx) {
append(div, button1);
append(div, t3);
append(div, button2);

dispose = [
listen(button0, "click", stop_propagation(prevent_default(handleClick))),
listen(button1, "click", handleClick, { once: true, capture: true }),
listen(button2, "click", handleClick, true),
listen(div, "touchstart", handleTouchstart, { passive: true })
];
},
p: noop,
i: noop,
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/input-files/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function create_fragment(ctx) {
input = element("input");
attr(input, "type", "file");
input.multiple = true;
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, input, anchor);
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
},
p: noop,
i: noop,
Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/input-no-initial-value/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ function create_fragment(ctx) {
button.textContent = "Store";
attr(input, "type", "text");
input.required = true;

dispose = [
listen(input, "input", /*input_input_handler*/ ctx[2]),
listen(form, "submit", /*handleSubmit*/ ctx[1])
];
},
m(target, anchor) {
insert(target, form, anchor);
append(form, input);
set_input_value(input, /*test*/ ctx[0]);
append(form, t0);
append(form, button);

dispose = [
listen(input, "input", /*input_input_handler*/ ctx[2]),
listen(form, "submit", /*handleSubmit*/ ctx[1])
];
},
p(ctx, [dirty]) {
if (dirty & /*test*/ 1 && input.value !== /*test*/ ctx[0]) {
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/input-range/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ function create_fragment(ctx) {
c() {
input = element("input");
attr(input, "type", "range");
},
m(target, anchor) {
insert(target, input, anchor);
set_input_value(input, /*value*/ ctx[0]);

dispose = [
listen(input, "change", /*input_change_input_handler*/ ctx[1]),
listen(input, "input", /*input_change_input_handler*/ ctx[1])
];
},
m(target, anchor) {
insert(target, input, anchor);
set_input_value(input, /*value*/ ctx[0]);
},
p(ctx, [dirty]) {
if (dirty & /*value*/ 1) {
set_input_value(input, /*value*/ ctx[0]);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/input-value/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ function create_fragment(ctx) {
t1 = text(/*name*/ ctx[0]);
t2 = text("!");
input.value = /*name*/ ctx[0];
dispose = listen(input, "input", /*onInput*/ ctx[1]);
},
m(target, anchor) {
insert(target, input, anchor);
insert(target, t0, anchor);
insert(target, h1, anchor);
append(h1, t1);
append(h1, t2);
dispose = listen(input, "input", /*onInput*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*name*/ 1 && input.value !== /*name*/ ctx[0]) {
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/input-without-blowback-guard/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function create_fragment(ctx) {
c() {
input = element("input");
attr(input, "type", "checkbox");
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, input, anchor);
input.checked = /*foo*/ ctx[0];
dispose = listen(input, "change", /*input_change_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*foo*/ 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ function create_fragment(ctx) {
p = element("p");
t2 = text("x: ");
t3 = text(/*x*/ ctx[0]);
dispose = listen(button, "click", /*foo*/ ctx[1]);
},
m(target, anchor) {
insert(target, button, anchor);
insert(target, t1, anchor);
insert(target, p, anchor);
append(p, t2);
append(p, t3);
dispose = listen(button, "click", /*foo*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*x*/ 1) set_data(t3, /*x*/ ctx[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ function create_fragment(ctx) {
p = element("p");
t2 = text("number of things: ");
t3 = text(t3_value);
dispose = listen(button, "click", /*foo*/ ctx[1]);
},
m(target, anchor) {
insert(target, button, anchor);
insert(target, t1, anchor);
insert(target, p, anchor);
append(p, t2);
append(p, t3);
dispose = listen(button, "click", /*foo*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ function create_fragment(ctx) {
p = element("p");
t2 = text("x: ");
t3 = text(/*x*/ ctx[0]);
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, button, anchor);
insert(target, t1, anchor);
insert(target, p, anchor);
append(p, t2);
append(p, t3);
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*x*/ 1) set_data(t3, /*x*/ ctx[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ function create_fragment(ctx) {
p = element("p");
t2 = text("number of things: ");
t3 = text(t3_value);
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
},
m(target, anchor) {
insert(target, button, anchor);
insert(target, t1, anchor);
insert(target, p, anchor);
append(p, t2);
append(p, t3);
dispose = listen(button, "click", /*click_handler*/ ctx[1]);
},
p(ctx, [dirty]) {
if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value);
Expand Down
Loading