Skip to content

Reactive objects unwrapped and mutated by the template #500

@rchl

Description

@rchl

In v1.0.0-beta.11 and since v1.0.0-beta.7 or maybe later version (haven't checked exactly), I'm seeing weird behavior with my refs being unwrapped in watchers. For example:

<template>
  <div>Check the console</div>
</template>

<script>
import { reactive, watchEffect, ref } from "@vue/composition-api";

export default {
  setup() {
    const temp = ref("xxx");

    const state = {
      value: ref(0)
    };

    watchEffect(() => {
      console.log("state.value:", state.value);
      temp.value = "";
    });

    return {
      state: reactive(state)
    };
  }
};
</script>

When you open the console you'll see that the first time the watchEffect is triggered the state.value is a ref (RefImpl). The second time it's just an unwrapped number.

It only happens when returning "reactive" state to the template.

Here is a live demo: https://codesandbox.io/s/lucid-hooks-y48qt?file=/src/App.vue:0-408

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