codejump

Pinia Internals

Preview — 3 of 10 questions

How does Pinia maintain a single store instance across multiple useMyStore() calls?

APinia uses a JavaScript singleton pattern with a global module-level variable
BEach useMyStore() call creates a new instance — Pinia merges them automatically
CPinia uses Symbol keys in WeakMap to associate store instances with components
DPinia stores the store instance in the active Pinia instance keyed by store ID, returning the cached instance on subsequent calls

How do you write a Pinia plugin that creates watchers and cleans them up when the store is disposed?

AUse onUnmounted inside the plugin — Pinia hooks into Vue's lifecycle
BUse the store.$dispose hook — plugins cannot create long-lived effects
CCreate effects inside the plugin using effectScope captured from the store's internal scope via store._e
DUse watchEffect in the plugin and return a cleanup function

What are the security implications of transferring Pinia state from server to client?

AState containing sensitive data (tokens, PII) can be exposed via XSS; improperly escaped JSON can enable script injection attacks
BThere are no security implications — the data is already public
CSSR state transfer is automatically secured by Vue's template escaping
DThe only risk is performance — security is not a concern for state transfer

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.