Skip to content

Commit b1d0b04

Browse files
committed
fix(runtome-dom): properly support creating customized built-in element
1 parent 412ec86 commit b1d0b04

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

packages/runtime-core/src/renderer.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ export interface RendererOptions<
102102
): void
103103
insert(el: HostNode, parent: HostElement, anchor?: HostNode | null): void
104104
remove(el: HostNode): void
105-
createElement(type: string, isSVG?: boolean): HostElement
105+
createElement(
106+
type: string,
107+
isSVG?: boolean,
108+
isCustomizedBuiltIn?: string
109+
): HostElement
106110
createText(text: string): HostNode
107111
createComment(text: string): HostNode
108112
setText(node: HostNode, text: string): void
@@ -549,7 +553,11 @@ function baseCreateRenderer(
549553
// exactly the same, and we can simply do a clone here.
550554
el = vnode.el = hostCloneNode(vnode.el)
551555
} else {
552-
el = vnode.el = hostCreateElement(vnode.type as string, isSVG)
556+
el = vnode.el = hostCreateElement(
557+
vnode.type as string,
558+
isSVG,
559+
props && props.is
560+
)
553561
// props
554562
if (props) {
555563
for (const key in props) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { render, h } from '@vue/runtime-dom'
2+
3+
describe('customimized built-in elements support', () => {
4+
let createElement: jest.SpyInstance
5+
afterEach(() => {
6+
createElement.mockRestore()
7+
})
8+
9+
test('should created element with is option', () => {
10+
const root = document.createElement('div')
11+
createElement = jest.spyOn(document, 'createElement')
12+
render(h('button', { is: 'plastic-button' }), root)
13+
expect(createElement.mock.calls[0]).toMatchObject([
14+
'button',
15+
{ is: 'plastic-button' }
16+
])
17+
// should also render the attribute
18+
expect(root.innerHTML).toBe(`<button is="plastic-button"></button>`)
19+
})
20+
})

packages/runtime-dom/src/nodeOps.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
2222
}
2323
},
2424

25-
createElement: (tag, isSVG): Element =>
26-
isSVG ? doc.createElementNS(svgNS, tag) : doc.createElement(tag),
25+
createElement: (tag, isSVG, is): Element =>
26+
isSVG
27+
? doc.createElementNS(svgNS, tag)
28+
: doc.createElement(tag, is ? { is } : undefined),
2729

2830
createText: text => doc.createTextNode(text),
2931

0 commit comments

Comments
 (0)