prazdevs / pinia-plugin-persistedstate

💾 Configurable persistence and rehydration of Pinia stores.
https://prazdevs.github.io/pinia-plugin-persistedstate/
MIT License
2.06k stars 119 forks source link

onUnmounted is called when there is no active component instance to be associated with. #101

Closed LHofman closed 2 years ago

LHofman commented 2 years ago

Describe the bug

Version 2.1.0

Steps to reproduce

import { mapWritableState } from "pinia";
import { defineComponent } from "vue";
import { useCounterStore } from "../stores/counter";

export default defineComponent({
  computed: {
    ...mapWritableState(useCounterStore, ['counter']),
    otherFn(): number {
      return this.counter;
    },
  },
});

<template>
  {{otherFn}}
</template>

What is expected? No warnings are given in the browser

What is actually happening? A warning is given runtime-core.esm-bundler.js:38 [Vue warn]: onUnmounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.

Reproduction

See above

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 4.14 GB / 15.85 GB
  Binaries:
    Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 103.0.5060.134
    Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.77)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations

prazdevs commented 2 years ago

Can you provide a proper repo/stackblitz for faster reproduction?

Also is this issue known for Pinia standalone, is it solely due to the plugin being added ? The plugin doenst use the onUnmounted itself, might be because of state subscription ($subscribe)

prazdevs commented 2 years ago

nevermind, it's a bug. at some point i dropped the detached: true from subscription. will fix it asap

prazdevs commented 2 years ago

Fixed with #102 release in 2.1.1