Skip to content

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

@Soviut

Description

@Soviut
Contributor

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.

Activity

jamiecarter7

jamiecarter7 commented on Aug 20, 2022

@jamiecarter7

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

themeler commented on Sep 4, 2023

@themeler

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @Soviut@posva@jamiecarter7@themeler

      Issue actions

        Warn if two stores are defined with the same name · Issue #1394 · vuejs/pinia