From 0dd5fb9e9f7401cf0be48b29a6fe63d2f488b2ea Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Dec 2020 12:16:11 +0800 Subject: [PATCH 1/2] fix(runtime-dom): use setAttribute to set DOM prop --- .../runtime-dom/__tests__/patchProps.spec.ts | 12 ----------- packages/runtime-dom/src/modules/props.ts | 21 ++++--------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 687b2b79056..5d988a08a29 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -93,18 +93,6 @@ describe('runtime-dom: props patching', () => { expect(el.srcObject).toBe(initialValue) }) - test('catch and warn prop set TypeError', () => { - const el = document.createElement('div') - Object.defineProperty(el, 'someProp', { - set() { - throw new TypeError('Invalid type') - } - }) - patchProp(el, 'someProp', null, 'foo') - - expect(`Failed setting prop "someProp" on
`).toHaveBeenWarnedLast() - }) - // #1576 test('remove attribute when value is falsy', () => { const el = document.createElement('div') diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 068701642f8..1c8b06b3a69 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -2,8 +2,6 @@ // Reason: potentially setting innerHTML. // This can come from explicit usage of v-html or innerHTML as a prop in render -import { warn } from '@vue/runtime-core' - // functions. The user is responsible for using them with only trusted content. export function patchDOMProp( el: any, @@ -38,9 +36,9 @@ export function patchDOMProp( if (value === '' || value == null) { const type = typeof el[key] - if (value === '' && type === 'boolean') { - // e.g. compiles to { multiple: '' } or { multiple: false } + el[key] = value != null return } else if (value == null && type === 'string') { // e.g.
@@ -55,16 +53,5 @@ export function patchDOMProp( } } - // some properties perform value validation and throw - try { - el[key] = value - } catch (e) { - if (__DEV__) { - warn( - `Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` + - `value ${value} is invalid.`, - e - ) - } - } + el.setAttribute(key, value) } From 77f22d77c1f8da0b57a8bc26798dc45fc53e58b3 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sat, 12 Dec 2020 12:26:59 +0800 Subject: [PATCH 2/2] fix(runtime-dom): use setAttribute to set DOM prop --- packages/runtime-dom/src/modules/props.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 1c8b06b3a69..b13f84be200 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -34,8 +34,8 @@ export function patchDOMProp( return } + const type = typeof el[key] if (value === '' || value == null) { - const type = typeof el[key] if (type === 'boolean') { // e.g.