@unhead/ssr 1.0.22 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +37 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +38 -7
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -15,17 +15,34 @@ const propsToString = (props) => {
|
|
|
15
15
|
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
return str.replace(/[
|
|
18
|
+
function encodeInnerHtml(str) {
|
|
19
|
+
return str.replace(/[&<>"'/]/g, (char) => {
|
|
20
|
+
switch (char) {
|
|
21
|
+
case "&":
|
|
22
|
+
return "&";
|
|
23
|
+
case "<":
|
|
24
|
+
return "<";
|
|
25
|
+
case ">":
|
|
26
|
+
return ">";
|
|
27
|
+
case '"':
|
|
28
|
+
return """;
|
|
29
|
+
case "'":
|
|
30
|
+
return "'";
|
|
31
|
+
case "/":
|
|
32
|
+
return "/";
|
|
33
|
+
default:
|
|
34
|
+
return char;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
20
37
|
}
|
|
21
38
|
const tagToString = (tag) => {
|
|
22
39
|
const attrs = propsToString(tag.props);
|
|
23
40
|
const openTag = `<${tag.tag}${attrs}>`;
|
|
24
41
|
if (!shared.TagsWithInnerContent.includes(tag.tag))
|
|
25
42
|
return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
26
|
-
let content = tag.
|
|
27
|
-
if (
|
|
28
|
-
content =
|
|
43
|
+
let content = tag.innerHTML || "";
|
|
44
|
+
if (tag.textContent)
|
|
45
|
+
content = encodeInnerHtml(tag.textContent);
|
|
29
46
|
return shared.SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
30
47
|
};
|
|
31
48
|
|
|
@@ -60,6 +77,20 @@ async function renderSSRHead(head) {
|
|
|
60
77
|
};
|
|
61
78
|
}
|
|
62
79
|
const ctx = { tags: await head.resolveTags() };
|
|
80
|
+
if (head.resolvedOptions.experimentalHashHydration) {
|
|
81
|
+
ctx.tags.push({
|
|
82
|
+
tag: "meta",
|
|
83
|
+
props: {
|
|
84
|
+
name: "unhead:ssr",
|
|
85
|
+
content: shared.computeHashes(
|
|
86
|
+
ctx.tags.filter((t) => {
|
|
87
|
+
const entry = head.headEntries().find((entry2) => entry2._i === t._e);
|
|
88
|
+
return entry?._m !== "server";
|
|
89
|
+
}).map((tag) => tag._h)
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
63
94
|
await head.hooks.callHook("ssr:render", ctx);
|
|
64
95
|
const html = ssrRenderTags(ctx.tags);
|
|
65
96
|
const renderCtx = { tags: ctx.tags, html };
|
|
@@ -67,7 +98,7 @@ async function renderSSRHead(head) {
|
|
|
67
98
|
return renderCtx.html;
|
|
68
99
|
}
|
|
69
100
|
|
|
70
|
-
exports.
|
|
101
|
+
exports.encodeInnerHtml = encodeInnerHtml;
|
|
71
102
|
exports.propsToString = propsToString;
|
|
72
103
|
exports.renderSSRHead = renderSSRHead;
|
|
73
104
|
exports.ssrRenderTags = ssrRenderTags;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPa
|
|
|
5
5
|
|
|
6
6
|
declare const propsToString: (props: Record<string, any>) => string;
|
|
7
7
|
|
|
8
|
-
declare function
|
|
8
|
+
declare function encodeInnerHtml(str: string): string;
|
|
9
9
|
declare const tagToString: <T extends HeadTag>(tag: T) => string;
|
|
10
10
|
|
|
11
11
|
declare function ssrRenderTags<T extends HeadTag>(tags: T[]): {
|
|
@@ -16,4 +16,4 @@ declare function ssrRenderTags<T extends HeadTag>(tags: T[]): {
|
|
|
16
16
|
bodyAttrs: string;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export {
|
|
19
|
+
export { encodeInnerHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TagsWithInnerContent, SelfClosingTags } from '@unhead/shared';
|
|
1
|
+
import { TagsWithInnerContent, SelfClosingTags, computeHashes } from '@unhead/shared';
|
|
2
2
|
|
|
3
3
|
const propsToString = (props) => {
|
|
4
4
|
const handledAttributes = [];
|
|
@@ -13,17 +13,34 @@ const propsToString = (props) => {
|
|
|
13
13
|
return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
function
|
|
17
|
-
return str.replace(/[
|
|
16
|
+
function encodeInnerHtml(str) {
|
|
17
|
+
return str.replace(/[&<>"'/]/g, (char) => {
|
|
18
|
+
switch (char) {
|
|
19
|
+
case "&":
|
|
20
|
+
return "&";
|
|
21
|
+
case "<":
|
|
22
|
+
return "<";
|
|
23
|
+
case ">":
|
|
24
|
+
return ">";
|
|
25
|
+
case '"':
|
|
26
|
+
return """;
|
|
27
|
+
case "'":
|
|
28
|
+
return "'";
|
|
29
|
+
case "/":
|
|
30
|
+
return "/";
|
|
31
|
+
default:
|
|
32
|
+
return char;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
18
35
|
}
|
|
19
36
|
const tagToString = (tag) => {
|
|
20
37
|
const attrs = propsToString(tag.props);
|
|
21
38
|
const openTag = `<${tag.tag}${attrs}>`;
|
|
22
39
|
if (!TagsWithInnerContent.includes(tag.tag))
|
|
23
40
|
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
24
|
-
let content = tag.
|
|
25
|
-
if (
|
|
26
|
-
content =
|
|
41
|
+
let content = tag.innerHTML || "";
|
|
42
|
+
if (tag.textContent)
|
|
43
|
+
content = encodeInnerHtml(tag.textContent);
|
|
27
44
|
return SelfClosingTags.includes(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
28
45
|
};
|
|
29
46
|
|
|
@@ -58,6 +75,20 @@ async function renderSSRHead(head) {
|
|
|
58
75
|
};
|
|
59
76
|
}
|
|
60
77
|
const ctx = { tags: await head.resolveTags() };
|
|
78
|
+
if (head.resolvedOptions.experimentalHashHydration) {
|
|
79
|
+
ctx.tags.push({
|
|
80
|
+
tag: "meta",
|
|
81
|
+
props: {
|
|
82
|
+
name: "unhead:ssr",
|
|
83
|
+
content: computeHashes(
|
|
84
|
+
ctx.tags.filter((t) => {
|
|
85
|
+
const entry = head.headEntries().find((entry2) => entry2._i === t._e);
|
|
86
|
+
return entry?._m !== "server";
|
|
87
|
+
}).map((tag) => tag._h)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
61
92
|
await head.hooks.callHook("ssr:render", ctx);
|
|
62
93
|
const html = ssrRenderTags(ctx.tags);
|
|
63
94
|
const renderCtx = { tags: ctx.tags, html };
|
|
@@ -65,4 +96,4 @@ async function renderSSRHead(head) {
|
|
|
65
96
|
return renderCtx.html;
|
|
66
97
|
}
|
|
67
98
|
|
|
68
|
-
export {
|
|
99
|
+
export { encodeInnerHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"packageManager": "pnpm@7.
|
|
4
|
+
"version": "1.1.1",
|
|
5
|
+
"packageManager": "pnpm@7.27.1",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/schema": "1.
|
|
34
|
-
"@unhead/shared": "1.
|
|
33
|
+
"@unhead/schema": "1.1.1",
|
|
34
|
+
"@unhead/shared": "1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "unbuild .",
|