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);
const fn = `%actions-${action.name}`;
block.builders.hydrate.addLine(
block.builders.mount.addLine(
`${name} = ${fn}.call(#component, ${this.var}${snippet ? `, ${snippet}` : ''}) || {};`
);

@ -133,7 +133,7 @@ var proto = {
/* generated by Svelte vX.Y.Z */
function link(node) {
function onClick(event) {
event.preventDefault();
history.pushState(null, null, event.target.href);
@ -155,11 +155,11 @@ function create_main_fragment(component, ctx) {
a = createElement("a");
a.textContent = "Test";
a.href = "#";
link_action = link.call(component, a) || {};
},
m(target, anchor) {
insert(target, a, anchor);
link_action = link.call(component, a) || {};
},
p: noop,

@ -2,7 +2,7 @@
import { assign, createElement, detachNode, init, insert, noop, proto } from "svelte/shared.js";
function link(node) {
function onClick(event) {
event.preventDefault();
history.pushState(null, null, event.target.href);
@ -25,11 +25,11 @@ function create_main_fragment(component, ctx) {
a = createElement("a");
a.textContent = "Test";
a.href = "#";
link_action = link.call(component, a) || {};
},
m(target, anchor) {
insert(target, a, anchor);
link_action = link.call(component, a) || {};
},
p: noop,

Loading…
Cancel
Save