Skip to content

Strange sequence of calling lifecycle functions (beforeUpdate) #3181

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

Closed
a3con opened this issue Jul 5, 2019 · 1 comment
Closed

Strange sequence of calling lifecycle functions (beforeUpdate) #3181

a3con opened this issue Jul 5, 2019 · 1 comment

Comments

@a3con
Copy link

a3con commented Jul 5, 2019

Continuing issues #2281. When rendering a list of nested components (A, B, C) and calling beforeUpdate, onMount, afterUpdate in each of them, all beforeUpdate calls occur first and in reverse order (I think this is unintuitive). Calls onMount and afterUpdate are predictable.

Here's a repro: https://svelte.dev/repl/0e2b1e068bb9431fa9f5e2827b552ff3?version=3.6.4

@antony antony added the question label Feb 1, 2020
@antony
Copy link
Member

antony commented Feb 1, 2020

This would be a breaking change to modify now, but I think from my point of view at least it makes sense. My reasoning is that beforeUpdate isn't part of the render lifecycle, and is called after the component is loaded, but before any state exists/changes. onMount is then called as the components mount in the DOM, and then afterUpdate is called because the state is modified as part of the component's mount sequence.

I think it's one of those things that would benefit from documentation, but is probably working in the intended way.

@antony antony closed this as completed Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants