diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index f5bd0af8da..cab004bf9f 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -1890,7 +1890,8 @@ export const template_visitors = { ? b.literal(null) : b.thunk(/** @type {Expression} */ (visit(node.expression))); - state.init.push( + // in after_update to ensure it always happens after bind:this + state.after_update.push( b.stmt( b.call( '$.animation', @@ -1922,7 +1923,8 @@ export const template_visitors = { args.push(b.thunk(/** @type {Expression} */ (visit(node.expression)))); } - state.init.push(b.stmt(b.call('$.transition', ...args))); + // in after_update to ensure it always happens after bind:this + state.after_update.push(b.stmt(b.call('$.transition', ...args))); }, RegularElement(node, context) { /** @type {import('#shared').SourceLocation} */ diff --git a/packages/svelte/tests/runtime-runes/samples/bind-this-order/_config.js b/packages/svelte/tests/runtime-runes/samples/bind-this-order/_config.js new file mode 100644 index 0000000000..1f1aadeb6d --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/bind-this-order/_config.js @@ -0,0 +1,13 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + mode: ['client'], + async test({ assert, target }) { + const btn = target.querySelector('button'); + + btn?.click(); + flushSync(); + assert.htmlEqual(target.innerHTML, ` `); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/bind-this-order/main.svelte b/packages/svelte/tests/runtime-runes/samples/bind-this-order/main.svelte new file mode 100644 index 0000000000..2d0d18df5e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/bind-this-order/main.svelte @@ -0,0 +1,15 @@ + + + + +{#if show} + + +{/if}