Skip to content

Commit

Permalink
fix: ensure user effects are correctly executed on initialisation (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Oct 19, 2024
1 parent ae10f4d commit 2ca9a81
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-rivers-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure user effects are correctly executed on initialisation
3 changes: 1 addition & 2 deletions packages/svelte/src/internal/client/reactivity/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
async test({ assert, logs }) {
assert.deepEqual(logs, ['effect 1', 'effect 2']);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
$effect.pre(() => {
$effect(() => {
console.log('effect 1')
})
})
function template() {
$effect(() => {
console.log('effect 2')
});
}
</script>

{template()}

0 comments on commit 2ca9a81

Please sign in to comment.