Calling a command inside an effect causes an infinite loop
Open
Nobody has claimed this yet.
svelte 5
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
The following triggers an infinite loop where pending_count is constantly updated.
<script>
import { mark_seen } from '$lib/foo.remote.ts';
const { params } = $props();
$effect(() => {
$inspect.trace('mark');
mark_seen(params.id);
});
</script>
Reproduction
Logs
$state pending_count 1
$state pending_count 2
$state pending_count 3
... etc
Severity
serious, but I can work around it
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduced case in src/routes/+page.svelte from the linked StackBlitz project and inspect the $effect call to mark_seen(params.id). Run the reproduction and compare its behavior with the pending_count logs. Done means the command no longer causes the effect to loop and pending_count stops increasing continuously.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100