Sfoglia il codice sorgente

treat <input> with different types as different nodes (fix #5266)

Evan You 9 anni fa
parent
commit
f4630d0105
1 ha cambiato i file con 16 aggiunte e 5 eliminazioni
  1. 16 5
      src/core/vdom/patch.js

+ 16 - 5
src/core/vdom/patch.js

@@ -34,15 +34,26 @@ function isTrue (v) {
   return v === true
 }
 
-function sameVnode (vnode1, vnode2) {
+function sameVnode (a, b) {
   return (
-    vnode1.key === vnode2.key &&
-    vnode1.tag === vnode2.tag &&
-    vnode1.isComment === vnode2.isComment &&
-    !vnode1.data === !vnode2.data
+    a.key === b.key &&
+    a.tag === b.tag &&
+    a.isComment === b.isComment &&
+    isDef(a.data) === isDef(b.data) &&
+    sameInputType(a, b)
   )
 }
 
+// Some browsers do not support dynamically changing type for <input>
+// so they need to be treated as different nodes
+function sameInputType (a, b) {
+  if (a.tag !== 'input') return true
+  let i
+  const typeA = isDef(i = a.data) && isDef(i = i.attrs) && i.type
+  const typeB = isDef(i = b.data) && isDef(i = i.attrs) && i.type
+  return typeA === typeB
+}
+
 function createKeyToOldIdx (children, beginIdx, endIdx) {
   let i, key
   const map = {}