Skip to content

Commit bb6a346

Browse files
committed
fix(runtime-core): should preserve props casing when component has no declared props
close #583
1 parent 8aca71b commit bb6a346

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('attribute fallthrough', () => {
3232
id: 'test',
3333
class: 'c' + count.value,
3434
style: { color: count.value ? 'red' : 'green' },
35-
onClick: inc
35+
onClick: inc,
36+
'data-id': 1
3637
})
3738
}
3839
}
@@ -66,6 +67,7 @@ describe('attribute fallthrough', () => {
6667
expect(node.getAttribute('class')).toBe('c2 c0')
6768
expect(node.style.color).toBe('green')
6869
expect(node.style.fontWeight).toBe('bold')
70+
expect(node.dataset.id).toBe('1')
6971
node.dispatchEvent(new CustomEvent('click'))
7072
expect(click).toHaveBeenCalled()
7173

packages/runtime-core/src/componentProps.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ export function resolveProps(
127127
if (key === 'key' || key === 'ref') continue
128128
// prop option names are camelized during normalization, so to support
129129
// kebab -> camel conversion here we need to camelize the key.
130-
const camelKey = camelize(key)
131-
if (hasDeclaredProps && !hasOwn(options, camelKey)) {
132-
// Any non-declared props are put into a separate `attrs` object
133-
// for spreading. Make sure to preserve original key casing
134-
;(attrs || (attrs = {}))[key] = rawProps[key]
130+
if (hasDeclaredProps) {
131+
const camelKey = camelize(key)
132+
if (hasOwn(options, camelKey)) {
133+
setProp(camelKey, rawProps[key])
134+
} else {
135+
// Any non-declared props are put into a separate `attrs` object
136+
// for spreading. Make sure to preserve original key casing
137+
;(attrs || (attrs = {}))[key] = rawProps[key]
138+
}
135139
} else {
136-
setProp(camelKey, rawProps[key])
140+
setProp(key, rawProps[key])
137141
}
138142
}
139143
}

0 commit comments

Comments
 (0)