Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TerenceZ opened this issue Aug 20, 2015 · 1 comment
Closed

Comments

@TerenceZ
Copy link

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>
@yyx990803
Copy link
Member

Thanks for the detailed report! Appreciated.

yyx990803 added a commit that referenced this issue Aug 22, 2015
yyx990803 added a commit that referenced this issue Aug 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants