fix(custom-elements): compatibility of createElement in older versions of Chrome (#9615)

close #9614
This commit is contained in:
Peixin Liu 2024-06-06 18:21:28 +08:00 committed by GitHub
parent d04417da41
commit a88295dc07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,20 @@ describe('runtime-dom: node-ops', () => {
expect(option2.selected).toBe(true) expect(option2.selected).toBe(true)
}) })
test('create custom elements', () => {
const spyCreateElement = vi.spyOn(document, 'createElement')
nodeOps.createElement('custom-element')
expect(spyCreateElement).toHaveBeenLastCalledWith('custom-element')
nodeOps.createElement('custom-element', undefined, 'li')
expect(spyCreateElement).toHaveBeenLastCalledWith('custom-element', {
is: 'li',
})
spyCreateElement.mockClear()
})
describe('insertStaticContent', () => { describe('insertStaticContent', () => {
test('fresh insertion', () => { test('fresh insertion', () => {
const content = `<div>one</div><div>two</div>three` const content = `<div>one</div><div>two</div>three`

View File

@ -25,7 +25,9 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
? doc.createElementNS(svgNS, tag) ? doc.createElementNS(svgNS, tag)
: namespace === 'mathml' : namespace === 'mathml'
? doc.createElementNS(mathmlNS, tag) ? doc.createElementNS(mathmlNS, tag)
: doc.createElement(tag, is ? { is } : undefined) : is
? doc.createElement(tag, { is })
: doc.createElement(tag)
if (tag === 'select' && props && props.multiple != null) { if (tag === 'select' && props && props.multiple != null) {
;(el as HTMLSelectElement).setAttribute('multiple', props.multiple) ;(el as HTMLSelectElement).setAttribute('multiple', props.multiple)