diff --git a/package-lock.json b/package-lock.json index bcde04de2034..66dd55ef883a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.6.7", + "version": "3.6.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/runtime/internal/scheduler.ts b/src/runtime/internal/scheduler.ts index e3d7181fcbec..8d9002be1a3b 100644 --- a/src/runtime/internal/scheduler.ts +++ b/src/runtime/internal/scheduler.ts @@ -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 diff --git a/test/runtime/samples/binding-this-sequential-lifcycle-hooks/_config.js b/test/runtime/samples/binding-this-sequential-lifcycle-hooks/_config.js new file mode 100644 index 000000000000..9fc60a87f714 --- /dev/null +++ b/test/runtime/samples/binding-this-sequential-lifcycle-hooks/_config.js @@ -0,0 +1,23 @@ +export default { + html: `
bind
`, + + 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'); + } +}; diff --git a/test/runtime/samples/binding-this-sequential-lifcycle-hooks/main.svelte b/test/runtime/samples/binding-this-sequential-lifcycle-hooks/main.svelte new file mode 100644 index 000000000000..14d2f3cb36d6 --- /dev/null +++ b/test/runtime/samples/binding-this-sequential-lifcycle-hooks/main.svelte @@ -0,0 +1,15 @@ + + +{#if bind} +
bind
+{/if}