vike-react 0.5.13 → 0.6.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.
@@ -1,7 +1,7 @@
1
1
  export { ClientOnly };
2
2
  import React, { lazy, useEffect, useState, startTransition } from 'react';
3
3
  function ClientOnly({ load, children, fallback, deps = [], }) {
4
- // TODO/next-major-release: remove this file/export
4
+ // TODO/next-major: remove this file/export
5
5
  console.warn('[vike-react][warning] <ClientOnly> is deprecated: use clientOnly() instead https://vike.dev/clientOnly');
6
6
  const [Component, setComponent] = useState(null);
7
7
  useEffect(() => {
package/dist/config.js CHANGED
@@ -100,6 +100,7 @@ const config = {
100
100
  cumulative: true,
101
101
  env: { client: true, server: true },
102
102
  },
103
+ // TODO/next-major: move to +react.js > strictMode ?
103
104
  reactStrictMode: {
104
105
  env: { client: true, server: true },
105
106
  },
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- // TODO/next-major-release: remove this file/export
1
+ // TODO/next-major: remove this file/export
2
2
  console.warn("[vike-react][warning][deprecation] Replace `import vikeReact from 'vike-react'` with `import vikeReact from 'vike-react/config'` (typically in your /pages/+config.js)");
3
3
  export { default } from './config.js';
@@ -9,16 +9,29 @@ import { getHeadSetting } from './getHeadSetting.js';
9
9
  import { getPageElement } from './getPageElement.js';
10
10
  import { isReactElement } from '../utils/isReactElement.js';
11
11
  import { getTagAttributesString } from '../utils/getTagAttributesString.js';
12
+ import { assert } from '../utils/assert.js';
12
13
  import { callCumulativeHooks } from '../utils/callCumulativeHooks.js';
13
14
  import { resolveReactOptions } from './resolveReactOptions.js';
14
15
  addEcosystemStamp();
15
16
  const onRenderHtml = async (pageContext) => {
16
- const pageHtml = await getPageHtml(pageContext);
17
+ await renderPageToHtml(pageContext);
17
18
  const headHtml = getHeadHtml(pageContext);
18
19
  const { bodyHtmlBegin, bodyHtmlEnd } = await getBodyHtmlBoundary(pageContext);
19
20
  const { htmlAttributesString, bodyAttributesString } = getTagAttributes(pageContext);
20
21
  // Not needed on the client-side, thus we remove it to save KBs sent to the client
21
22
  delete pageContext._configFromHook;
23
+ // pageContext.{pageHtmlString,pageHtmlStream} is set by renderPageToHtml() and can be overridden by user at onAfterRenderHtml()
24
+ let pageHtmlStringOrStream =
25
+ // Set to empty string if SSR is disabled
26
+ '';
27
+ if (pageContext.pageHtmlString) {
28
+ assert(pageContext.pageHtmlStream === undefined);
29
+ pageHtmlStringOrStream = dangerouslySkipEscape(pageContext.pageHtmlString);
30
+ }
31
+ if (pageContext.pageHtmlStream) {
32
+ assert(pageContext.pageHtmlString === undefined);
33
+ pageHtmlStringOrStream = pageContext.pageHtmlStream;
34
+ }
22
35
  return escapeInject `<!DOCTYPE html>
23
36
  <html${dangerouslySkipEscape(htmlAttributesString)}>
24
37
  <head>
@@ -27,24 +40,22 @@ const onRenderHtml = async (pageContext) => {
27
40
  </head>
28
41
  <body${dangerouslySkipEscape(bodyAttributesString)}>
29
42
  ${bodyHtmlBegin}
30
- <div id="root">${pageHtml}</div>
43
+ <div id="root">${pageHtmlStringOrStream}</div>
31
44
  ${bodyHtmlEnd}
32
45
  </body>
33
46
  </html>`;
34
47
  };
35
- async function getPageHtml(pageContext) {
48
+ async function renderPageToHtml(pageContext) {
36
49
  if (pageContext.Page)
37
50
  pageContext.page = getPageElement(pageContext).page;
38
51
  // https://github.com/vikejs/vike-react/issues/87#issuecomment-2488742744
39
52
  await callCumulativeHooks(pageContext.config.onBeforeRenderHtml, pageContext);
40
53
  const { renderToStringOptions } = resolveReactOptions(pageContext);
41
- let pageHtml = '';
42
54
  if (pageContext.page) {
43
55
  const { stream, streamIsRequired } = pageContext.config;
44
56
  if (!stream && !streamIsRequired) {
45
57
  const pageHtmlString = renderToString(pageContext.page, renderToStringOptions);
46
58
  pageContext.pageHtmlString = pageHtmlString;
47
- pageHtml = dangerouslySkipEscape(pageHtmlString);
48
59
  }
49
60
  else {
50
61
  const pageHtmlStream = await renderToStream(pageContext.page, {
@@ -56,12 +67,10 @@ async function getPageHtml(pageContext) {
56
67
  disable: stream === false ? true : undefined,
57
68
  });
58
69
  pageContext.pageHtmlStream = pageHtmlStream;
59
- pageHtml = pageHtmlStream;
60
70
  }
61
71
  }
62
72
  // https://github.com/vikejs/vike/discussions/1804#discussioncomment-10394481
63
73
  await callCumulativeHooks(pageContext.config.onAfterRenderHtml, pageContext);
64
- return pageHtml;
65
74
  }
66
75
  function getHeadHtml(pageContext) {
67
76
  pageContext._headAlreadySet = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-react",
3
- "version": "0.5.13",
3
+ "version": "0.6.1",
4
4
  "repository": "https://github.com/vikejs/vike-react",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,19 +27,19 @@
27
27
  "./__internal/integration/Loading": "./dist/integration/Loading.js"
28
28
  },
29
29
  "dependencies": {
30
- "react-streaming": "^0.3.48"
30
+ "react-streaming": "^0.4.2"
31
31
  },
32
32
  "peerDependencies": {
33
- "react": ">=18.0.0",
34
- "react-dom": ">=18.0.0",
33
+ "react": ">=19",
34
+ "react-dom": ">=19",
35
35
  "vike": ">=0.4.182"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@biomejs/biome": "^1.6.4",
39
39
  "@brillout/release-me": "^0.4.2",
40
40
  "@types/node": "^20.11.17",
41
- "@types/react": "^19.0.8",
42
- "@types/react-dom": "^19.0.3",
41
+ "@types/react": "^19.0.10",
42
+ "@types/react-dom": "^19.0.4",
43
43
  "react": "^19.0.0",
44
44
  "react-dom": "^19.0.0",
45
45
  "rimraf": "^5.0.5",