Skip to content
Closed
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
33 changes: 33 additions & 0 deletions packages/runtime-dom/__tests__/patchProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,37 @@ describe('runtime-dom: props patching', () => {
expect(root.innerHTML).toBe(`<div>bar</div>`)
expect(fn).toHaveBeenCalled()
})

// #1049
test('set domProps where string is not accepted', () => {
const realCreateElement = document.createElement.bind(document)
const spyCreateElement = jest
.spyOn(document, 'createElement')
.mockImplementation(tagName => {
const el = realCreateElement(tagName)
let srcObject: any = undefined
Object.defineProperty(el, 'srcObject', {
enumerable: true,
set(v) {
if (typeof v === 'string') {
throw new TypeError(
`Failed to set the 'srcObject' property on 'HTMLMediaElement'`
)
}
srcObject = v
},
get() {
return srcObject
}
})
return el
})

const el = document.createElement('video')

patchProp(el, 'srcObject', undefined, null)

expect(el.srcObject).toBeNull()
spyCreateElement.mockRestore()
})
})
7 changes: 6 additions & 1 deletion packages/runtime-dom/src/modules/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export function patchDOMProp(
// e.g. <select multiple> compiles to { multiple: '' }
el[key] = true
} else {
el[key] = value == null ? '' : value
try {
el[key] = value == null ? '' : value
} catch (e) {
if (e.name !== 'TypeError') throw e
el[key] = value
}
}
}