vike-react 0.5.3 → 0.5.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.
- package/dist/+config.d.ts +10 -3
- package/dist/+config.js +10 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/renderer/onRenderHtml.d.ts +2 -0
- package/dist/renderer/onRenderHtml.js +9 -2
- package/dist/types/Config.d.ts +9 -1
- package/dist/types/PageContext.d.ts +5 -0
- package/dist/utils/callCumulativeHooks.d.ts +2 -1
- package/dist/utils/callCumulativeHooks.js +4 -1
- package/package.json +19 -16
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +0 -2
package/dist/+config.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
export { config };
|
1
2
|
import { ssrEffect } from './renderer/ssrEffect.js';
|
2
|
-
|
3
|
-
declare const _default: {
|
3
|
+
declare const config: {
|
4
4
|
name: string;
|
5
5
|
require: {
|
6
6
|
vike: string;
|
@@ -88,6 +88,12 @@ declare const _default: {
|
|
88
88
|
server: true;
|
89
89
|
};
|
90
90
|
};
|
91
|
+
onAfterRenderHtml: {
|
92
|
+
env: {
|
93
|
+
server: true;
|
94
|
+
};
|
95
|
+
cumulative: true;
|
96
|
+
};
|
91
97
|
onBeforeRenderClient: {
|
92
98
|
env: {
|
93
99
|
client: true;
|
@@ -121,4 +127,5 @@ declare const _default: {
|
|
121
127
|
};
|
122
128
|
};
|
123
129
|
};
|
124
|
-
|
130
|
+
import './types/Config.js';
|
131
|
+
import './types/PageContext.js';
|
package/dist/+config.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
1
|
+
export { config };
|
2
2
|
import { ssrEffect } from './renderer/ssrEffect.js';
|
3
|
-
|
4
|
-
|
5
|
-
export default {
|
3
|
+
import { isNotFalse } from './utils/isNotFalse.js';
|
4
|
+
const config = {
|
6
5
|
name: 'vike-react',
|
7
6
|
require: {
|
8
7
|
vike: '>=0.4.182'
|
@@ -69,6 +68,10 @@ export default {
|
|
69
68
|
streamIsRequired: {
|
70
69
|
env: { server: true }
|
71
70
|
},
|
71
|
+
onAfterRenderHtml: {
|
72
|
+
env: { server: true },
|
73
|
+
cumulative: true
|
74
|
+
},
|
72
75
|
onBeforeRenderClient: {
|
73
76
|
env: { client: true },
|
74
77
|
cumulative: true
|
@@ -89,3 +92,6 @@ export default {
|
|
89
92
|
}
|
90
93
|
}
|
91
94
|
};
|
95
|
+
// 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'`
|
96
|
+
import './types/Config.js';
|
97
|
+
import './types/PageContext.js';
|
package/dist/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { default } from './+config.js';
|
1
|
+
export { config as 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 { config as default } from './+config.js';
|
@@ -1,4 +1,6 @@
|
|
1
1
|
export { onRenderHtml };
|
2
|
+
import { renderToStream } from 'react-streaming/server';
|
2
3
|
import type { OnRenderHtmlAsync } from 'vike/types';
|
3
4
|
declare const onRenderHtml: OnRenderHtmlAsync;
|
5
|
+
export type PageHtmlStream = Awaited<ReturnType<typeof renderToStream>>;
|
4
6
|
export type Viewport = 'responsive' | number | null;
|
@@ -9,6 +9,7 @@ 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 { callCumulativeHooks } from '../utils/callCumulativeHooks.js';
|
12
13
|
addEcosystemStamp();
|
13
14
|
const onRenderHtml = async (pageContext) => {
|
14
15
|
const pageHtml = await getPageHtml(pageContext);
|
@@ -36,11 +37,13 @@ async function getPageHtml(pageContext) {
|
|
36
37
|
const page = getPageElement(pageContext);
|
37
38
|
const { stream, streamIsRequired } = pageContext.config;
|
38
39
|
if (!stream && !streamIsRequired) {
|
39
|
-
|
40
|
+
const pageHtmlString = renderToString(page);
|
41
|
+
pageContext.pageHtmlString = pageHtmlString;
|
42
|
+
pageHtml = dangerouslySkipEscape(pageHtmlString);
|
40
43
|
}
|
41
44
|
else {
|
42
45
|
const disable = stream === false ? true : undefined;
|
43
|
-
|
46
|
+
const pageHtmlStream = await renderToStream(page, {
|
44
47
|
webStream: typeof stream === 'string' ? stream === 'web' : undefined,
|
45
48
|
userAgent: pageContext.headers?.['user-agent'] ||
|
46
49
|
// TODO/eventually: remove old way of acccessing the User Agent header.
|
@@ -48,8 +51,12 @@ async function getPageHtml(pageContext) {
|
|
48
51
|
pageContext.userAgent,
|
49
52
|
disable
|
50
53
|
});
|
54
|
+
pageContext.pageHtmlStream = pageHtmlStream;
|
55
|
+
pageHtml = pageHtmlStream;
|
51
56
|
}
|
52
57
|
}
|
58
|
+
// https://github.com/vikejs/vike/discussions/1804#discussioncomment-10394481
|
59
|
+
await callCumulativeHooks(pageContext.config.onAfterRenderHtml, pageContext);
|
53
60
|
return pageHtml;
|
54
61
|
}
|
55
62
|
function getHeadHtml(pageContext) {
|
package/dist/types/Config.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ImportString,
|
1
|
+
import type { ImportString, PageContextServer, PageContext, PageContextClient } from 'vike/types';
|
2
2
|
import type { TagAttributes } from '../utils/getTagAttributesString.js';
|
3
3
|
import type { Viewport } from '../renderer/onRenderHtml.js';
|
4
4
|
import type { ConfigsCumulative } from '../hooks/useConfig/configsCumulative.js';
|
@@ -152,6 +152,12 @@ declare global {
|
|
152
152
|
* https://vike.dev/reactStrictMode
|
153
153
|
*/
|
154
154
|
reactStrictMode?: boolean;
|
155
|
+
/**
|
156
|
+
* Server-side hook called right after rendering the page's root React component to HTML.
|
157
|
+
*
|
158
|
+
* https://vike.dev/onAfterRenderHtml
|
159
|
+
*/
|
160
|
+
onAfterRenderHtml?: (pageContext: PageContextServer) => void;
|
155
161
|
/**
|
156
162
|
* Client-side hook called before the page is rendered.
|
157
163
|
*
|
@@ -177,11 +183,13 @@ declare global {
|
|
177
183
|
Head?: Head[];
|
178
184
|
bodyAttributes?: TagAttributes[];
|
179
185
|
htmlAttributes?: TagAttributes[];
|
186
|
+
onAfterRenderHtml?: Function[];
|
180
187
|
onBeforeRenderClient?: Function[];
|
181
188
|
onAfterRenderClient?: Function[];
|
182
189
|
}
|
183
190
|
}
|
184
191
|
}
|
192
|
+
type PageContext_ = PageContext;
|
185
193
|
export type Head = React.ReactNode | (() => React.ReactNode);
|
186
194
|
type Wrapper = (props: {
|
187
195
|
children: React.ReactNode;
|
@@ -2,6 +2,7 @@ import type React from 'react';
|
|
2
2
|
import type { JSX } from 'react';
|
3
3
|
import type ReactDOM from 'react-dom/client';
|
4
4
|
import type { ConfigFromHookResolved } from './Config.js';
|
5
|
+
import type { PageHtmlStream } from '../renderer/onRenderHtml.js';
|
5
6
|
declare global {
|
6
7
|
namespace Vike {
|
7
8
|
interface PageContext {
|
@@ -11,6 +12,10 @@ declare global {
|
|
11
12
|
page?: JSX.Element;
|
12
13
|
/** The React root DOM container */
|
13
14
|
root?: ReactDOM.Root;
|
15
|
+
/** The +Page.jsx component rendered to the HTML string. */
|
16
|
+
pageHtmlString?: string;
|
17
|
+
/** The +Pagejsx component rendered to an HTML stream. */
|
18
|
+
pageHtmlStream?: PageHtmlStream;
|
14
19
|
}
|
15
20
|
}
|
16
21
|
}
|
@@ -1 +1,2 @@
|
|
1
|
-
export
|
1
|
+
export { callCumulativeHooks };
|
2
|
+
declare function callCumulativeHooks(values: undefined | unknown[], pageContext: Record<string, any>): Promise<unknown[]>;
|
@@ -1,8 +1,11 @@
|
|
1
|
-
export
|
1
|
+
export { callCumulativeHooks };
|
2
|
+
import { providePageContext } from 'vike/getPageContext';
|
3
|
+
async function callCumulativeHooks(values, pageContext) {
|
2
4
|
if (!values)
|
3
5
|
return [];
|
4
6
|
const valuesPromises = values.map((val) => {
|
5
7
|
if (typeof val === 'function') {
|
8
|
+
providePageContext(pageContext);
|
6
9
|
// Hook
|
7
10
|
return val(pageContext);
|
8
11
|
}
|
package/package.json
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "vike-react",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.4",
|
4
|
+
"repository": "https://github.com/vikejs/vike-react",
|
4
5
|
"type": "module",
|
5
|
-
"main": "./dist/index.js",
|
6
|
-
"types": "./dist/index.d.ts",
|
7
6
|
"exports": {
|
8
|
-
"./useData": "./dist/hooks/useData.js",
|
9
7
|
"./usePageContext": "./dist/hooks/usePageContext.js",
|
8
|
+
"./useData": "./dist/hooks/useData.js",
|
10
9
|
"./useConfig": {
|
11
10
|
"browser": "./dist/hooks/useConfig/useConfig-client.js",
|
12
11
|
"default": "./dist/hooks/useConfig/useConfig-server.js"
|
@@ -19,14 +18,22 @@
|
|
19
18
|
"browser": "./dist/components/Head/Head-client.js",
|
20
19
|
"default": "./dist/components/Head/Head-server.js"
|
21
20
|
},
|
22
|
-
"./ClientOnly": "./dist/components/ClientOnly.js",
|
23
21
|
"./clientOnly": "./dist/helpers/clientOnly.js",
|
22
|
+
"./ClientOnly": "./dist/components/ClientOnly.js",
|
24
23
|
".": "./dist/index.js",
|
25
24
|
"./config": "./dist/+config.js",
|
26
25
|
"./renderer/onRenderHtml": "./dist/renderer/onRenderHtml.js",
|
27
26
|
"./renderer/onRenderClient": "./dist/renderer/onRenderClient.js",
|
28
27
|
"./components/Loading": "./dist/components/Loading.js"
|
29
28
|
},
|
29
|
+
"dependencies": {
|
30
|
+
"react-streaming": "^0.3.42"
|
31
|
+
},
|
32
|
+
"peerDependencies": {
|
33
|
+
"react": ">=18.0.0",
|
34
|
+
"react-dom": ">=18.0.0",
|
35
|
+
"vike": ">=0.4.182"
|
36
|
+
},
|
30
37
|
"scripts": {
|
31
38
|
"dev": "tsc --watch",
|
32
39
|
"build": "rimraf dist/ && tsc && pnpm run build:css",
|
@@ -35,11 +42,6 @@
|
|
35
42
|
"release:minor": "release-me minor",
|
36
43
|
"release:commit": "release-me commit"
|
37
44
|
},
|
38
|
-
"peerDependencies": {
|
39
|
-
"react": ">=18.0.0",
|
40
|
-
"react-dom": ">=18.0.0",
|
41
|
-
"vike": ">=0.4.182"
|
42
|
-
},
|
43
45
|
"devDependencies": {
|
44
46
|
"@biomejs/biome": "^1.6.4",
|
45
47
|
"@brillout/release-me": "^0.3.8",
|
@@ -51,12 +53,9 @@
|
|
51
53
|
"react-streaming": "^0.3.43",
|
52
54
|
"rimraf": "^5.0.5",
|
53
55
|
"typescript": "^5.5.4",
|
54
|
-
"vike": "^0.4.
|
56
|
+
"vike": "^0.4.191",
|
55
57
|
"vite": "^5.4.0"
|
56
58
|
},
|
57
|
-
"dependencies": {
|
58
|
-
"react-streaming": "^0.3.42"
|
59
|
-
},
|
60
59
|
"typesVersions": {
|
61
60
|
"*": {
|
62
61
|
"useData": [
|
@@ -94,9 +93,13 @@
|
|
94
93
|
]
|
95
94
|
}
|
96
95
|
},
|
96
|
+
"main": "./dist/index.js",
|
97
|
+
"types": "./dist/index.d.ts",
|
97
98
|
"files": [
|
98
99
|
"dist/"
|
99
100
|
],
|
100
|
-
"
|
101
|
-
"
|
101
|
+
"license": "MIT",
|
102
|
+
"keywords": [
|
103
|
+
"react"
|
104
|
+
]
|
102
105
|
}
|
package/dist/types/index.d.ts
DELETED
package/dist/types/index.js
DELETED