Просмотр исходного кода

do not warn real custom elements

Evan You 10 лет назад
Родитель
Сommit
cbc6fe63a4
1 измененных файлов с 32 добавлено и 6 удалено
  1. 32 6
      src/runtime/vdom/create-element.js

+ 32 - 6
src/runtime/vdom/create-element.js

@@ -20,12 +20,14 @@ export default function createElement (tag, data, children) {
     } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
       return Component(Ctor, data, parent, children)
     } else {
-      if (process.env.NODE_ENV !== 'production' && !data.svg) {
-        warn(
-          'Unknown custom element: <' + tag + '> - did you ' +
-          'register the component correctly? For recursive components, ' +
-          'make sure to provide the "name" option.'
-        )
+      if (process.env.NODE_ENV !== 'production') {
+        if (!data.svg && isUnknownElement(tag)) {
+          warn(
+            'Unknown custom element: <' + tag + '> - did you ' +
+            'register the component correctly? For recursive components, ' +
+            'make sure to provide the "name" option.'
+          )
+        }
       }
       return VNode(tag, data, flatten(children && children()))
     }
@@ -54,3 +56,27 @@ export function flatten (children) {
     return children
   }
 }
+
+const unknownElementCache = Object.create(null)
+
+function isUnknownElement (tag) {
+  tag = tag.toLowerCase()
+  if (unknownElementCache[tag] != null) {
+    return unknownElementCache[tag]
+  }
+  const el = document.createElement(tag)
+  if (tag.indexOf('-') > -1) {
+    // http://stackoverflow.com/a/28210364/1070244
+    return (unknownElementCache[tag] = (
+      el.constructor === window.HTMLUnknownElement ||
+      el.constructor === window.HTMLElement
+    ))
+  } else {
+    return (unknownElementCache[tag] = (
+      /HTMLUnknownElement/.test(el.toString()) &&
+      // Chrome returns unknown for several HTML5 elements.
+      // https://code.google.com/p/chromium/issues/detail?id=540526
+      !/^(data|time|rtc|rb)$/.test(tag)
+    ))
+  }
+}