From 82d1048bac13c29a7f3a96c2e91464ee586eeba3 Mon Sep 17 00:00:00 2001 From: edison1105 Date: Wed, 30 Nov 2022 21:50:05 +0800 Subject: [PATCH 1/8] fix(ssr): apply ssr props to the the fallback vnode-based branch in ssr --- packages/runtime-core/src/directives.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 18c3352b002..bb111cd2205 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -11,7 +11,7 @@ return withDirectives(h(comp), [ ]) */ -import { VNode } from './vnode' +import { mergeProps, VNode } from './vnode' import { isFunction, EMPTY_OBJ, isBuiltInDirective } from '@vue/shared' import { warn } from './warning' import { ComponentInternalInstance, Data, getExposeProxy } from './component' @@ -105,14 +105,21 @@ export function withDirectives( if (dir.deep) { traverse(value) } - bindings.push({ + const binding = { dir, instance, value, oldValue: void 0, arg, modifiers - }) + } + if (dir.getSSRProps) { + vnode.props = mergeProps( + vnode.props || {}, + dir.getSSRProps(binding, vnode) || {} + ) + } + bindings.push(binding) } } return vnode From a38a08dc2956ec979bbb37955f3a2a93010af356 Mon Sep 17 00:00:00 2001 From: edison1105 Date: Wed, 30 Nov 2022 21:52:46 +0800 Subject: [PATCH 2/8] fix(ssr): apply ssr props to the the fallback vnode-based branch in ssr --- packages/runtime-core/src/directives.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index bb111cd2205..f90dcd550af 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -113,6 +113,9 @@ export function withDirectives( arg, modifiers } + + // #6123 + // apply ssr props to the the fallback vnode-based branch in ssr if (dir.getSSRProps) { vnode.props = mergeProps( vnode.props || {}, From 4e22e8fc84bff9c79fbde4b48259cd0b1750d3a2 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 1 Dec 2022 09:00:06 +0800 Subject: [PATCH 3/8] chore: improve code --- packages/runtime-core/src/directives.ts | 16 +++------------- packages/server-renderer/src/render.ts | 5 ++++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index f90dcd550af..18c3352b002 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -11,7 +11,7 @@ return withDirectives(h(comp), [ ]) */ -import { mergeProps, VNode } from './vnode' +import { VNode } from './vnode' import { isFunction, EMPTY_OBJ, isBuiltInDirective } from '@vue/shared' import { warn } from './warning' import { ComponentInternalInstance, Data, getExposeProxy } from './component' @@ -105,24 +105,14 @@ export function withDirectives( if (dir.deep) { traverse(value) } - const binding = { + bindings.push({ dir, instance, value, oldValue: void 0, arg, modifiers - } - - // #6123 - // apply ssr props to the the fallback vnode-based branch in ssr - if (dir.getSSRProps) { - vnode.props = mergeProps( - vnode.props || {}, - dir.getSSRProps(binding, vnode) || {} - ) - } - bindings.push(binding) + }) } } return vnode diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index a1f327b4320..acb81406aeb 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -218,7 +218,10 @@ export function renderVNode( parentComponent: ComponentInternalInstance, slotScopeId?: string ) { - const { type, shapeFlag, children } = vnode + const { type, shapeFlag, children, dirs, props } = vnode + if (dirs) { + vnode.props = applySSRDirectives(vnode, props, dirs) + } switch (type) { case Text: push(escapeHtml(children as string)) From 5899e88f87c2a09849ac78ab6b86e389fda8e2a4 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 1 Dec 2022 11:31:50 +0800 Subject: [PATCH 4/8] test: add test case --- .../__tests__/ssrDynamicComponent.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts index 751c229a8b8..9ee2c916969 100644 --- a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts +++ b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts @@ -21,6 +21,23 @@ describe('ssr: dynamic component', () => { ).toBe(`
slot
`) }) + test('resolved to component with v-show', async () => { + expect( + await renderToString( + createApp({ + components: { + one: { + template: `` + } + }, + template: `hi` + }) + ) + ).toBe( + `
hi
` + ) + }) + test('resolve to element', async () => { expect( await renderToString( From ae27f4c84cccf3f60bfb6260202a9e9f7ae8eb9a Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 23 Feb 2023 13:17:12 +0800 Subject: [PATCH 5/8] test: ensure is called --- packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts index 89e2774e525..d89ddc64ec7 100644 --- a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts +++ b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts @@ -1,5 +1,5 @@ import { createApp, createVNode } from 'vue' -import { renderToString } from '../src/renderToString' +import { renderToString } from '../src' describe('ssr: dynamic component', () => { test('resolved to component', async () => { From d8b6e89d3aa4566dba9d10b400dbbd5f2353a4bd Mon Sep 17 00:00:00 2001 From: edison1105 Date: Sun, 2 Jun 2024 09:04:35 +0800 Subject: [PATCH 6/8] chore: remove unnecessary code --- packages/server-renderer/src/render.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index acb81406aeb..6d8c13690d1 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -285,13 +285,9 @@ function renderElementVNode( slotScopeId: string | undefined ) { const tag = vnode.type as string - let { props, children, shapeFlag, scopeId, dirs } = vnode + let { props, children, shapeFlag, scopeId } = vnode let openTag = `<${tag}` - if (dirs) { - props = applySSRDirectives(vnode, props, dirs) - } - if (props) { openTag += ssrRenderAttrs(props, tag) } From d576de534f5ebfee0f0c1b79eb54005a2e7d0767 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 2 Jun 2024 01:06:14 +0000 Subject: [PATCH 7/8] [autofix.ci] apply automated fixes --- .../__tests__/ssrDynamicComponent.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts index f4bacda3ca6..0679c82168b 100644 --- a/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts +++ b/packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts @@ -23,14 +23,14 @@ describe('ssr: dynamic component', () => { createApp({ components: { one: { - template: `` - } + template: ``, + }, }, - template: `hi` - }) - ) + template: `hi`, + }), + ), ).toBe( - `
hi
` + `
hi
`, ) }) From a22d36decf5c902d0944b122fc62022396114404 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 02:01:35 +0000 Subject: [PATCH 8/8] [autofix.ci] apply automated fixes --- packages/server-renderer/src/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index 03739ae1e6e..4744940e827 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -221,7 +221,7 @@ export function renderVNode( if (dirs) { vnode.props = applySSRDirectives(vnode, props, dirs) } - + switch (type) { case Text: push(escapeHtml(children as string))