Skip to content

Reactive declaration on a store, caused by a change in another store from another component is not called #5365

Closed
@lovetoast

Description

@lovetoast

Describe the bug

ComponentA setting the value of a store (call it store1), which calls a function in ComponentB as it is dependent on this store. The function in componentB sets the value of another store (call it store2) and has a reactive declaration for store2 (just a console log, or anything else for that matter), the reactive declaration is NOT called.

This appears to be because the initial trigger is from ComponentA. If I update store2 from ComponentB, it calls the reactive declaration on store2.

To Reproduce

Please click here:

https://svelte.dev/repl/f51251e28e1a42d292de15b1a6079476?version=3.24.1

Top.svelte sets setCategory (type the value in the text field and hit SetCat and it updates it). Annoying.svelte listens for this and calls on onSetCat, which console logs (to make sure it's running) and then sets setSearch, which should show an alert, but it does not (only shows on page load, when the value is set from stores.js. There is a button in Annoying.svelte, called try locally, and this DOES trigger the reactive declaration. I've included commented code for a traditional subscribe function, to show it does not work with this either.

Information about your Svelte project:

  • Version 85.0.4183.83 (Official Build) (64-bit)

  • Windows 10

  • Reproduced on repl which I believe is the latest?

Severity

Umm going to be honest, I like this bug, because it actually makes my live search function work a bit better, but hey, I'm an honest guy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions