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

Store does not update component in certain combination with bind + #if + store #5538

Closed
Splamy opened this issue Oct 18, 2020 · 2 comments · Fixed by #5600
Closed

Store does not update component in certain combination with bind + #if + store #5538

Splamy opened this issue Oct 18, 2020 · 2 comments · Fixed by #5600

Comments

@Splamy
Copy link

Splamy commented Oct 18, 2020

Describe the bug / To Reproduce
We encountered a weird edge case in our app where where one of the stores didn't trigger any updates in a child component sometimes.
There are multiple steps necessary for this bug to happen, so I'll try to explain it in a step-by-step way, otherwise it gets unreadable.

The step-by-step is tied to this REPL:
https://svelte.dev/repl/ae73276603ff41048ac558daae06bf4a?version=3.29.0

In the basic outline App has two childs:

  • Bind which will set displayPanel to true when $x != undefined and show Subscr
  • Subscr which subscribes to $x in code within a reactive block $:
  • And we have a global store x initialized to undefined

When clicking on start:

  1. store x is set to "1"
  2. Bind will notice this and set displayPanel to true
  3. App will notice this and render the {#if} Block
  4. Subscr will render with the store value correctly set and show E: 1
  5. store x is set to undefinded
  6. Subscr will not notice this update, even though $x is in the recative block. In fact the reactive block does not get executed at all (check the console output).
  7. Only setting $x to something that is not undefined and then setting it back to undefined the Subscr component will notice each update again.

You can see in the console log that the first set to undefined does not get noticed by the Subscr component.

Set to e
update 1
Set to undef
Set to e
update 2
Set to undef
update undefined

From my debugging it seems like Subscr has a stale value of x when it gets created but $x has the new value. When then setting x to undefined the update will not execute since the old value already is undefined. But I might be wrong here.

Also when using the $x variable in the html this problem does not occour and the store gets updated correctly. (I've added a comment in the Subscr to mark this)

Expected behavior
The reactive statement should correctly be executed with the store change.

Information about your Svelte project:

  • Your browser and the version: Firefox 81.0.2 (64-bit)
  • Your operating system: Windows 10 Education
  • Svelte version 3.29.0
  • Using rollup (but should not relevant for this case)

Severity
Low to Medium:
The bug itself can be easily work around by adding the store somewhere in the html part, but finding and debugging the cause is a nightmare.

@Conduitry
Copy link
Member

This has been fixed in 3.30.0 - https://svelte.dev/repl/ae73276603ff41048ac558daae06bf4a?version=3.30.0

@Splamy
Copy link
Author

Splamy commented Nov 25, 2020

Nice, thanks!

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

Successfully merging a pull request may close this issue.

2 participants