From: Peixin Liu Date: Thu, 6 Jun 2024 10:21:28 +0000 (+0800) Subject: fix(custom-elements): compatibility of createElement in older versions of Chrome... X-Git-Tag: v3.4.28~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88295dc076ee867939d8b0ee2225e63c5ffb0ca;p=thirdparty%2Fvuejs%2Fcore.git fix(custom-elements): compatibility of createElement in older versions of Chrome (#9615) close #9614 --- diff --git a/packages/runtime-dom/__tests__/nodeOps.spec.ts b/packages/runtime-dom/__tests__/nodeOps.spec.ts index ed30e42ade..db56ff25df 100644 --- a/packages/runtime-dom/__tests__/nodeOps.spec.ts +++ b/packages/runtime-dom/__tests__/nodeOps.spec.ts @@ -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 = `
one
two
three` diff --git a/packages/runtime-dom/src/nodeOps.ts b/packages/runtime-dom/src/nodeOps.ts index a318000aa9..ef3ef0748c 100644 --- a/packages/runtime-dom/src/nodeOps.ts +++ b/packages/runtime-dom/src/nodeOps.ts @@ -25,7 +25,9 @@ export const nodeOps: Omit, '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)