Skip to content

Commit 7013e8f

Browse files
committed
fix(runtime-dom): remove class attribute on nullish values
close #3173
1 parent 5af718b commit 7013e8f

File tree

1 file changed

+12
-13
lines changed
  • packages/runtime-dom/src/modules

1 file changed

+12
-13
lines changed

packages/runtime-dom/src/modules/class.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import { ElementWithTransition } from '../components/Transition'
33
// compiler should normalize class + :class bindings on the same element
44
// into a single binding ['staticClass', dynamic]
55
export function patchClass(el: Element, value: string | null, isSVG: boolean) {
6-
if (value == null) {
7-
value = ''
6+
// directly setting className should be faster than setAttribute in theory
7+
// if this is an element during a transition, take the temporary transition
8+
// classes into account.
9+
const transitionClasses = (el as ElementWithTransition)._vtc
10+
if (transitionClasses) {
11+
value = (value
12+
? [value, ...transitionClasses]
13+
: [...transitionClasses]
14+
).join(' ')
815
}
9-
if (isSVG) {
16+
if (value == null) {
17+
el.removeAttribute('class')
18+
} else if (isSVG) {
1019
el.setAttribute('class', value)
1120
} else {
12-
// directly setting className should be faster than setAttribute in theory
13-
// if this is an element during a transition, take the temporary transition
14-
// classes into account.
15-
const transitionClasses = (el as ElementWithTransition)._vtc
16-
if (transitionClasses) {
17-
value = (value
18-
? [value, ...transitionClasses]
19-
: [...transitionClasses]
20-
).join(' ')
21-
}
2221
el.className = value
2322
}
2423
}

0 commit comments

Comments
 (0)