Skip to content
Merged
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
12 changes: 12 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3709,6 +3709,18 @@ describe('SSR hydration', () => {
expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(2)
})

test('bigint attr handling', () => {
mountWithHydration(`<div title="10">x</div>`, () =>
h('div', { title: BigInt(10) }, 'x'),
)
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()

mountWithHydration(`<div>x</div>`, () =>
h('div', { title: BigInt(10) }, 'x'),
)
expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(1)
})

test('attr special case: textarea value', () => {
mountWithHydration(`<textarea>foo</textarea>`, () =>
h('textarea', { value: 'foo' }),
Expand Down
16 changes: 16 additions & 0 deletions packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ describe('ssr: renderAttrs', () => {
).toBe(` id="foo" title="bar"`)
})

test('bigint attrs', () => {
expect(
ssrRenderAttrs({
'data-id': BigInt(10),
title: BigInt(10),
}),
).toBe(` data-id="10" title="10"`)
// boolean attrs follow the same truthiness check as the client
expect(ssrRenderAttrs({ disabled: BigInt(10) })).toBe(` disabled`)
expect(ssrRenderAttrs({ disabled: BigInt(0) })).toBe(``)
})

test('empty value attrs', () => {
expect(
ssrRenderAttrs({
Expand Down Expand Up @@ -161,6 +173,10 @@ describe('ssr: renderAttr', () => {
expect(ssrRenderAttr('foo', undefined)).toBe(``)
})

test('bigint', () => {
expect(ssrRenderAttr('data-id', BigInt(10))).toBe(` data-id="10"`)
})

test('escape', () => {
expect(ssrRenderAttr('foo', '<script>')).toBe(
` foo="${escapeHtml(`<script>`)}"`,
Expand Down
9 changes: 8 additions & 1 deletion packages/shared/src/domAttrConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,12 @@ export function isRenderableAttrValue(value: unknown): boolean {
return false
}
const type = typeof value
return type === 'string' || type === 'number' || type === 'boolean'
return (
type === 'string' ||
type === 'number' ||
type === 'boolean' ||
// bigint stringifies the same way on both sides (`setAttribute`/property
// assignment on the client, `escapeHtml` during SSR)
type === 'bigint'
Comment thread
edison1105 marked this conversation as resolved.
Resolved
)
}
Loading