Skip to content
New issue

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

By clicking “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? Sign in to your account

5.0.0-next.227: Reading $state in script tags does not return the current value if the variable is not referenced outside of script tags #13022

Closed
lts20050703 opened this issue Aug 25, 2024 · 5 comments · Fixed by #13026
Labels
Milestone

Comments

@lts20050703
Copy link

Describe the bug

5.0.0-next.227: Reading $state in script tags does not return the current value if the variable is not referenced outside of script tags

Downgrading to 5.0.0-next.226 and it works again.

Reproduction

Reproduction: https://www.sveltelab.dev/q619bx8mtraspmd

The number printed to the console is always 0

... unless the variable is referenced outside of script tag (https://www.sveltelab.dev/7r3mc9ydsw6heco)

Downgrading to 5.0.0-next.225 and it works again, no need to reference the variable outside of script tag (https://www.sveltelab.dev/8nijtfv76v7wjz8)

Logs

No response

System Info

System:
    OS: Linux 6.8 KDE neon 6.1 6.0
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 8.22 GB / 15.41 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.6.0 - ~/.local/share/pnpm/node
    Yarn: 1.22.22 - ~/.local/share/pnpm/yarn
    npm: 10.8.2 - ~/.local/share/pnpm/npm
    pnpm: 9.7.1 - ~/.local/share/pnpm/pnpm
    bun: 1.1.16 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 128.1.69.153
  npmPackages:
    svelte: ^5.0.0-next.238 => 5.0.0-next.238

Severity

annoyance

@brunnerh
Copy link
Member

Preview REPL repro

@dummdidumm dummdidumm added this to the 5.0 milestone Aug 25, 2024
@dummdidumm
Copy link
Member

dummdidumm commented Aug 26, 2024

Simpler reproduction. Caused by #12916, and a result of not mutating the underlying data:

  • .length is called after new items are added to the array
  • ... but if .length wasn't called previously, it doesn't contain any related source entry at that point in time, and thus a new one is created, but using the initial value of the underlying object, which is 0 because the new array entries were not written through

Related bug: entry signals are not updated correctly when resetting length

@lts20050703
Copy link
Author

Thank you for the simpler reproduction!

However, I usually do a forEach, like foo.array.forEach((element) => {}). Does the PR also fixes this?

@dummdidumm
Copy link
Member

It should yes. You can try for yourself in this playground built from the PR branch

@lts20050703
Copy link
Author

Can confirm it works again. Thank you! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants