Change actions to init on mount rather than hydrate

Looking at the discussion on https://github.com/sveltejs/svelte/pull/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.
pull/1653/head
Jacob Wright 6 years ago
parent 51c2cddd90
commit b6e51ddc32

@ -846,7 +846,7 @@ export default class Element extends Node {
block.addVariable(name); block.addVariable(name);
const fn = `%actions-${action.name}`; const fn = `%actions-${action.name}`;
block.builders.hydrate.addLine( block.builders.mount.addLine(
`${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};` `${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};`
); );

@ -155,11 +155,11 @@ function create_main_fragment(component, ctx) {
a = createElement("a"); a = createElement("a");
a.textContent = "Test"; a.textContent = "Test";
a.href = "#"; a.href = "#";
link_action = link.call(component, a) || {};
}, },
m(target, anchor) { m(target, anchor) {
insert(target, a, anchor); insert(target, a, anchor);
link_action = link.call(component, a) || {};
}, },
p: noop, p: noop,

@ -25,11 +25,11 @@ function create_main_fragment(component, ctx) {
a = createElement("a"); a = createElement("a");
a.textContent = "Test"; a.textContent = "Test";
a.href = "#"; a.href = "#";
link_action = link.call(component, a) || {};
}, },
m(target, anchor) { m(target, anchor) {
insert(target, a, anchor); insert(target, a, anchor);
link_action = link.call(component, a) || {};
}, },
p: noop, p: noop,

Loading…
Cancel
Save