-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Possible edge case in devtools integration: Cannot read properties of null (reading '__VUE_DEVTOOLS_APP_RECORD_ID__') #1630
Comments
As a side note, I discourage you from doing this: const useUserStore = defineStore('user', { ... })
export const userStore = useUserStore(pinia) Instead, use the patterns shown in docs with |
+1, I encountered this when trying to use a Pinia store in a Vue Router navigation guard in a Vue 2.7 app, importing the Pinia instance from main.ts. |
I'm a bit confused by this. But how do we set the state on the store to some initial stuff (like from an API) before 'loading the app' (doing the very first new Vue()). In my code I have this:
To make an axios call to see if we are logged in or not, and store that in the store, and only then load up the very first Vue component. This way the Vue app knows from the very first moment if it has a user or not and to go to a login-page or not. I used to do this method with vuex without issues. Is it just the devtools that are having issue with this or do I have a problem in my code I didn't encounter yet? |
I'm having the same problem, is there a solution? 😥 |
I still had cases of using it outside a component without giving the instance from my main.ts. like in a router hook. Carefully looking it all through and fixing it , seemed to fix it. But now after a while it's back. |
@basuneko I wound up here because I was having a similar issue, turns out I had a I refactored your example a bit to get rid of the errors, it works exactly the same way but I got rid of these: and just did a normal import of the store:
You can see a diff here |
Sorry for digging this up awhile after you posted, but did you ever find a solution for this? This is the exact same situation I'm facing currently. |
Well, the code is working fine. For me it's in a SPA , so it's client side only. The weird errors in the devtools don't seem to hinder the app or the devtools... It just hints at a pattern that's discouraged , specially for SSR leaking . Since this is for me without SSR , i have no issue with it. I just don't see a better pattern to so this. Thinking out loud now: i want the store to have a valid 'logged in or not' state before the first route hits. If you do it later, you get a flash of the page you are visiting, and then the route guard kicking in and getting redirected to the login route after seeing a flash of something else (or some sort of loading indicator ). I didn't want that , so i refresh my logged in state before doing the first The thing is that my refreshUser call is async, it returns a promise . I basically want that promise to resolve (or error ) before attempting to create and mount the first route. I don't know if this is possible . Another completely different method is to embed that initial state data in the initial server request that returns the html to start your app . There could be a script tag with some json inside it, and pinia can maybe fetch that json data to setup initial data in a store. 'hydration'. If pinia has no automated way for this , your code in your store can do it manually as a last resort. (Use document.getElementById to find a script tag with an id, use inner text/html to get the json inside. And set your default store values depending on this object, if it all works out. But this means that your backend must generate the html dynamically . And normally i just have a static index.html. In a SSR situation - which means nuxt3 for me - i just use the pinia nuxt module. The refreshUser call is there in a nuxt middleware, which bypasses this whole problem. (do i have a valid user in the store ? Do nothing . If not, check if we called refreshUser at least once. If we did, that means we redirect to login. If we now have a valid user after calling refreshUser , continue like normal). I basically use 'user == undefined' for 'store is not initialized yet, 'user == null' for no user logged in, and otherwise we have a valid user . |
I am facing the same issue with Nuxt2. I have just one store that I try to use from the Nuxt plugin.
Leads to console errors
|
Reproduction
https://github.com/basuneko/pinia-devtools-issue
Steps to reproduce the bug
npm run serve
Expected behavior
Actual behavior
✅ Both 'bacon' and 'yolo' stores are indeed listed in the pinia devtools tab
❌ However, instead of the 🍍 messages, after a timeout, devtools spits out a bunch of errors
Additional information
Hi. I'm migrating a Vue 2, Vuex 3, vuex-module-decorators project to Pinia.
For some historic reasons, our store module files export the actual store instance and, while that seems to work with Pinia as well, it seems to break something in the devtools integration. Here's an example:
I'm following the Stores outside of components guide, and passing an instance of Pinia into
useUserStore
. Functionality-wise, this seems to work fine. I have plenty of cypress tests and they're all passing after the migration. But the devtools errors are mildly concerning.Vue 2.7.5 -> 2.7.10
Pinia 2.0.21
Devtools extension 6.2.1
Chrome 105.0.5195.52
The text was updated successfully, but these errors were encountered: