Skip to content

When passing object to Vuex's state (e.g. initState), copy it instead of changing its reference directly #946

@iFwu

Description

@iFwu

What problem does this feature solve?

In server side rendering, if you set separate initial state object outside of Vuex's constructing function, it will be referenced and all changes to it will be shared. It's very confusing when you building custom Vue SSR project using vuex.
It would be better if vuex doesn't use the outside state object's reference directly, instead, copy it to a new state object every time the vuex instance is created.

FYI, my solution is just using object spread syntax like: state: { ...initState }.

What does the proposed API look like?

If there's need to promise backward compatibility, vuex can offer a option like initWithNewContext.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions