-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
What problem is this solving
I have a store. I copied it to make a second store but forgot to change the name of the second store.
This resulted in very subtle bugs where store state that should never be able to be undefined
was appearing as undefined
.
It should be noted that these stores are being intentionally used in an un-strict manner where the state is being mutated directly.
store/invoices.ts
export const useStore = defineStore('invoices', () => {
store/templates.ts
export const useStore = defineStore('invoices', () => {
Proposed solution
Warn if multiple stores share the same name.
Describe alternatives you've considered
Using the Vue Dev Tools, I was able to see that only one store existed and it sometimes had the values of the first store and sometimes values from the second store.
RobinTilman, hirenm1990, wopian, Ydot19, natuan62 and 10 morelcharette, zhangenming and RAIbrahim360
Activity
feat: add warning message if store id already exists (vuejs#1394)
jamiecarter7 commentedon Aug 20, 2022
I had a simlar issue, where I had created a state variable and a function with the same name.
I was getting some 'computed' error on my nuxt project until I did some digging
themeler commentedon Sep 4, 2023
Since Vuex there is one thing in my mind that could resolve the issue with possible name duplicates. Personally I have one big enum for a whole project (with store names) but it feels like a workaround.
Maybe instead of using
string
as a store name, there could be at least an option to usesymbol
. It's description could serve as displayed store name in dev tools. That would give unique id for every store, even if the name is the same. It could still warn about duplicated names (symbol descriptions) but without failing functionally.