Skip to content

cached linker in v-if may lead to wrong host and unexpected behaviours #1185

@TerenceZ

Description

@TerenceZ

Test Version: v0.12.10

In v-if, it will cache the linker if the constructor and the element's html are the same. However, the linker is relative to the host. It means it will lead to some hard-to-discover unexpected behaviours. For example as followed, the comp-b in #two won't fire any ready / attached events! Because

  1. After the #one attached, the program will compile and link the #two.
  2. When binding the v-if directive for comp-b in #two's template, the directive will fetch the linker from the cache (whose host is the comp-a in #one!).
  3. The directive invoke the update and compile and link the comp-b.
  4. The comp-b will be added into #one's comp-a's $children list.
  5. Then it will check if need to fire the attached event, however, because the host (the comp-b in #one) is attached, it won't fire it!
<template id="comp-c">
  <comp-a>
    <comp-b v-if="some-condition-true">Something</comp-b>
  </comp-a>
</template>

<template id="comp-a">
  <content></content>
</template>

<template id="comp-b">
  <content></content>
</template>

<body>
  <div id="app">
   <comp-c id="one"></comp-c>
   <comp-c id="two"></comp-c>
  </div>
</body>

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