Skip to content

Commit 2ca9a81

Browse files
authored
fix: ensure user effects are correctly executed on initialisation (#13697)
1 parent ae10f4d commit 2ca9a81

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.changeset/brave-rivers-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure user effects are correctly executed on initialisation

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ export function user_effect(fn) {
192192
// until the component is mounted
193193
var defer =
194194
active_effect !== null &&
195-
(active_effect.f & RENDER_EFFECT) !== 0 &&
196-
// TODO do we actually need this? removing them changes nothing
195+
(active_effect.f & BRANCH_EFFECT) !== 0 &&
197196
component_context !== null &&
198197
!component_context.m;
199198

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
async test({ assert, logs }) {
5+
assert.deepEqual(logs, ['effect 1', 'effect 2']);
6+
}
7+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
$effect.pre(() => {
3+
$effect(() => {
4+
console.log('effect 1')
5+
})
6+
})
7+
8+
function template() {
9+
$effect(() => {
10+
console.log('effect 2')
11+
});
12+
}
13+
</script>
14+
15+
{template()}

0 commit comments

Comments
 (0)