Skip to content

Runes: $effect in *.svelte.js files is a footgun #9265

Closed
@WaltzingPenguin

Description

@WaltzingPenguin

Describe the problem

$effect looks like $dervied, $state, and store.subscribe but has all the pitfalls of get_context. There are very tight restrictions about when and where one can call functions containing $effect.

Examples of things that look like they should work:
Object instantiation
Singleton patterns

The first at least errors at runtime. That second one is much worse: it will provide no errors or warning, it just will work incorrectly.

Describe the proposed solution

If $effect remains tightly coupled to the component life cycle, it should look tightly coupled to the component.

Alternatives considered

  • Update documentation to make restrictions about using $effect more explicit
  • Replace the current implementation of $effect with an interface mimicking store subscriptions, forcing the end user to handle unsubscribing at the appropriate time.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions