From 8c430e1e1adcf7a83599a728cad68cc24f3bba4e Mon Sep 17 00:00:00 2001 From: linzhe141 <1572213544@qq.com> Date: Thu, 12 Dec 2024 11:29:01 +0800 Subject: [PATCH 1/2] fix(ssr): handle manually using the h function (return a HTMLElement) --- packages/server-renderer/__tests__/render.spec.ts | 11 +++++++++++ packages/server-renderer/src/render.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/packages/server-renderer/__tests__/render.spec.ts b/packages/server-renderer/__tests__/render.spec.ts index d0a5223b2ff..ad5fd01d1f1 100644 --- a/packages/server-renderer/__tests__/render.spec.ts +++ b/packages/server-renderer/__tests__/render.spec.ts @@ -1229,5 +1229,16 @@ function testRender(type: string, render: typeof renderToString) { // during the render phase expect(getterSpy).toHaveBeenCalledTimes(2) }) + + test('manually using the h function (return a HTMLElement)', async () => { + const MyNode = h('div', { id: 'aaaa' }) + const app = createSSRApp({ + ssrRender(_ctx, push, parent) { + push(ssrRenderComponent(MyNode, null, null, parent)) + }, + }) + const html = await render(app) + expect(html).toBe(`
`) + }) }) } diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index f04080b9c31..d433ca266d4 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -93,6 +93,11 @@ export function renderComponentVNode( parentComponent: ComponentInternalInstance | null = null, slotScopeId?: string, ): SSRBuffer | Promise { + if (isString(vnode.type)) { + const { getBuffer, push } = createBuffer() + renderVNode(push, vnode, parentComponent!, slotScopeId) + return getBuffer() + } const instance = (vnode.component = createComponentInstance( vnode, parentComponent, From 495da080bcdac2797f329fa715da126afacb6fd3 Mon Sep 17 00:00:00 2001 From: linzhe141 <1572213544@qq.com> Date: Thu, 12 Dec 2024 15:36:15 +0800 Subject: [PATCH 2/2] chore: update --- packages/server-renderer/src/render.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index d433ca266d4..b261bb06795 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -93,11 +93,13 @@ export function renderComponentVNode( parentComponent: ComponentInternalInstance | null = null, slotScopeId?: string, ): SSRBuffer | Promise { - if (isString(vnode.type)) { + // vnode may be an ELEMENT + if (vnode.shapeFlag & ShapeFlags.ELEMENT) { const { getBuffer, push } = createBuffer() - renderVNode(push, vnode, parentComponent!, slotScopeId) + renderElementVNode(push, vnode, parentComponent!, slotScopeId) return getBuffer() } + const instance = (vnode.component = createComponentInstance( vnode, parentComponent,