Skip to content

Commit

Permalink
fix: compatibility of createElement in older versions of Chrome (vuej…
Browse files Browse the repository at this point in the history
  • Loading branch information
peixin committed Nov 16, 2023
1 parent 83e618f commit 1ee0f87
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 @@ -17,6 +17,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', false)
expect(spyCreateElement).toHaveBeenLastCalledWith('custom-element')

nodeOps.createElement('custom-element', false, '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 @@ -21,7 +21,9 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
createElement: (tag, isSVG, is, props): Element => {
const el = isSVG
? doc.createElementNS(svgNS, 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 1ee0f87

Please sign in to comment.