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

Warn if two stores are defined with the same name #1394

Open
Soviut opened this issue Jun 26, 2022 · 2 comments · May be fixed by #1731
Open

Warn if two stores are defined with the same name #1394

Soviut opened this issue Jun 26, 2022 · 2 comments · May be fixed by #1731

Comments

@Soviut
Copy link
Contributor

Soviut commented Jun 26, 2022

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.

@jamiecarter7
Copy link

jamiecarter7 commented 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

@rmartins90 rmartins90 linked a pull request Oct 18, 2022 that will close this issue
@themeler
Copy link

themeler commented 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 use symbol. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants