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

Svelte 5 backwards compatibility: Assigning store from props to local variable does not update subscribers #14183

Closed
fkling opened this issue Nov 6, 2024 · 4 comments · Fixed by #14195
Labels

Comments

@fkling
Copy link

fkling commented Nov 6, 2024

Describe the bug

We have the following situation: Component receives a store via prop a. The component also has a local variable b which is assigned the value of a in response to some event. However when this happens anything that accesses $b does not get updated.
I've simplified the situation in the repl linked below and what stood out to me is that b is not initialized as $.mutable_state(). So this might be less about stores and more about b not being detected as mutable.
Interestingly it works within a single component.


In our real world example we receive an observable from a SvelteKit page data loader and we assign this observable to another local variable once another promise is done loading.

This code works in Svelte 4.

Reproduction

https://svelte.dev/playground/a6ca4f7f1ed84860b98793a571f9ff4d?version=5.1.11

Logs

No response

System Info

System:
    OS: Linux 6.6 Gentoo Linux
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 29.83 GB / 62.75 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.1 - ~/.asdf/installs/nodejs/20.8.1/bin/node
    Yarn: 1.22.21 - ~/.asdf/installs/nodejs/20.8.1/bin/yarn
    npm: 10.1.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.9.2 - ~/.asdf/installs/pnpm/8.9.2/bin/pnpm
  npmPackages:
    svelte: ^5.1.9 => 5.1.9

Severity

blocking an upgrade

@trueadm
Copy link
Contributor

trueadm commented Nov 6, 2024

I've simplified the situation in the repl linked below and what stood out to me is that b is not initialized as $.mutable_state(). So this might be less about stores and more about b not being detected as mutable.
Interestingly it works within a single component.

What is b in your example?

@paoloricciuti
Copy link
Member

This is because currentStore is actually never read so while it's reassigned it's mistakenly never considered a mutable.

@paoloricciuti
Copy link
Member

Basically since that is a store you are always reading $currentStore and never currentStore. So we need to fix the logic for that.

@fkling
Copy link
Author

fkling commented Nov 6, 2024

@trueadm @paoloricciuti already mentioned it but for completeness: currentStore

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