vike-react 0.5.7 → 0.5.9

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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Romuald Brillout
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,2 +1 @@
1
- Docs: [vike.dev/vike-react](https://vike.dev/vike-react)
2
- Source code: [GitHub > vikejs/vike-react](https://github.com/vikejs/vike-react)
1
+ See [Vike Docs > vike-react](https://vike.dev/vike-react).
@@ -5,7 +5,7 @@ declare const config: {
5
5
  require: {
6
6
  vike: string;
7
7
  };
8
- Loading: "import:vike-react/__internal/components/Loading:default";
8
+ Loading: "import:vike-react/__internal/integration/Loading:default";
9
9
  onRenderHtml: "import:vike-react/__internal/integration/onRenderHtml:onRenderHtml";
10
10
  onRenderClient: "import:vike-react/__internal/integration/onRenderClient:onRenderClient";
11
11
  passToClient: string[];
@@ -102,6 +102,12 @@ declare const config: {
102
102
  server: true;
103
103
  };
104
104
  };
105
+ onBeforeRenderHtml: {
106
+ env: {
107
+ server: true;
108
+ };
109
+ cumulative: true;
110
+ };
105
111
  onAfterRenderHtml: {
106
112
  env: {
107
113
  server: true;
@@ -2,15 +2,17 @@ export { config as default };
2
2
  import { ssrEffect } from './integration/ssrEffect.js';
3
3
  import { isNotFalse } from './utils/isNotFalse.js';
4
4
  const config = {
5
+ // @eject-remove start
5
6
  name: 'vike-react',
6
7
  require: {
7
8
  vike: '>=0.4.182',
8
9
  },
9
- Loading: 'import:vike-react/__internal/components/Loading:default',
10
+ Loading: 'import:vike-react/__internal/integration/Loading:default',
10
11
  // https://vike.dev/onRenderHtml
11
12
  onRenderHtml: 'import:vike-react/__internal/integration/onRenderHtml:onRenderHtml',
12
13
  // https://vike.dev/onRenderClient
13
14
  onRenderClient: 'import:vike-react/__internal/integration/onRenderClient:onRenderClient',
15
+ // @eject-remove end
14
16
  passToClient: [
15
17
  '_configFromHook',
16
18
  // https://github.com/vikejs/vike-react/issues/25
@@ -78,6 +80,10 @@ const config = {
78
80
  streamIsRequired: {
79
81
  env: { server: true },
80
82
  },
83
+ onBeforeRenderHtml: {
84
+ env: { server: true },
85
+ cumulative: true,
86
+ },
81
87
  onAfterRenderHtml: {
82
88
  env: { server: true },
83
89
  cumulative: true,
@@ -102,6 +108,8 @@ const config = {
102
108
  },
103
109
  },
104
110
  };
111
+ // @eject-remove start
105
112
  // This is required to make TypeScript load the global interfaces Vike.Config and Vike.PageContext so that they're always loaded: we can assume that the user always imports this file over `import vikeReact from 'vike-react/config'`
106
113
  import './types/Config.js';
107
114
  import './types/PageContext.js';
115
+ // @eject-remove end
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default } from './+config.js';
1
+ export { default } from './config.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // TODO/next-major-release: 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
- export { default } from './+config.js';
3
+ export { default } from './config.js';
@@ -32,27 +32,26 @@ const onRenderHtml = async (pageContext) => {
32
32
  </html>`;
33
33
  };
34
34
  async function getPageHtml(pageContext) {
35
- let pageHtml;
36
- if (!pageContext.Page) {
37
- pageHtml = '';
38
- }
39
- else {
40
- const { page } = getPageElement(pageContext);
35
+ if (pageContext.Page)
36
+ pageContext.page = getPageElement(pageContext).page;
37
+ // https://github.com/vikejs/vike-react/issues/87#issuecomment-2488742744
38
+ await callCumulativeHooks(pageContext.config.onBeforeRenderHtml, pageContext);
39
+ let pageHtml = '';
40
+ if (pageContext.page) {
41
41
  const { stream, streamIsRequired } = pageContext.config;
42
42
  if (!stream && !streamIsRequired) {
43
- const pageHtmlString = renderToString(page);
43
+ const pageHtmlString = renderToString(pageContext.page);
44
44
  pageContext.pageHtmlString = pageHtmlString;
45
45
  pageHtml = dangerouslySkipEscape(pageHtmlString);
46
46
  }
47
47
  else {
48
- const disable = stream === false ? true : undefined;
49
- const pageHtmlStream = await renderToStream(page, {
48
+ const pageHtmlStream = await renderToStream(pageContext.page, {
50
49
  webStream: typeof stream === 'string' ? stream === 'web' : undefined,
51
50
  userAgent: pageContext.headers?.['user-agent'] ||
52
51
  // TODO/eventually: remove old way of acccessing the User Agent header.
53
52
  // @ts-ignore
54
53
  pageContext.userAgent,
55
- disable,
54
+ disable: stream === false ? true : undefined,
56
55
  });
57
56
  pageContext.pageHtmlStream = pageHtmlStream;
58
57
  pageHtml = pageHtmlStream;
@@ -1,4 +1,4 @@
1
- /* For components/Loading.tsx */
1
+ /* For integration/Loading.tsx */
2
2
  @keyframes vike-react-shine {
3
3
  to {
4
4
  background-position-x: -200%;
@@ -165,11 +165,17 @@ declare global {
165
165
  */
166
166
  reactStrictMode?: boolean;
167
167
  /**
168
- * Server-side hook called right after rendering the page's root React component to HTML.
168
+ * Hook called right before rendering the page's root React component to HTML.
169
+ *
170
+ * https://vike.dev/onBeforeRenderHtml
171
+ */
172
+ onBeforeRenderHtml?: ((pageContext: PageContextServer) => void) | ImportString;
173
+ /**
174
+ * Hook called right after rendering the page's root React component to HTML.
169
175
  *
170
176
  * https://vike.dev/onAfterRenderHtml
171
177
  */
172
- onAfterRenderHtml?: (pageContext: PageContextServer) => void;
178
+ onAfterRenderHtml?: ((pageContext: PageContextServer) => void) | ImportString;
173
179
  /**
174
180
  * Client-side hook called before the page is rendered.
175
181
  *
@@ -197,6 +203,7 @@ declare global {
197
203
  bodyHtmlEnd?: BodyHtmlBoundary[];
198
204
  bodyAttributes?: TagAttributes[];
199
205
  htmlAttributes?: TagAttributes[];
206
+ onBeforeRenderHtml?: Function[];
200
207
  onAfterRenderHtml?: Function[];
201
208
  onBeforeRenderClient?: Function[];
202
209
  onAfterRenderClient?: Function[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-react",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "repository": "https://github.com/vikejs/vike-react",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,10 +21,10 @@
21
21
  "./clientOnly": "./dist/helpers/clientOnly.js",
22
22
  "./ClientOnly": "./dist/components/ClientOnly.js",
23
23
  ".": "./dist/index.js",
24
- "./config": "./dist/+config.js",
24
+ "./config": "./dist/config.js",
25
25
  "./__internal/integration/onRenderHtml": "./dist/integration/onRenderHtml.js",
26
26
  "./__internal/integration/onRenderClient": "./dist/integration/onRenderClient.js",
27
- "./__internal/components/Loading": "./dist/components/Loading.js"
27
+ "./__internal/integration/Loading": "./dist/integration/Loading.js"
28
28
  },
29
29
  "dependencies": {
30
30
  "react-streaming": "^0.3.42"
@@ -34,17 +34,9 @@
34
34
  "react-dom": ">=18.0.0",
35
35
  "vike": ">=0.4.182"
36
36
  },
37
- "scripts": {
38
- "dev": "tsc --watch",
39
- "build": "rimraf dist/ && tsc && pnpm run build:css",
40
- "build:css": "cp src/integration/styles.css dist/integration/styles.css",
41
- "release": "release-me patch",
42
- "release:minor": "release-me minor",
43
- "release:commit": "release-me commit"
44
- },
45
37
  "devDependencies": {
46
38
  "@biomejs/biome": "^1.6.4",
47
- "@brillout/release-me": "^0.3.8",
39
+ "@brillout/release-me": "^0.4.2",
48
40
  "@types/node": "^20.11.17",
49
41
  "@types/react": "^18.2.55",
50
42
  "@types/react-dom": "^18.2.19",
@@ -53,7 +45,7 @@
53
45
  "react-streaming": "^0.3.43",
54
46
  "rimraf": "^5.0.5",
55
47
  "typescript": "^5.5.4",
56
- "vike": "^0.4.191",
48
+ "vike": "^0.4.203",
57
49
  "vite": "^5.4.0"
58
50
  },
59
51
  "typesVersions": {
@@ -83,7 +75,7 @@
83
75
  "./dist/index.d.ts"
84
76
  ],
85
77
  "config": [
86
- "./dist/+config.d.ts"
78
+ "./dist/config.d.ts"
87
79
  ],
88
80
  "__/internal/integration/onRenderHtml": [
89
81
  "./dist/integration/onRenderHtml.d.ts"
@@ -101,5 +93,13 @@
101
93
  "license": "MIT",
102
94
  "keywords": [
103
95
  "react"
104
- ]
105
- }
96
+ ],
97
+ "scripts": {
98
+ "dev": "tsc --watch",
99
+ "build": "rimraf dist/ && tsc && pnpm run build:css",
100
+ "build:css": "cp src/integration/styles.css dist/integration/styles.css",
101
+ "release": "release-me patch",
102
+ "release:minor": "release-me minor",
103
+ "release:commit": "release-me commit"
104
+ }
105
+ }
File without changes
File without changes