vike-react 0.3.2 → 0.3.3

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.
@@ -3,6 +3,9 @@ import React from 'react';
3
3
  import { PageContextProvider } from './PageContextProvider.js';
4
4
  function getPageElement(pageContext) {
5
5
  var _a;
6
+ if (!pageContext.Page) {
7
+ return React.createElement(React.Fragment, null);
8
+ }
6
9
  const Layout = (_a = pageContext.config.Layout) !== null && _a !== void 0 ? _a : PassThrough;
7
10
  const Wrapper =
8
11
  /* Should we implement this? Enabling users to defined a wrapper that is used across all layouts.
@@ -1,44 +1,39 @@
1
1
  // https://vike.dev/onRenderHtml
2
2
  export { onRenderHtml };
3
- import { renderToString } from 'react-dom/server';
4
- import { escapeInject, dangerouslySkipEscape, version } from 'vike/server';
3
+ import { renderToStream } from 'react-streaming/server';
4
+ import { escapeInject, version } from 'vike/server';
5
5
  import { getTitle } from './getTitle.js';
6
6
  import { getPageElement } from './getPageElement.js';
7
7
  import { PageContextProvider } from './PageContextProvider.js';
8
8
  import React from 'react';
9
9
  checkVikeVersion();
10
10
  const onRenderHtml = async (pageContext) => {
11
- let pageHtml = '';
12
- if (!!pageContext.Page) {
13
- const page = getPageElement(pageContext);
14
- pageHtml = renderToString(page);
15
- }
11
+ const lang = pageContext.config.lang || 'en';
12
+ const { favicon } = pageContext.config;
13
+ const faviconTag = !favicon ? '' : React.createElement("link", { rel: "icon", href: favicon });
16
14
  const title = getTitle(pageContext);
17
- const titleTag = !title ? '' : escapeInject `<title>${title}</title>`;
15
+ const titleTag = !title ? '' : React.createElement("title", null, title);
18
16
  const { description } = pageContext.config;
19
- const descriptionTag = !description ? '' : escapeInject `<meta name="description" content="${description}" />`;
20
- const { favicon } = pageContext.config;
21
- const faviconTag = !favicon ? '' : escapeInject `<link rel="icon" href="${favicon}" />`;
17
+ const descriptionTag = !description ? '' : React.createElement("meta", { name: "description", content: description });
22
18
  const Head = pageContext.config.Head || (() => React.createElement(React.Fragment, null));
23
19
  const head = (React.createElement(React.StrictMode, null,
24
20
  React.createElement(PageContextProvider, { pageContext: pageContext },
25
21
  React.createElement(Head, null))));
26
- const headHtml = renderToString(head);
27
- const lang = pageContext.config.lang || 'en';
22
+ const page = getPageElement(pageContext);
23
+ const stream = await renderToStream(React.createElement(React.Fragment, null,
24
+ React.createElement("head", null,
25
+ React.createElement("meta", { charSet: "UTF-8" }),
26
+ faviconTag,
27
+ titleTag,
28
+ descriptionTag,
29
+ head),
30
+ React.createElement("body", null,
31
+ React.createElement("div", { id: "page-view" }, page))), { userAgent: pageContext.userAgent });
28
32
  const documentHtml = escapeInject `<!DOCTYPE html>
29
- <html lang='${lang}'>
30
- <head>
31
- <meta charset="UTF-8" />
32
- ${faviconTag}
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>`;
33
+ <html lang='${lang}'>
34
+ ${stream}
35
+ <!-- built with https://github.com/vikejs/vike-react -->
36
+ </html>`;
42
37
  return documentHtml;
43
38
  };
44
39
  function checkVikeVersion() {
@@ -9,6 +9,7 @@ declare global {
9
9
  pageProps?: Record<string, unknown>;
10
10
  /** &lt;title>${title}&lt;/title> - has precedence over the config */
11
11
  title?: string;
12
+ userAgent?: string;
12
13
  }
13
14
  }
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-react",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
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
  ".": [