Skip to content

TypeError when route-link with sibling slot used #4584

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
Darkside73 opened this issue Dec 27, 2016 · 6 comments
Closed

TypeError when route-link with sibling slot used #4584

Darkside73 opened this issue Dec 27, 2016 · 6 comments
Labels

Comments

@Darkside73
Copy link

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
@mochetts
Copy link

mochetts commented Dec 27, 2016

Having same issue in a SPA...

image

Downgraded to 2.1.6 and there it seems to work fine.

@johnleider
Copy link
Contributor

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

@samuelantonioli
Copy link

samuelantonioli commented Dec 27, 2016

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.

@yyx990803
Copy link
Member

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.

@samuelantonioli
Copy link

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

@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
Labels
Projects
None yet
Development

No branches or pull requests

5 participants