Skip to content

injected ref value is not reactive when updated inside setup of a child component #2043

Closed
@amrnn90

Description

@amrnn90

Version

3.0.0-rc.10

Reproduction link

https://codesandbox.io/s/admiring-snow-4u748?file=/src/Child.vue

Steps to reproduce

Open the reproduction link, in parent component setup we have:

 setup() {
    const msg = ref("initial");
    provide("CONTEXT", { msg });

    return {
      msg
    };
  }

and in a child component setup:

  setup() {
    const ctx = inject("CONTEXT");

    // not working (works when wrapped inside onBeforeMount)
    ctx.msg.value = "updated";
  }

What is expected?

the screen should show: "updated"

What is actually happening?

the screen shows "initial"


It works fine when wrapped inside a lifecycle hook:

onBeforeMount(() => {
    ctx.msg.value = "updated";
})

I'm not sure if it's a bug or intentional behavior, but I find it weird since the parent's setup function is executed before the child's.

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