Skip to content

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

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
delay opened this issue Mar 24, 2024 · 0 comments · Fixed by #11540
Closed

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

delay opened this issue Mar 24, 2024 · 0 comments · Fixed by #11540
Milestone

Comments

@delay
Copy link

delay commented Mar 24, 2024

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

@dummdidumm dummdidumm added this to the 5.0 milestone Mar 24, 2024
dummdidumm added a commit that referenced this issue May 10, 2024
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants