vike-react 0.3.2 → 0.3.4
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.
@@ -1,6 +1,7 @@
|
|
1
1
|
// https://vike.dev/onRenderHtml
|
2
2
|
export { onRenderHtml };
|
3
3
|
import { renderToString } from 'react-dom/server';
|
4
|
+
import { renderToStream } from 'react-streaming/server';
|
4
5
|
import { escapeInject, dangerouslySkipEscape, version } from 'vike/server';
|
5
6
|
import { getTitle } from './getTitle.js';
|
6
7
|
import { getPageElement } from './getPageElement.js';
|
@@ -8,37 +9,36 @@ import { PageContextProvider } from './PageContextProvider.js';
|
|
8
9
|
import React from 'react';
|
9
10
|
checkVikeVersion();
|
10
11
|
const onRenderHtml = async (pageContext) => {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
pageHtml = renderToString(page);
|
15
|
-
}
|
12
|
+
const lang = pageContext.config.lang || 'en';
|
13
|
+
const { favicon } = pageContext.config;
|
14
|
+
const faviconTag = !favicon ? '' : React.createElement("link", { rel: "icon", href: favicon });
|
16
15
|
const title = getTitle(pageContext);
|
17
|
-
const titleTag = !title ? '' :
|
16
|
+
const titleTag = !title ? '' : React.createElement("title", null, title);
|
18
17
|
const { description } = pageContext.config;
|
19
|
-
const descriptionTag = !description ? '' :
|
20
|
-
const { favicon } = pageContext.config;
|
21
|
-
const faviconTag = !favicon ? '' : escapeInject `<link rel="icon" href="${favicon}" />`;
|
18
|
+
const descriptionTag = !description ? '' : React.createElement("meta", { name: "description", content: description });
|
22
19
|
const Head = pageContext.config.Head || (() => React.createElement(React.Fragment, null));
|
23
20
|
const head = (React.createElement(React.StrictMode, null,
|
24
21
|
React.createElement(PageContextProvider, { pageContext: pageContext },
|
25
22
|
React.createElement(Head, null))));
|
26
|
-
const
|
27
|
-
const
|
23
|
+
const isSsrDisabled = !pageContext.Page;
|
24
|
+
const page = isSsrDisabled ? React.createElement(React.Fragment, null) : getPageElement(pageContext);
|
25
|
+
const htmlContent = (React.createElement(React.Fragment, null,
|
26
|
+
React.createElement("head", null,
|
27
|
+
React.createElement("meta", { charSet: "UTF-8" }),
|
28
|
+
faviconTag,
|
29
|
+
titleTag,
|
30
|
+
descriptionTag,
|
31
|
+
head),
|
32
|
+
React.createElement("body", null,
|
33
|
+
React.createElement("div", { id: "page-view" }, page))));
|
34
|
+
const streamOrString = isSsrDisabled
|
35
|
+
? dangerouslySkipEscape(renderToString(htmlContent))
|
36
|
+
: await renderToStream(htmlContent, { userAgent: pageContext.userAgent });
|
28
37
|
const documentHtml = escapeInject `<!DOCTYPE html>
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
${titleTag}
|
34
|
-
${descriptionTag}
|
35
|
-
${dangerouslySkipEscape(headHtml)}
|
36
|
-
</head>
|
37
|
-
<body>
|
38
|
-
<div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
|
39
|
-
</body>
|
40
|
-
<!-- built with https://github.com/vikejs/vike-react -->
|
41
|
-
</html>`;
|
38
|
+
<html lang='${lang}'>
|
39
|
+
${streamOrString}
|
40
|
+
<!-- built with https://github.com/vikejs/vike-react -->
|
41
|
+
</html>`;
|
42
42
|
return documentHtml;
|
43
43
|
};
|
44
44
|
function checkVikeVersion() {
|
package/dist/renderer/types.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "vike-react",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.4",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/renderer/+config.js",
|
6
6
|
"types": "./dist/renderer/+config.d.ts",
|
@@ -32,6 +32,9 @@
|
|
32
32
|
"typescript": "^5.2.2",
|
33
33
|
"vike": "^0.4.147"
|
34
34
|
},
|
35
|
+
"dependencies": {
|
36
|
+
"react-streaming": "^0.3.16"
|
37
|
+
},
|
35
38
|
"typesVersions": {
|
36
39
|
"*": {
|
37
40
|
".": [
|