Skip to content

Svelte 5: Introduce $effect.tick #9986

Open
@Thiagolino8

Description

@Thiagolino8

Describe the problem

Mutating state within effects is something that can cause infinite loops and should be avoided, but sometimes this is the only/most natural way to solve a problem
To solve this, reactive statements in Svelte 3/4 were only executed once per tick, which is a terrible thing to have by default but a great optional behavior

Describe the proposed solution

My suggestion is $effect.tick, a version of effect that only runs once per tick, mimicking the behavior of $: statements
Not only does this create a place where state can be mutated reactively without worrying about loops or performance issues as it facilitates migration from previous versions

Alternatives considered

Abusing untrack and asynchronous code

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions