Skip to content

Commit

Permalink
fix(server-renderer): render className during SSR (#11722)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Sep 3, 2024
1 parent ca12e77 commit 52cdb0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ describe('ssr: renderClass', () => {
test('escape class values', () => {
expect(ssrRenderClass(`"><script`)).toBe(`&quot;&gt;&lt;script`)
})

test('className', () => {
expect(
ssrRenderAttrs({
className: 'foo',
}),
).toBe(` class="foo"`)
expect(
ssrRenderAttrs({
className: ['foo', 'bar'],
}),
).toBe(` class="foo,bar"`)
})
})

describe('ssr: renderStyle', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/server-renderer/src/helpers/ssrRenderAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export function ssrRenderAttrs(
ret += ` class="${ssrRenderClass(value)}"`
} else if (key === 'style') {
ret += ` style="${ssrRenderStyle(value)}"`
} else if (key === 'className') {
ret += ` class="${String(value)}"`

This comment has been minimized.

Copy link
@zhangenming

zhangenming Sep 3, 2024

Contributor

这里value有可能为symbol吗
如果没有可能的话 是不是可以去掉String

} else {
ret += ssrRenderDynamicAttr(key, value, tag)
}
Expand Down

0 comments on commit 52cdb0f

Please sign in to comment.