Skip to content
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

ensures sequential lifecycle ending in afterUpdate #3308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions src/runtime/internal/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ export function flush() {
const seen_callbacks = new Set();

do {
// first, call beforeUpdate functions
// and update components
while (dirty_components.length) {
const component = dirty_components.shift();
set_current_component(component);
update(component.$$);
}

while (binding_callbacks.length) binding_callbacks.pop()();
do {
// check dirty bindings first
while (binding_callbacks.length) binding_callbacks.pop()();

// then call beforeUpdate functions
// and update components
while (dirty_components.length) {
const component = dirty_components.shift();
set_current_component(component);
update(component.$$);
}
} while (binding_callbacks.length);

// then, once components are updated, call
// afterUpdate functions. This may cause
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
html: `<div>bind</div>`,

async test({ assert, component, target }) {
assert.equal(component.ref, target.querySelector('div'));
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');

while (component.hooks.length) component.hooks.pop();

component.bind = false;
assert.equal(component.ref, null);
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');

while (component.hooks.length) component.hooks.pop();

component.bind = true;
assert.equal(component.ref, target.querySelector('div'));
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
// adapted from https://svelte.dev/repl/8a96e6e545244bff9fd0125b152d6840?version=3.6.9
import { afterUpdate, beforeUpdate, onMount } from 'svelte';

export let ref = null, bind = true, hooks = [];

// using push to not make hooks reactive
beforeUpdate(() => hooks.push('Before'))
afterUpdate(() => hooks.push('After'))
onMount(() => hooks.push('Mount'))
</script>

{#if bind}
<div bind:this={ref}>bind</div>
{/if}