pinia-plugin-subscription
| Install | |
|---|---|
npm install pinia-plugin-subscription |
|
| Latest Version: | 0.2.1 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Oct 21, 2026 |
| Links: | GitHub · npm |
pinia-plugin-subscription
Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing a Store base class for store helpers.
This project provides:
- a lightweight mechanism to declare "subscribers" that are invoked when stores are registered or updated by Pinia;
- a
Storebase class (helper wrapper) to ease interacting with Pinia stores from subscribers or other plugin code; - an API to create a Pinia plugin from a list of subscribers;
- the
$resetmethod on all stores modified by the plugin; - automatic state rollback on action failure via the
rollbackAfterFailurestore option and the$rollbackAfterFailuremethod.
Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks. For both rollback APIs, stateKeys: [] restores the full state on failure.
Tested & maintained
The package is fully tested with Vitest: runtime behavior, type-level contracts (*.test-d.ts) and performance regressions are covered, and coverage reports are available in coverage/. The full test suite and the build run on every push and pull request through GitHub Actions.
Trust & supply chain
This package is open source (MIT) and developed in a public repository. You can read, audit, fork and self-host the code at any time — no vendor lock-in, no service-continuity risk.
Development follows these practices:
- No direct pushes to
main— every change lands through a reviewed pull request (branch protection enforced). - Commits are GPG-signed and verified on GitHub.
- Tests and build gate every merge — a pull request cannot merge with a failing CI run.
- npm releases ship with provenance — each published package is built and signed on GitHub Actions and cryptographically linked to the exact commit and CI run that built it (example transparency log entry), so you can verify what you install.
- Security issues are handled privately — see SECURITY.md for the reporting process.
Documentation
The package serves two audiences:
| You want to… | Guide |
|---|---|
Use a compatible plugin (e.g. pinia-plugin-extending-store, pinia-plugin-persist-state) or this package's built-in store features (defineAStore, $reset, state rollback) in your app |
Using compatible plugins |
Build your own pinia plugin on top of pinia-plugin-subscription (API reference, Store class, import subpaths, development and testing) |
Plugin authoring guide |
| Debug stores and plugins with structured trace events | Tracing |
Installation
npm install pinia pinia-plugin-subscription
Register the plugin in your main.ts:
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPlugin } from 'pinia-plugin-subscription'
import { myStoreSubscriber } from './plugins/my-store'
import App from './App.vue'
const app = createApp(App)
const pinia = createPinia()
pinia.use(createPlugin([myStoreSubscriber]))
app.use(pinia)
app.mount('#app')
Advanced Features
- Structured tracing: Subscribe to typed trace events and filter them at runtime, per store or per namespace — see Tracing.
- Reset callbacks: Define
resetStoreCallbackto run custom logic when a store is reset. - SSR and hydration control: Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
- Lifecycle safety: Internal hydration ordering is now guarded so
hydrate()completes beforeafterHydration()and disposed stores do not retain stale subscriber metadata.
Tracing
A built-in, opt-in debugging solution: plugins and stores emit structured trace events that you select with filters, optionally redact, and group in the console. It is disabled by default in production builds and costs nothing when unused.
import { createPlugin } from 'pinia-plugin-subscription'
import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
const registry = createTracerRegistry({ redact: true })
registry.addListener([{ target: 'scope', value: 'cart' }])
pinia.use(createPlugin(subscribers, { tracerHandler: registry.tracerHandler }))
See the Tracing documentation for filtering, redaction, production safety, event shape and error reporting.
License
MIT
Publishing
Releases are published to npm via GitHub Actions. GitHub releases marked as pre-releases are published with the beta dist-tag using npm publish --tag beta; stable releases use the default latest tag. The workflow uses npm provenance for better supply-chain security and requires a NPM_TOKEN secret in the repository settings.
Related Packages
A Pinia plugin to create reusable stores that can extend other Pinia stores.
Version History
| Version | Released | License |
|---|---|---|
| 0.2.1 | MIT | |
| 0.2.0 | MIT | |
| 0.1.8 | MIT | |
| 0.1.7 | MIT | |
| 0.1.6 | MIT | |
| 0.1.5 | MIT | |
| 0.1.4 | MIT | |
| 0.1.3 | MIT | |
| 0.1.2 | MIT | |
| 0.1.1 | MIT | |
| 0.1.0 | MIT | |
| 0.0.3 | ||
| 0.0.2 | ||
| 0.0.1 |
Pre-releases (42)
| Version | Released | License |
|---|---|---|
| 1.0.0-beta.7 | MIT | |
| 1.0.0-beta.6 | MIT | |
| 1.0.0-beta.5 | MIT | |
| 1.0.0-beta.4 | MIT | |
| 1.0.0-beta.3 | MIT | |
| 1.0.0-beta.2 | MIT | |
| 1.0.0-beta.1 | MIT | |
| 1.0.0-beta.0 | MIT | |
| 0.2.0-beta.0 | MIT | |
| 0.1.7-beta.1 | MIT | |
| 0.1.7-beta.0 | MIT | |
| 0.1.6-beta.1 | MIT | |
| 0.1.6-beta.0 | MIT | |
| 0.1.4-beta.1 | MIT | |
| 0.1.4-beta.0 | MIT | |
| 0.1.3-beta.1 | MIT | |
| 0.1.3-beta.0 | MIT | |
| 0.0.0-beta.21 | ||
| 0.0.0-beta.20 | ||
| 0.0.0-beta.19 | ||
| 0.0.0-beta.18 | ||
| 0.0.0-beta.17 | ||
| 0.0.0-beta.16 | ||
| 0.0.0-beta.15 | ||
| 0.0.0-beta.14 | ||
| 0.0.0-beta.13 | ||
| 0.0.0-beta.12 | ||
| 0.0.0-beta.11 | ||
| 0.0.0-beta.10 | ||
| 0.0.0-beta.9 |
Showing the latest 30 of 42. See every release on npm