Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not render class when it is undefined or null #9199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
toDisplayString,
normalizeClass,
normalizeStyle,
stringifyClass,
stringifyStyle,
makeMap,
isKnownSvgAttr,
Expand Down Expand Up @@ -311,7 +312,7 @@ function stringifyElement(
if (evaluated != null) {
const arg = p.arg && (p.arg as SimpleExpressionNode).content
if (arg === 'class') {
evaluated = normalizeClass(evaluated)
evaluated = stringifyClass(normalizeClass(evaluated))
} else if (arg === 'style') {
evaluated = stringifyStyle(normalizeStyle(evaluated))
}
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/__tests__/normalizeProp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('normalizeClass', () => {
)
})

// #3173
test('handles null and undefined correctly', () => {
expect(normalizeClass(undefined)).toEqual(undefined)
expect(normalizeClass(null)).toEqual(undefined)
})

// #6777
test('parse multi-line inline style', () => {
expect(
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ export function stringifyStyle(
return ret
}

export function normalizeClass(value: unknown): string {
export function stringifyClass(klass: string | undefined): string {
return klass || ''
}

export function normalizeClass(value: unknown): string | undefined {
// #3173
if (value == null) return undefined
let res = ''
if (isString(value)) {
res = value
Expand Down