From 2ca9a816799485e0fc932d8bb86ff03df71d5cad Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Sat, 19 Oct 2024 14:11:55 +0100 Subject: [PATCH] fix: ensure user effects are correctly executed on initialisation (#13697) --- .changeset/brave-rivers-jam.md | 5 +++++ .../src/internal/client/reactivity/effects.js | 3 +-- .../samples/effect-order-5/_config.js | 7 +++++++ .../samples/effect-order-5/main.svelte | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/brave-rivers-jam.md create mode 100644 packages/svelte/tests/runtime-runes/samples/effect-order-5/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/effect-order-5/main.svelte diff --git a/.changeset/brave-rivers-jam.md b/.changeset/brave-rivers-jam.md new file mode 100644 index 0000000000..c8dcd42c0d --- /dev/null +++ b/.changeset/brave-rivers-jam.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure user effects are correctly executed on initialisation diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index 193c6df145..6e24ce5724 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -192,8 +192,7 @@ export function user_effect(fn) { // until the component is mounted var defer = active_effect !== null && - (active_effect.f & RENDER_EFFECT) !== 0 && - // TODO do we actually need this? removing them changes nothing + (active_effect.f & BRANCH_EFFECT) !== 0 && component_context !== null && !component_context.m; diff --git a/packages/svelte/tests/runtime-runes/samples/effect-order-5/_config.js b/packages/svelte/tests/runtime-runes/samples/effect-order-5/_config.js new file mode 100644 index 0000000000..2067a5b3dd --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/effect-order-5/_config.js @@ -0,0 +1,7 @@ +import { test } from '../../test'; + +export default test({ + async test({ assert, logs }) { + assert.deepEqual(logs, ['effect 1', 'effect 2']); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/effect-order-5/main.svelte b/packages/svelte/tests/runtime-runes/samples/effect-order-5/main.svelte new file mode 100644 index 0000000000..986cb8d72b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/effect-order-5/main.svelte @@ -0,0 +1,15 @@ + + +{template()}