From: Evan You Date: Thu, 15 Jul 2021 17:45:43 +0000 (-0400) Subject: fix(runtime-dom): remove class attribute on nullish values X-Git-Tag: v3.1.5~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7013e8f5781e838256bf07e7d5de58a974e761a8;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-dom): remove class attribute on nullish values close #3173 --- diff --git a/packages/runtime-dom/src/modules/class.ts b/packages/runtime-dom/src/modules/class.ts index d26867d9a0..6eecf64169 100644 --- a/packages/runtime-dom/src/modules/class.ts +++ b/packages/runtime-dom/src/modules/class.ts @@ -3,22 +3,21 @@ import { ElementWithTransition } from '../components/Transition' // compiler should normalize class + :class bindings on the same element // into a single binding ['staticClass', dynamic] export function patchClass(el: Element, value: string | null, isSVG: boolean) { - if (value == null) { - value = '' + // directly setting className should be faster than setAttribute in theory + // if this is an element during a transition, take the temporary transition + // classes into account. + const transitionClasses = (el as ElementWithTransition)._vtc + if (transitionClasses) { + value = (value + ? [value, ...transitionClasses] + : [...transitionClasses] + ).join(' ') } - if (isSVG) { + if (value == null) { + el.removeAttribute('class') + } else if (isSVG) { el.setAttribute('class', value) } else { - // directly setting className should be faster than setAttribute in theory - // if this is an element during a transition, take the temporary transition - // classes into account. - const transitionClasses = (el as ElementWithTransition)._vtc - if (transitionClasses) { - value = (value - ? [value, ...transitionClasses] - : [...transitionClasses] - ).join(' ') - } el.className = value } }