-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Environment
- Operating System:
Linux - Node Version:
v18.14.0 - Nuxt Version:
3.2.0 - Nitro Version:
2.2.2 - Package Manager:
[email protected] - Builder:
vite - User Config:
modules - Runtime Modules:
@pinia/[email protected] - Build Modules:
-
Reproduction
https://github.com/ironexdev/nuxt3-pinia-issue
- yarn
- yarn dev
Go to "/" in order to reproduce the issue using middleware.
Go to "/foo" in order to reproduce the issue using page.
Describe the bug
Hello, I have an issue with (Pinia) store value that is unexpectedly reset when I set in on the server and redirect user to another page.
When the "/" route is loaded, a middleware is triggered that sets the value of fooBarStore.code to "bar" and redirects an user to navigateTo("bar").
- Note that I also appended current value as a query parameter to show that value in store is correct before redirection
However, after the redirection, the value of fooBarStore.code is reset and on the "/bar" page, the original value "foo" is displayed instead of "bar".
Without the redirection in the middleware, everything works as expected (the value of code in fooBarStore is changed from "foo" to "bar").
My question is - is this a bug? And if so, is it a Nuxt or Pinia bug?
Middleware (middleware/foo.global.ts)
Additional context
I also added page "/foo" to the project to show that this issue also occurs when using page instead of middleware for redirection.
Page "/foo" sets value fooBarStore.code to "bar" and redirects user to "/bar" (same as the middleware).
However, after the redirection, the value of fooBarStore.code is reset and on the "/bar" page, the original value "foo" is displayed instead of "bar" (same as with the middleware).
On the "/foo" page I commented out onMounted hook, because if the app redirects user in the onMounted hook, then everything works as expected.
Logs
No response