Skip to content

Commit

Permalink
fix(custom-elements): compatibility of createElement in older version…
Browse files Browse the repository at this point in the history
…s of Chrome (#9615)

close #9614
  • Loading branch information
peixin authored Jun 6, 2024
1 parent d04417d commit a88295d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/runtime-dom/__tests__/nodeOps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ describe('runtime-dom: node-ops', () => {
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', () => {
test('fresh insertion', () => {
const content = `<div>one</div><div>two</div>three`
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-dom/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
? doc.createElementNS(svgNS, tag)
: namespace === 'mathml'
? 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) {
;(el as HTMLSelectElement).setAttribute('multiple', props.multiple)
Expand Down

0 comments on commit a88295d

Please sign in to comment.