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

Derived store from multiple stores won't get update #3116

Closed
trongthanh opened this issue Jun 25, 2019 · 1 comment
Closed

Derived store from multiple stores won't get update #3116

trongthanh opened this issue Jun 25, 2019 · 1 comment
Labels

Comments

@trongthanh
Copy link

trongthanh commented Jun 25, 2019

I'm experiencing a bug on my application that is very hard to reproduce to a minimal case on REPL. Anyway, after few hours of tweaking, I am able to make it happen on REPL and realize what's going on.

This bug happen to Svelte 3.5.4

REPL: https://svelte.dev/repl/012883fabed9405fab808be3fd613d5c?version=3.5.4

What does not work: Notice derived multi-store will not update and return initial value forever.

In summary:

// the source stores:
storeA = writable({counter: 0, name: 'Thanh'})
storeB = derived(storeA, $storeA => $storeA.name)

// somewhere down the path: increase counter, but name never change
storeA.update(current => {...current, counter: current.counter + 1});

// the troubled store:
storeC = derived([storeA, storeB], ([$storeA, $storeB]) => {
  // should compute stuff when either storeA or storeB updates, but it never update
});

Interestingly, it was working previously with older version of Svelte, specifically, 3.2.1 from my yarn.lock: https://svelte.dev/repl/012883fabed9405fab808be3fd613d5c?version=3.2.1

After reproducing this, I realize that deriving from storeA is enough because storeB also derive from it. (And that's my current work around).

If storeB is a readable from another value, this bug won't happen.

@Conduitry Conduitry added the bug label Jul 28, 2019
@Conduitry
Copy link
Member

#3191 was actually a duplicate of this. Fixed in 3.6.9.

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

No branches or pull requests

2 participants