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

$subscribe misses event when several mutations happen synchronously one after another #2819

Closed
dmytro-grablov opened this issue Nov 1, 2024 · 2 comments
Labels
📚 docs Related to documentation changes

Comments

@dmytro-grablov
Copy link

Reproduction

https://play.pinia.vuejs.org/#eNqNU01vGjEQ/SvWqhIbBWwoVSJRiGijHNpDWzU97mXZHcDEX7K9BAnx3zu2l2WTVlEOK61n3sy8efY7Zl+MofsGslk2d5XlxhMHvjFElGqzKDLviuyuUFwabT05ksbBo9cWyImsrZZkQFmlG+XBUu8GhSpUpZXDJhG06PD5VcjFKP3gmlWYtYI8l40vPdfqiizuyLFQhIR6LYAKvckH29IYUFAPhqRDfi7UKXZLk7S6F7x6wln5pUkaZKw2k+trLOhHPsbICb85SyvjgnjwII0oPeCJkPmq8V4rsqxCcxSiHYNqpHES5ixhED9nveJsmCW5RrI0dOe0QnEjq6JNoKazxDPEDFe8DJEiY/GfgpOjldXPDlXdIXh4hi7xplgNe6+1cKPS8FS29d64GWNVrRBfg+B7SxV4poxk/9Qsb+gNnTDBVwwHMa5qOLwcgxWjGuR7up+hyzGdfKK3set+2jaVoWtoekK9URbv8MrWfPNKlEpLwwXYnybc70txSiH08/cY87aBjmK1herpP/GdOyTWvyygfHvoreVLuwGf0g+PP+CA/11S6roRiH4j+RvwYTaBY4J9bVSNtHu4yPZbvGOuNn/cw8GDcuelAtGoRsRHme/fWP1Cd0qnPRUvfkMJO2PWsObqlTfja4qmhEOEJcd0Hl70q/JB2xi91noI3/OsdVXe0oqWmpHJeNwuHR01I7dtIDgzfNnpL7afdGw=

Steps to reproduce the bug

The store defines 2 properties on state. The click handler increments both of them simultaneously.
The $subscribe callback prints to the console the resulting mutation

Open the playground and open the browser console.
Click on the button

Expected behavior

either 2 log statements in the console with respective mutations
or 1 event in the console with 1 mutation, but 2 events inside, one for each changed property

Actual behavior

there is only one entry with one mutation event, for prop1.
prop2 is unreported

Additional information

If the change happened on different ticks, as shown here , both events will be reported.

This is probably similar to #992 , but I find the problem more generic.

Basically it means if I have an action that alters several state elements as shown here, my subscribers will miss some of the mutations.

Copy link
Member

posva commented Nov 1, 2024

This is because $subscribe are watchers under the hood. You can get the behavior you want by using flush: 'sync'. It's slightly less performant but that won't matter in 99% of the cases.

@posva posva closed this as completed in 40828b6 Nov 1, 2024
@posva posva added the 📚 docs Related to documentation changes label Nov 1, 2024 — with Volta.net
@dmytro-grablov
Copy link
Author

thank you for the hint

Takahiro92 added a commit to Takahiro92/pinia-business that referenced this issue Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 docs Related to documentation changes
Projects
None yet
Development

No branches or pull requests

2 participants