Skip to content

Commit 8ae4c29

Browse files
authored
fix(runtime-dom): prevent setting state as attribute for custom elements (#11165)
close #11163
1 parent 3bd79e3 commit 8ae4c29

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/runtime-dom/__tests__/customElement.spec.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
inject,
1010
nextTick,
1111
ref,
12+
render,
1213
renderSlot,
1314
} from '../src'
1415

@@ -137,7 +138,7 @@ describe('defineCustomElement', () => {
137138

138139
describe('props', () => {
139140
const E = defineCustomElement({
140-
props: ['foo', 'bar', 'bazQux'],
141+
props: ['foo', 'bar', 'bazQux', 'value'],
141142
render() {
142143
return [
143144
h('div', null, this.foo),
@@ -147,6 +148,12 @@ describe('defineCustomElement', () => {
147148
})
148149
customElements.define('my-el-props', E)
149150

151+
test('renders custom element w/ correct object prop value', () => {
152+
render(h('my-el-props', { value: { x: 1 } }), container)
153+
const el = container.children[0]
154+
expect((el as any).value).toEqual({ x: 1 })
155+
})
156+
150157
test('props via attribute', async () => {
151158
// bazQux should map to `baz-qux` attribute
152159
container.innerHTML = `<my-el-props foo="hello" baz-qux="bye"></my-el-props>`

packages/runtime-dom/src/patchProp.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export const patchProp: DOMRendererOptions['patchProp'] = (
5454
)
5555
// #6007 also set form state as attributes so they work with
5656
// <input type="reset"> or libs / extensions that expect attributes
57-
if (key === 'value' || key === 'checked' || key === 'selected') {
57+
// #11163 custom elements may use value as an prop and set it as object
58+
if (
59+
!el.tagName.includes('-') &&
60+
(key === 'value' || key === 'checked' || key === 'selected')
61+
) {
5862
patchAttr(el, key, nextValue, isSVG, parentComponent, key !== 'value')
5963
}
6064
} else {

0 commit comments

Comments
 (0)