Files
fuel-price/.agents/skills/pinia/references/advanced-hmr.md
Ovidiu U 4a3ce4cc1d
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
docs: add advanced skills for Vitest, Pinia, and Vue built-ins
Add comprehensive reference documentation for:
- Vitest: environments, projects/workspaces, type testing, vi utilities
- Pinia: HMR, Nuxt integration, SSR setup
- Vue: built-in components (Transition, Teleport, Suspense, KeepAlive) and advanced directives
2026-04-11 16:28:36 +01:00

1.4 KiB

name, description
name description
hot-module-replacement Enable HMR to preserve store state during development

Hot Module Replacement (HMR)

Pinia supports HMR to edit stores without page reload, preserving existing state.

Setup

Add this snippet after each store definition:

import { defineStore, acceptHMRUpdate } from 'pinia'

export const useAuth = defineStore('auth', {
  // store options...
})

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

Setup Store Example

import { defineStore, acceptHMRUpdate } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const increment = () => count.value++
  return { count, increment }
})

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

Bundler Support

  • Vite: Officially supported via import.meta.hot
  • Webpack: Uses import.meta.webpackHot
  • Any bundler implementing the import.meta.hot spec should work

Nuxt

With @pinia/nuxt, acceptHMRUpdate is auto-imported but you still need to add the HMR snippet manually.

Benefits

  • Edit store logic without losing state
  • Add/remove state, actions, and getters on the fly
  • Faster development iteration