TypeError when route-link with sibling slot used #4584

Closed
Darkside73 opened this Issue Dec 27, 2016 · 6 comments

Projects

None yet

5 participants

@Darkside73

Vue.js version

2.1.7

Reproduction Link

https://jsfiddle.net/1anum7y4/1/

This template fails to compile if no default slot given

<p>
  <router-link :to="{ name: 'foo' }">foo</router-link>
  <slot></slot>
</p>

It does not reproduce if slot given or <slot></slot> wrapped by any tag

What is Expected?

Component renders without slot

What is actually happening?

Uncaught TypeError: Cannot set property 'isRootInsert' of undefined

@yyx990803 yyx990803 added the bug label Dec 27, 2016
@mmochetti
mmochetti commented Dec 27, 2016 edited

Having same issue in a SPA...

image

Downgraded to 2.1.6 and there it seems to work fine.

@johnleider

Same, submitted issue on the vue-router repo #1051.

@samuelantonioli
samuelantonioli commented Dec 27, 2016 edited

the problem

The difference seems to be the following between the versions:
Vue 2.1.7 calls createElm with an undefined vnode (createElm(undefined, ...))

console.log in createElm reveals the following:

Vue 2.1.6:
216

Vue 2.1.7:
217

So the problem is that createElem gets called with an undefined vnode.
calling Vue 2.1.6's createElm with an undefined vnode creates the same error:

Uncaught TypeError: Cannot set property 'isRootInsert' of undefined


bug

The relevant part is here: src/core/vdom/patch.js#L89


solution

I think it would be a good idea to add the following lines in createElm which just make sure
that the function doesn't want to access attributes of an undefined object:

if (typeof(vnode) === 'undefined') {
    return
}

This seems to solve the problem for Vue 2.1.7 and also Vue 2.1.6 when calling createElm(undefined, ...).

It should be analyzed where the error gets introduced (i.e. why createElm gets called with an undefined vnode), but I think it is a good idea to do type checking here regardless.
Maybe a unit test should be added to check for this case.

Would be glad to help.

@johnleider johnleider referenced this issue in vuetifyjs/vuetify Dec 27, 2016
Closed

CLI is failing #37

@yyx990803
Collaborator

This should actually be the same issue with #4564 and is fixed by #4572 (confirmed for @Darkside73 and @johnleider 's cases)

@mmochetti @samuelantonioli you can try the patch in #4572 in your local Vue dist file to see if they are the same issue - if the error persists, they are likely different bugs and please open separate issue with repro.

@yyx990803 yyx990803 closed this Dec 27, 2016
@samuelantonioli

@johnleider

it seems that there's the same problem with missing type checking before accessing the attributes in your referenced issue #4584

The relevant part for this bug is here: src/core/instance/render.js#L293. Replacing the current if statement there with the following lines solves the problem for me (patching my local dist for testing):

if (
  typeof(child) === 'object' &&
  (child.context === context || child.functionalContext === context) &&
  child.data && (name = child.data.slot)
) {
    ...
}
@samuelantonioli

@yyx990803 Thanks, after applying the changes to getNormalizationType, everything works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment