#991·pinia

subscriptions are lost during HMR

Author: duoyueCreated Jan 25, 2022Updated Nov 8, 2022
Labels✨ enhancementHMR 🔥

I have some code like this , it could output correctly when app first loaded or refresh ,but don‘t work after HMR.

javascript
const pinia = createPinia();
pinia.use(({ store }) => {
  store.$subscribe((mutations, state) => {
    console.log('trigger subscritions ', mutations, state);
  });
});

I have add some breakpoints in Pinia.js ,and found that subscriptions is emty [] after HMR.

javascript

// the  "subscriptions" is empty [] after HMR
function triggerSubscriptions(subscriptions, ...args) {
    subscriptions.forEach((callback) => {
        callback(...args);
    });
}