Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 38 ยท Getting Started

DevTools and Hot Module Replacement

Inspect Pinia stores in Vue DevTools, understand pinia.state, see how timeline events and time travel work, and enable hot module replacement with acceptHMRUpdate.

A big reason to use Pinia instead of a hand-made store is the tooling. You can open your browser, look at every store, edit values live, and watch each action appear on a timeline. You can also change a store file and see the update instantly without losing the app's state. This lesson explains both features and shows what they are built on, so you can reason about them even without opening DevTools.

Vue DevTools and Pinia

Vue DevTools is the official debugging tool for Vue. It is available as a browser extension for Chrome, Edge and Firefox, and as a standalone app. When your app runs in development mode and uses Pinia, a Pinia tab appears next to the component tree. It shows:

  • Every store that has been created (a store appears once it is used for the first time)
  • State, getters and the store id, with live editing: change a value and the UI updates
  • A timeline of mutations and actions, with the arguments each action received
  • Time travel: click an earlier event to see the state as it was
flowchart LR
    A["Component calls<br/>store.addItem('Pen')"] --> B["Pinia records an event<br/>(action name + args)"]
    B --> C["State changes"]
    C --> D["Pinia records a<br/>mutation event"]
    B --> E["DevTools timeline"]
    D --> E
    E -->|"click an event"| F["Inspect the state<br/>at that moment"]

Pinia reports every action and state change to DevTools, which draws them on the timeline.

DevTools support is only active in development builds. In a production build Pinia drops the integration code, so there is no cost for your users. That is also why the live examples on this site, which use a production build, have no DevTools tab. The next examples show you what DevTools reads.

The data behind the Pinia tab

All state of all stores lives in one place: pinia.state.value, an object with one key per store id. DevTools reads and edits it, SSR serializes it, and plugins and tests can use it. You can inspect it yourself:

Peek at pinia.state

The store and pinia.state.value.user point at the same data. When you edit a field in DevTools, you are writing to this object, and every component that reads the store updates.

Time travel, explained with a stand-in

DevTools can show earlier states because Pinia reports each change. You can build a tiny version of this yourself with $subscribe, which fires after every state change. (Subscriptions get a full lesson in Subscribing to State; here it is just to demystify the timeline.)

A hand-made timeline

Real time travel is more careful: it replaces the state without adding new timeline entries. But the principle is the same, because state is plain data and every change can be observed.

Hot module replacement (HMR)

When you edit a store file in a Vite project, the browser normally reloads the whole page, and you lose whatever state you built up (a filled-in form, a cart with five items). HMR swaps just the changed code. Components hot-update automatically. For stores you add one small block at the bottom of the store file:

JavaScript
// src/stores/cart.js
import { defineStore, acceptHMRUpdate } from "pinia";

export const useCartStore = defineStore("cart", {
  state: () => ({ items: [] }),
  getters: { count: (state) => state.items.length },
  actions: {
    add(item) { this.items.push(item); },
  },
});

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useCartStore, import.meta.hot));
}

acceptHMRUpdate(useStore, hot) tells Pinia how to apply the new definition to the existing store: it keeps the current state, but replaces getters and actions with the new versions. Edit a getter, save, and the page updates, with your cart intact.

A few details:

  • import.meta.hot only exists in Vite's dev server, so the if guard keeps production builds clean (the bundler removes the block).
  • You must add the block to every store file where you want HMR. It is not automatic for a reason: Pinia cannot know what you want to keep.
  • Changing the state shape (adding a new field to state) is applied to existing state in newer versions, but if something looks stale, reload once.
  • Nuxt adds this for you through its Pinia module, so you will not write it by hand there.

Troubleshooting checklist

If the Pinia tab does not show your store:

  1. Is the app running in development mode (not a production build)?
  2. Has the store been used yet? Stores appear only after the first useXxxStore() call.
  3. Is the Vue DevTools extension up to date? Old versions had no Pinia support.
  4. Did you install the same pinia instance the components use? A second createPinia() would hide stores from the tab.

If state resets on every edit, you probably forgot acceptHMRUpdate in that store file.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. When does a store appear in the Pinia tab of Vue DevTools?

    Stores are created lazily, so they show up once a component or script calls the use function.
  2. 2. Where is all store state kept?

    pinia.state.value is the single object holding every store's state, which DevTools and SSR both use.
  3. 3. What does acceptHMRUpdate do?

    It lets you edit getters and actions and see the result without losing the live state.
  4. 4. Why is acceptHMRUpdate wrapped in if (import.meta.hot)?

    The guard keeps HMR code out of production builds because the bundler can drop it.

Summary

  • Vue DevTools has a Pinia tab for inspecting, editing and time-traveling store state.
  • DevTools integration exists only in development builds.
  • All state lives in pinia.state.value, keyed by store id.
  • acceptHMRUpdate(useStore, import.meta.hot) enables hot reload of a store while keeping its state.
  • Next, you will go deep on state: reading it, writing it and resetting it.

Next: State Basics