Skip to content

Commit 5e50909

Browse files
committedNov 11, 2022
fix(custom-elements): should not reflect non-decalred properties set before upgrade
1 parent 665f2ae commit 5e50909

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,18 @@ describe('defineCustomElement', () => {
201201
expect(props.dataAge).toBe(5)
202202
},
203203
render() {
204-
return `foo: ${this.foo}`
204+
return h('div', `foo: ${this.foo}`)
205205
}
206206
})
207207
const el = document.createElement('my-el-upgrade') as any
208208
el.foo = 'hello'
209209
el.dataset.age = 5
210+
el.notProp = 1
210211
container.appendChild(el)
211212
customElements.define('my-el-upgrade', E)
212-
expect(el.shadowRoot.innerHTML).toBe(`foo: hello`)
213+
expect(el.shadowRoot.firstChild.innerHTML).toBe(`foo: hello`)
214+
// should not reflect if not declared as a prop
215+
expect(el.hasAttribute('not-prop')).toBe(false)
213216
})
214217

215218
// https://github.com/vuejs/core/issues/6163

‎packages/runtime-dom/src/apiCustomElement.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ export class VueElement extends BaseClass {
248248
// check if there are props set pre-upgrade or connect
249249
for (const key of Object.keys(this)) {
250250
if (key[0] !== '_') {
251-
this._setProp(key, this[key as keyof this], true, false)
251+
this._setProp(
252+
key,
253+
this[key as keyof this],
254+
rawKeys.includes(key),
255+
false
256+
)
252257
}
253258
}
254259

0 commit comments

Comments
 (0)
Please sign in to comment.