Skip to content

watchEffect within a Setup Store is stopped unexpectedly #1862

Closed
@0x009922

Description

@0x009922

Reproduction

https://stackblitz.com/edit/github-u4jlt8

Steps to reproduce the bug

  1. Click "Negate store.flag" buttonn any times you like. You will see how store.flag negates, ang how its computed store.negated stays reactive.
  2. Uncheck "Show StoreUser" input. The component will be unmounted.
  3. Check it again, to mount the component back.
  4. Click "Negate" button again - store.negated is not reactive anymore.
Screen.Recording.2022-12-11.at.14.02.35.mov

Expected behavior

I expected the watchEffect(), called within a Setup Store, to be active as long as the store's scope is active. It makes possible for utilities like computedEager() just work in setup stores.

Actual behavior

The watch effect seems to bind not to the store's setup scope, but to the component where the initial useStore invocation happened. Thus, when the component is unmounted, the watch effect is cleared and stopped, leaving the store in a broken and hard-to-debug state.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions