]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(custom-elements): compatibility of createElement in older versions of Chrome...
authorPeixin Liu <fengyi.mail@gmail.com>
Thu, 6 Jun 2024 10:21:28 +0000 (18:21 +0800)
committerGitHub <noreply@github.com>
Thu, 6 Jun 2024 10:21:28 +0000 (18:21 +0800)
close #9614

packages/runtime-dom/__tests__/nodeOps.spec.ts
packages/runtime-dom/src/nodeOps.ts

index ed30e42adee44b2f0b34d955a9d3f7d1b87a7928..db56ff25df5b37b9c817dfb9dd05fc5a1f41d3d8 100644 (file)
@@ -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`
index a318000aa915e36149734e016ff1b0926f12c4ec..ef3ef0748c111eba5097444ab8ae9fc940c8165e 100644 (file)
@@ -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)