Skip to content

Commit

Permalink
fix(runtime-dom): remove class attribute on nullish values
Browse files Browse the repository at this point in the history
close #3173
  • Loading branch information
yyx990803 committed Jul 15, 2021
1 parent 5af718b commit 7013e8f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/runtime-dom/src/modules/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 7013e8f

Please sign in to comment.