Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 65b8148

Browse files
committed
refactor(framework/vue): Add ssrRenderComponent for Head component.
1 parent 650eba3 commit 65b8148

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

framework/vue/head.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import { defineComponent, inject, onBeforeUnmount } from "vue";
2+
import { ssrRenderComponent } from "vue/server-renderer";
23
import util from "../../lib/util.ts";
34

45
export const Head = defineComponent({
56
name: "Head",
67
setup(_props, ctx) {
78
const ssrHeadCollection: string[] | undefined = inject("ssrHeadCollection");
89
if (ctx.slots.default && ssrHeadCollection) {
9-
const children = ctx?.slots.default();
10+
const children = ctx.slots.default();
1011
children.forEach((vnode) => {
11-
const { type, children } = vnode;
12-
if (type === "title") {
13-
if (util.isFilledString(children)) {
14-
ssrHeadCollection.push(`<title ssr>${children}</title>`);
15-
} else if (util.isFilledArray(children)) {
16-
ssrHeadCollection.push(`<title ssr>${children.join("")}</title>`);
17-
}
18-
}
12+
const { props } = vnode;
13+
// add srr attr
14+
vnode.props = { ...props, ssr: "" };
15+
const s = ssrRenderComponent({ render: () => vnode }) as string[];
16+
ssrHeadCollection.push(...s);
1917
});
2018
}
2119
},

0 commit comments

Comments
 (0)