sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
80.34k stars 4.28k forks source link

`$effect.root` not firing in `.svelte.js` file #14544

Closed jhwz closed 9 hours ago

jhwz commented 10 hours ago

Describe the bug

When I have an $effect.root in a .svelte.js/ts file, that effect doesn't appear to properly fire when dependant state changes.

Reproduction

https://svelte.dev/playground/f4917869686e4d78901a3b3d3fd0a617?version=5.5.3

Would expect to see the console.log firing

Logs

No response

System Info

Not relevant, see playground

Severity

annoyance

dummdidumm commented 9 hours ago

$effect.root creates a new root context, but doesn itself rerun. You need to put an $effect inside: https://svelte.dev/playground/f4917869686e4d78901a3b3d3fd0a617?version=5.5.3#H4sIAAAAAAAACnVQ206DQBD9lXHSpJASsK8IJL75D65J6TJt0WWXsEOt2ey_m4Walqiv5zZzjkNdd4Q5vpBSBj7NoBqIqGmZmhgTPLSKLOavDvmrD7oAYPLjeu771J5JccD2taW_cGk0k2aLORZWDm3PldCC2643A4OTZtTs4TCYDgSmGZPlqzl9twKDVhFDiIYS1tOP6yehi-yWpovTtpo7uCD0D0V22s7MfmQ2GoyWqpUfpYtiKCuYzqbnWo202fiq1XKgjjTPRJHNrinB3Wm90Jgg04Ux52Ekn_wzzbLGcp5f3N1EdJlmCY2ns1DCynLNFLnpgRweffwU3lrR4UCS08EYjuZSLox1xW-QNNoaRakyx2g3h8pTrY_U5LBalNvFIUCwj4X28bLom_8GFpe6_C0CAAA=

jhwz commented 1 hour ago

My mistake sorry! That went straight over my head when reading the docs 😅