Skip to content

Commit b6e51dd

Browse files
committed
Change actions to init on mount rather than hydrate
Looking at the discussion on #1247 it sounds like this was the intended way actions would be set up to work (which is why we didn't add a `mount` lifecycle method). I *believe* this is a fix in the original implementation. Complaints in chat about this surfaced the issue. Some libraries expect the element to be in the DOM when initializing and these libraries cannot be used without any lifecycle hook. @PaulMaly is requesting this be looked at, and I agree with his assesment. What's more, this change *should* be backwards compatable. Actions which work before this change should continue working after this change.
1 parent 51c2cdd commit b6e51dd

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/compile/nodes/Element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ export default class Element extends Node {
846846
block.addVariable(name);
847847
const fn = `%actions-${action.name}`;
848848

849-
block.builders.hydrate.addLine(
849+
block.builders.mount.addLine(
850850
`${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};`
851851
);
852852

test/js/samples/action/expected-bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ var proto = {
133133
/* generated by Svelte vX.Y.Z */
134134

135135
function link(node) {
136-
136+
137137
function onClick(event) {
138138
event.preventDefault();
139139
history.pushState(null, null, event.target.href);
@@ -155,11 +155,11 @@ function create_main_fragment(component, ctx) {
155155
a = createElement("a");
156156
a.textContent = "Test";
157157
a.href = "#";
158-
link_action = link.call(component, a) || {};
159158
},
160159

161160
m(target, anchor) {
162161
insert(target, a, anchor);
162+
link_action = link.call(component, a) || {};
163163
},
164164

165165
p: noop,

test/js/samples/action/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { assign, createElement, detachNode, init, insert, noop, proto } from "svelte/shared.js";
33

44
function link(node) {
5-
5+
66
function onClick(event) {
77
event.preventDefault();
88
history.pushState(null, null, event.target.href);
@@ -25,11 +25,11 @@ function create_main_fragment(component, ctx) {
2525
a = createElement("a");
2626
a.textContent = "Test";
2727
a.href = "#";
28-
link_action = link.call(component, a) || {};
2928
},
3029

3130
m(target, anchor) {
3231
insert(target, a, anchor);
32+
link_action = link.call(component, a) || {};
3333
},
3434

3535
p: noop,

0 commit comments

Comments
 (0)