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

component with transition directive didn't update correctly when store updated #4696

Open
kjj6198 opened this issue Apr 20, 2020 · 2 comments

Comments

@kjj6198
Copy link
Contributor

kjj6198 commented Apr 20, 2020

Describe the bug

When store get updated, I found component with transition directive won't update. It only happens when:

  • store.update() inside Promise then() block, if I move store.update() call to outside, it works as expected.
  • transition directive was added in component.

To Reproduce

demo

  1. click tab2 button, text should be updated to Hello Tab2 (can check console for store detail)
  2. click tab1 button again
  3. click tab2 button again, it now updates.

work around

  • go to Title.svelte, remove transition:fade, rerun it
  • move store.update() outside of then(), rerun it.

Expected behavior
text should be updated.

Severity
small.

@kjj6198
Copy link
Contributor Author

kjj6198 commented Apr 29, 2020

Not sure if it's helpful but I found if I change Promise.resolve() to new Promise(resolve => ...) it seems to work.

+$: $store[currentTab] !== 'LOADED' && new Promise(resolve => {...})
-$: $store[currentTab] !== 'LOADED' && Promise.resolve(...)

You can check repl here.

@markoboy
Copy link

markoboy commented May 8, 2020

Hello,

That's not exactly a resolution as you are setting a timeout in order to wait for the promise to resolve. The codes provided are slightly different, as the first snippet resolves immediately, but the second one has a timeout with 1s delay. If you set the delay to 0ms it would behave the same.

The issue is that you are updating the currentTab before the store has been updated, so when the if statment passes the condition, it will not update the children because the currentTab variable is not being reassinged.

A solution to that would be to either create a store that will store the currentTab as well as the loading. Or based on the current code with a small tweek if you add this reactive value:

$: current = $store[currentTab] === 'LOADED' && currentTab;

And update the template:

<Title title={`Hello ${current}`}>
	<caption slot="caption">{current}</caption>
</Title>

This would update the children because the current variable will be updated when the store is updated resulting in updating the view.

You can check the repl here.

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

Successfully merging a pull request may close this issue.

5 participants