Open rdmurphy opened 3 years ago
For me it would be unexpected if it would trigger another afterUpdate
. I see onMount
as some kind of initialisation method, that triggering other hooks depending on it's content seems inconsistent to me. Having an Angular background onMount
is similar to ngOnInit
to me, and that doesn't trigger ngOnChange
either.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The Svelte docs say that the first time afterUpdate
runs will be after the initial onMount
, but that applies to lifecycle functions run within the same component. The docs say nothing about what order lifecycle functions will run in parent and child components, so it's not clear to me what the expected behavior is. So I'm not sure if this is a bug, or working as designed.
P.S. The behavior in current Svelte is unchanged: https://svelte.dev/repl/a3a7cb61eb7b4b74aed5eb1340fd0c33?version=3.46.4
Describe the bug This may be by design, but I couldn't tell — when state changes are made within
onMount
(that would cause a component to update), these changes will not triggerafterUpdate
within any child components. It appears you can only depend onafterUpdate
triggering if a state change happens outside ofonMount
.To Reproduce https://svelte.dev/repl/a3a7cb61eb7b4b74aed5eb1340fd0c33?version=3.29.4
I would expect the
afterUpdate
logs withinCanvas.svelte
to reflect the changes made inonMount
withinApp.svelte
.Expected behavior Ideally all state/component changes would propagate. It'd make sense I think if in this scenario
afterUpdate
triggers twice.Information about your Svelte project:
Severity It was certainly a surprise! I know it's possible to hack around this with
tick()
(though I'm unsure if it makes more sense to do that inonMount
orafterUpdate
) and that may ultimately be "the answer."