-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
While working on #6920, I discovered that the order of calling afterUpdate
callbacks is inconsistent. During initial component mounting, afterUpdate
callbacks from child components will be called before afterUpdate
callbacks from parent components. But during updates that happen after mounting (e.g., adding 1 to a count variable), the afterUpdate
callbacks from parent components are called first, then afterUpdate
callbacks from child components are called later.
This may or may not be intended behavior, but it seems strange to me that the callback order is different at mount time vs. when "regular" updates happen.
Reproduction
https://svelte.dev/repl/4b285f9150ed4812a7205291e10b3b86?version=3.44.2
Expected:
"Registering callbacks in parent"
"Parent beforeUpdate, count is 0"
"Registering callbacks in child #1"
"Child #1 beforeUpdate, count is 0"
"Registering callbacks in child #2"
"Child #2 beforeUpdate, count is 0"
"Child #1 onMount"
"Child #1 afterUpdate, count is 0"
"Child #2 onMount"
"Child #2 afterUpdate, count is 0"
"Parent onMount"
"Parent afterUpdate, count is 0"
(At this point I clicked the "Add 1 to count" button)
"Parent beforeUpdate, count is 1"
"Child #1 beforeUpdate, count is 1"
"Child #2 beforeUpdate, count is 1"
"Child #1 afterUpdate, count is 1"
"Child #2 afterUpdate, count is 1"
"Parent afterUpdate, count is 1"
Actual: almost identical to what I expected to see, except for the last three lines, which were:
"Parent afterUpdate, count is 1"
"Child #1 afterUpdate, count is 1"
"Child #2 afterUpdate, count is 1"
See Logs section below for the full logs from the Svelte REPL console.
Logs
"Registering callbacks in parent"
"Parent beforeUpdate, count is 0"
"Registering callbacks in child #1"
"Child #1 beforeUpdate, count is 0"
"Registering callbacks in child #2"
"Child #2 beforeUpdate, count is 0"
"Child #1 onMount"
"Child #1 afterUpdate, count is 0"
"Child #2 onMount"
"Child #2 afterUpdate, count is 0"
"Parent onMount"
"Parent afterUpdate, count is 0"
(At this point I clicked the "Add 1 to count" button)
"Parent beforeUpdate, count is 1"
"Child #1 beforeUpdate, count is 1"
"Child #2 beforeUpdate, count is 1"
"Parent afterUpdate, count is 1"
"Child #1 afterUpdate, count is 1"
"Child #2 afterUpdate, count is 1"
System Info
REPL. Svelte version 3.44.2.
Severity
annoyance