Skip to content

updating state outside of an $effect gives a warning. #10905

@delay

Description

@delay

Describe the bug

This warning may need to be removed...

State referenced in its own scope will never update. Did you mean to reference it inside a closure?

<script>
    let name = $state("John");
    name = "Jane";
  </script>
  
  <h1>Hello {name}</h1>

This is taken directly from your examples on how to update state.

CleanShot 2024-03-24 at 11 08 18

Reproduction

<script>
    let name = $state("John");
    name = "Jane";
  </script>
  
  <h1>Hello {name}</h1>

Logs

No response

System Info

System:
    OS: macOS 14.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 703.05 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.0 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.5.0 - ~/Programming/superbuildpro/node_modules/.bin/npm
    bun: 1.0.30 - /opt/homebrew/bin/bun
  npmPackages:
    svelte: ^5.0.0-next.82 => 5.0.0-next.82

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions