Skip to content

fix getContainedComponents in IE 11 #893

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

Merged
merged 1 commit into from
Jun 4, 2015
Merged

fix getContainedComponents in IE 11 #893

merged 1 commit into from
Jun 4, 2015

Conversation

KuroGuo
Copy link

@KuroGuo KuroGuo commented Jun 4, 2015

No description provided.

@yyx990803
Copy link
Member

Is it possible to provide a repro of the error before the fix?

@KuroGuo KuroGuo force-pushed the dev branch 2 times, most recently from a6f34ca to 4ebed2b Compare June 4, 2015 06:21
@KuroGuo KuroGuo closed this Jun 4, 2015
@KuroGuo
Copy link
Author

KuroGuo commented Jun 4, 2015

In IE, nextSibling returns a text node, but text node has no method 'contains'.

@KuroGuo KuroGuo reopened this Jun 4, 2015
while (next !== end) {
next = cur.nextSibling
if (cur.contains(c.$el)) {
isElementNode = cur.nodeType === Node.ELEMENT_NODE
if (isElementNode && cur.contains(c.$el)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The situation can be a bit more complicated though, in the case where the component is a block instance (thus its $el can be a TextNode too).

So I think it's better to change the check to:

if (
  cur === c.$el || // both are textNodes
  (cur.contains && cur.contains(c.$el)) // other situations
) {
  return true
}

@@ -90,7 +90,7 @@ module.exports = {
var next
while (next !== end) {
next = cur.nextSibling
if (cur.contains(c.$el)) {
if (cur.contains && cur.contains(c.$el)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need to check the case where cur === c.$el, because in IE cur.contains is not present if cur is a textNode

yyx990803 added a commit that referenced this pull request Jun 4, 2015
fix getContainedComponents in IE 11
@yyx990803 yyx990803 merged commit c0139e5 into vuejs:dev Jun 4, 2015
@yyx990803
Copy link
Member

Merging so you can get credit, I'll fix with tests. :) thanks

yyx990803 added a commit that referenced this pull request Jun 4, 2015
@salazr
Copy link

salazr commented Jun 4, 2015

FYI, we had the same issue, and came to the same workaround in testing (+cur.contains(el) on the if directive), but kept digging, and it was triggered by IE9 when doing v-if inside a < template > tag.

@yyx990803
Copy link
Member

yep, the whole IE family doesn't implement contains for text nodes. In the spec contains is part of the Node interface, which should be available for text nodes as well, but oh well, it's IE...

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

Successfully merging this pull request may close these issues.

3 participants