Replies: 2 comments 1 reply
-
I'm unsure what changed between v5.23 and v5.24 (too lazy to go check). Generally speaking, an effect re-runs whenever read state changes. You'lre creating state, but you're not reading it. Try reading it. |
Beta Was this translation helpful? Give feedback.
-
Since the change to For future readers, here’s a simple example: The following code used to cause <script lang="ts">
$effect(() => {
let dep = $state(0)
const id = setTimeout(() => dep++, 1000)
console.log("dep:", dep)
return () => clearTimeout(id)
})
</script> If you want <script lang="ts">
$effect(() => {
let dep = $state(0)
const id = setInterval(() => dep++, 1000)
$effect(() => {
console.log("dep:", dep)
})
return () => clearInterval(id)
})
</script> |
Beta Was this translation helpful? Give feedback.
-
issue: maxnowack/signaldb#1536
related: #15564
To briefly explain here as well — in Svelte 5.24.0, updates to
$state
variables created within an$effect
are no longer treated as dependencies of that$effect
. As a result, reactivity is lost in some features ofSignalDB
.On
SignalDB
, integration with svelte has code like the following ( same as guide ). In the code,cursor.fetch()
internally creates a$state
to catch changes to the database. Due to the change mentioned above, even when that$state
changes, the$effect
no longer re-runs.We're currently considering the use of createSubscriber instead of
$state
, as also suggested in maxnowack/signaldb#1536 (comment).Would this be considered an appropriate approach to handle this situation? Or is there a better solution?
Beta Was this translation helpful? Give feedback.
All reactions