doc/development/fe_guide/state_management.md
At GitLab we support two solutions for client state management: Apollo and Pinia. It is non-trivial to pick either of these as your primary state manager. This page should provide you with general guidance on how to make this choice.
You may also see Vuex in the GitLab codebase. Vuex is deprecated in GitLab and no new Vuex stores should be created. If your app has a Vuex store, consider migrating.
Data is information that user interacts with. It usually comes from external requests (GraphQL or REST) or from the page itself.
State stores information about user or system interactions.
For example any flag is considered state: isLoading, isFormVisible, etc.
State management could be used to work with both state and data.
You should prefer using the standard Vue data flow in your application first: components define local state and pass it down through props and change it through events.
However this might not be sufficient for complex cases where state is shared between multiple components that are not direct descendants of the component which defined this state. You might consider hoisting that state to the root of your application, but that eventually bloats the root component because it starts to do too many things at once.
To deal with that complexity you can use a state management solution. The sections below will help you with this choice. If you're still uncertain, prefer using Apollo before Pinia.
Apollo, our primary interface to GraphQL API, can also be used as a client-side state manager. Learn more about GraphQL and Apollo.
Pinia is the client-side state management tool Vue recommends. Learn more about Pinia at GitLab.
We recommend you pick either Apollo or Pinia as the only state manager in your app. Combining them is not recommended because:
However there may be cases when it's OK to combine these two to seek specific benefits from both solutions:
If you have to use both Apollo and Pinia, follow these rules:
You can have Apollo data management in your components alongside existing Pinia state when you both:
Don't try to manage client state (not to be confused with GraphQL or REST data) with Apollo and Pinia at the same time, consider migrating from Pinia to Apollo if you need this. Don't use Apollo inside Pinia stores.
Strongly consider using Apollo for client-side state management first. However, if all of the following are true, Apollo might not be the best tool for managing this client-side state:
Vuex is deprecated in GitLab, use the guidance above to pick either Apollo or Pinia as your primary state manager. Follow the corresponding migration guide: Apollo or Pinia. Do not add new Pinia stores on top of the existing Vuex store, migrate first.