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

Binding store value to a component evokes all callbacks of all of store's subscribers when the component is created #7330

Closed
pavish opened this issue Mar 2, 2022 · 2 comments

Comments

@pavish
Copy link

pavish commented Mar 2, 2022

Describe the bug

Based on the Svelte docs, the callbacks of writable store subscriptions get called on these scenarios:

  • writable value changes
  • when first subscriber subscribes

However, when we bind a store value to a component, the callbacks get called whenever the component is created, even when the component is not a first subscription to the store.

Reproduction

REPL Link: https://svelte.dev/repl/abb6864f83cc4b7f9a3e84cae74e8dad?version=3.46.4

When the REPL is opened, in the output console, you can notice the two logs:

"first-subscriber"
"names changed" Array(1)[ "value" ]

Try clicking on the 'Toggle' button, you can notice that the text names changed gets logged whenever Component is shown.

If we remove bind:names and pass names={$names}, it does not happen.

Logs

No response

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (4) arm64 unknown
    Memory: 188.52 MB / 1.94 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.19.0 - /usr/bin/node
    npm: 6.14.16 - /usr/bin/npm
  npmPackages:
    svelte: ^3.42.4 => 3.42.4

Severity

annoyance

@pavish pavish changed the title Binding a store value to a component calls all the callbacks of all of store's subscribers when the component is created Binding store value to a component evokes all callbacks of all of store's subscribers when the component is created Mar 2, 2022
@Prinzhorn
Copy link
Contributor

This is a known issue

#6298
#5689

@bluwy
Copy link
Member

bluwy commented Mar 3, 2022

Closing as duplicate of the linked issues

@bluwy bluwy closed this as completed Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants