Skip to content
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

node with v-show inside v-if is reused in the adjacent v-else #4484

Closed
dolymood opened this issue Dec 15, 2016 · 2 comments
Closed

node with v-show inside v-if is reused in the adjacent v-else #4484

dolymood opened this issue Dec 15, 2016 · 2 comments
Assignees
Labels

Comments

@dolymood
Copy link

Vue.js version

2.1.6

Reproduction Link

http://codepen.io/dolymood/pen/gLQmwy

Steps to reproduce

Code

<div class="el el-if" v-if="bln"><span v-show="false">hidden content</span></div>
<div class="el el-else" v-else><span @click="toggle">visible  content</span></div>
  1. bln=true, the span element in el-if is hidden

  2. bln=false, the span element in el-else is hidden

What is Expected?

When bln=false, the span element should be visible

What is actually happening?

patchVnode will check the nodes is same:

function sameVnode (vnode1, vnode2) {
  return (
    vnode1.key === vnode2.key &&
    vnode1.tag === vnode2.tag &&
    vnode1.isComment === vnode2.isComment &&
    !vnode1.data === !vnode2.data
  )
}

Because the old vnode vnode1.data is

{
  directives: [{
     def: {bind: fn, update: fn}
     expression: "false"
     modifiers: {},
     name: "show",
     rawName: "v-show",
     value: false
  }]
}

and the new vnode vnode2.data is

{
  on: {click: fn}
}

So sameVnode(span1, span2) result is true, but updateDirectives will be call v-show directive's unbind hook function.

If the span elements have different key attributes, the result will be correct. But i think it will be better if:

When bln=false, the span element should be visible

@posva posva changed the title v-show directive should have unbind hook to reset element's display style value? node with v-show inside v-if is reused in the adjacent v-else Dec 15, 2016
@defcc
Copy link
Member

defcc commented Dec 15, 2016

Thanks, I'm looking into it.

@dolymood
Copy link
Author

👍 Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants