sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.93k stars 4.15k forks source link

reactive state seems broken #10795

Closed JonathonRP closed 7 months ago

JonathonRP commented 7 months ago

Describe the bug

I have a calendar component that use a reactive variable $state to track month to display and updating its value used to work for transitioning component to next month and previous month but now it does not, it takes two clicks of button to modify and the second time it has changed the value two times too so the effect is skipping a month.

Reproduction

I'll make a reproduction when I get time, ...

Logs

No response

System Info

svelte-motion

edge

Severity

blocking an upgrade

Rich-Harris commented 7 months ago

There is literally nothing we can do with this bug report. Come back when you have a repro

JonathonRP commented 7 months ago

There is literally nothing we can do with this bug report. Come back when you have a repro

Thank you for the quick reply, I'll be back with a repo when I get a chance I just wanted to flag it ASAP.

JonathonRP commented 7 months ago

@Rich-Harris here is a repo, there seems to be some bug with stackblitz and running but this has the component and how it is being used, so maybe the additonal context will help

https://stackblitz.com/edit/sveltejs-kit-template-default-wm32rf?file=src%2Flib%2Fcomponents%2FDateSelect.svelte

dummdidumm commented 7 months ago

Can you condense the reproduction more? Right now it's a huge template, it would be great if anything that doesn't contribute to the bug could be removed.

JonathonRP commented 7 months ago

Can you condense the reproduction more? Right now it's a huge template, it would be great if anything that doesn't contribute to the bug could be removed.

I have condensed as much as possible, I am using libraries that were working fine until the latest updates like 76/78. Hopefully that helps narrow it and the bug is the reactivity of the currentDay variable it used to work fine and update smoothly but now it updates it's value but doesn't trigger changes until second press causing skipping months.

Hope this helps, if you need anything additional let me know.

Rich-Harris commented 7 months ago

This is not an adequate reproduction. You need to whittle it down to the bare minimum that shows the bug (that means delete every module that isn't directly involved, remove Tailwind, etc etc), and you need to explain exactly how to show the buggy behaviour, and how that behaviour differs from expectations.

If you can create the repro in https://svelte-5-preview.vercel.app/ that's much better, though if it requires SvelteKit then StackBlitz is fine too.

JonathonRP commented 7 months ago

@Rich-Harris @dummdidumm, here is a repor. notice the top changes and the bottom takes two presses. the bottom worked fine before. one quick point, I tried playing with the new reactive date primitive and that didn't work at all, as in it didn't change/update the date so hope that helps narrow it down.

link

Rich-Harris commented 7 months ago

Here is a simpler repro, though I don't have time to look into it any further than this right now

JonathonRP commented 7 months ago

Here is a simpler repro, though I don't have time to look into it any further than this right now

awesome!, thank you for the time you did spend!

JonathonRP commented 7 months ago

Screenshot_20240319-234147.png

I noticed the month value is populated from a derived calling function but not as derived.by maybe that is the source of the problem?

@Rich-Harris @dummdidumm

dummdidumm commented 7 months ago

Simpler repo. Either this is something with slots or something within the component. Investigating.

Edit: This is an effect ordering bug. There's an effect which updates an array, and there's second effect which derives a value from that array. The second one should run after the first, but it's the other way around for some reason.

Edit2: Bare minimum reproducible. I have a potential fix but it breaks another thing we fixed recently.

dummdidumm commented 7 months ago

This comes down to an effect ordering issue: the $: should run in a certain order which is determined at compile-time, but they can run out of order if two variables are assigned synchronously, and variable A triggers the second $: to run before variable B triggers the first $:. Closing as duplicate of #10787