Skip to content

Commit d8cba5f

Browse files
committed
+ Update JSXS handling.
1 parent 2d8d87d commit d8cba5f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/jsx.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { VNode, VNodeData } from 'vue'
2+
import Vue from 'vue'
23
import {
34
checkKeyIsVueDirective,
45
checkIsHTMLElement,
@@ -22,6 +23,7 @@ import { ConfigType, TagType } from './type'
2223
import { getCurrentInstance } from './runtime'
2324

2425
const V_BIND_REGEXP = /^v(-b|B)ind:/
26+
let _jsxsId = 0
2527

2628
// Reference:
2729
// https://cn.vuejs.org/v2/guide/render-function.html
@@ -144,11 +146,21 @@ const jsx = function (
144146
const children = isArray(config.children) ? config.children : [config.children]
145147

146148
// Check if it is JSXS function.
149+
// JSXS function must be wrapped into a Vue component, and in order to
150+
// avoid re-creating component, register it as a global component, and
151+
// next time it will be taken out from Vue.
147152
const isJsxsFunc = typeof tag === 'function' && isUndefined((tag as any).cid)
148153
if (isJsxsFunc) {
149-
return h({
150-
render: tag as any
151-
}, vNodeData, children)
154+
// @ts-ignore
155+
let jsxsId = tag.__jsxs_id__
156+
if (!jsxsId) {
157+
jsxsId = 'jsxs-comp-' + _jsxsId++
158+
// @ts-ignore
159+
tag.__jsxs_id__ = jsxsId
160+
// @ts-ignore
161+
Vue.component(jsxsId, { render: tag })
162+
}
163+
return h(Vue.component(jsxsId), vNodeData, children)
152164
}
153165

154166
return h(tag, vNodeData, children)

0 commit comments

Comments
 (0)