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

Pinia store reactivity breaks with vue-router on some cases #2778

Closed
valtteriluomapareto opened this issue Sep 25, 2024 · 5 comments
Closed
Labels
upstream The fix depends on a dependency

Comments

@valtteriluomapareto
Copy link

Reproduction

https://stackblitz.com/edit/vitejs-vite-ci1v82?file=src%2Fstore.ts

Steps to reproduce the bug

I tried to reproduce the bug on StackBlitz.

The example app:
The top component has router-view and links to 3 different pages:

  1. Home page shows cumulative xp of all the users in the state, using getter "totalExperience"
  2. Select page allows to set state to Pinia store with 2 buttons
  3. State page shows the list of users in the store

Steps to reproduce the bug:

  1. Check State page, should be empty array
  2. Check Home page, total experience should be 0
  3. Go to select page, set state by clicking button
  4. Go to State page, see that array has values
  5. Go to the home page, see that total experience is still 0 -> Should be sum of the xp from the users

Expected behavior

Getter value from the store should update and show the cumulative experience of the User objects on the Home page

Actual behavior

Getter value doesn't update on the Home page

Additional information

If you remove the { path: '/state', component: HelloWorld }, from the routes array in router.ts, the getter works as expected

Also: On the production app where I first noticed this, enabling Vue DevTools in prod with __VUE_PROD_DEVTOOLS__: true, the issue was fixed. This didn't reproduce in StackBlitz example.

@filipenco92
Copy link

Hi, I have the same issue, and it started with Vue 3.5.7. With Vue 3.5.6 the Pinia getters it's working fine.

@posva posva added the upstream The fix depends on a dependency label Sep 26, 2024
@posva
Copy link
Member

posva commented Sep 26, 2024

If this happens after 3.5.6, it's likely a bug in Vue, not specific to pinia (or router). I would recommend trying to reproduce it without the router first, using pinia playground and try to recreate it with effectScope() (without pinia) to find the bug.

When looking at the changelog and other issues, I see that the behavior is similar to vuejs/core#12033

@valtteriluomapareto
Copy link
Author

Thank you for the input. The referenced core repo issue does indeed seems similar.

Unfortunately, I won’t have the time to create another reproduction of the issue myself. However, based on my tests, I can confirm that the bug appears after Vue version 3.5.6 (so in 3.5.7).

If someone else has the bandwidth to try reproducing it in a Pinia playground without Pinia and the router, that would be great.

@skirtles-code
Copy link
Contributor

A couple of bugs related to computed reactivity have been fixed in Vue 3.5.9. I just tested on StackBlitz and it seems to have fixed the problem there. Could you confirm whether this is working for you?

@posva
Copy link
Member

posva commented Sep 26, 2024

Just tested and it works again 🎉

@posva posva closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream The fix depends on a dependency
Projects
None yet
Development

No branches or pull requests

4 participants