vike-react 0.5.3 → 0.5.5
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 +28 -7
- package/dist/+config.js +45 -29
- package/dist/components/ClientOnly.d.ts +1 -1
- package/dist/components/ClientOnly.js +2 -2
- package/dist/components/Loading.js +2 -2
- package/dist/helpers/clientOnly.js +1 -1
- package/dist/hooks/useConfig/useConfig-client.js +1 -1
- package/dist/hooks/usePageContext.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{renderer → integration}/getHeadSetting.js +1 -1
- package/dist/{renderer → integration}/getPageElement.js +2 -2
- package/dist/{renderer → integration}/onRenderClient.js +2 -2
- package/dist/{renderer → integration}/onRenderHtml.d.ts +2 -0
- package/dist/{renderer → integration}/onRenderHtml.js +19 -4
- package/dist/{renderer → integration}/ssrEffect.js +3 -3
- package/dist/types/Config.d.ts +25 -2
- 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 +27 -24
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +0 -2
- /package/dist/{renderer → integration}/applyHeadSettings.d.ts +0 -0
- /package/dist/{renderer → integration}/applyHeadSettings.js +0 -0
- /package/dist/{renderer → integration}/getHeadSetting.d.ts +0 -0
- /package/dist/{renderer → integration}/getPageElement.d.ts +0 -0
- /package/dist/{renderer → integration}/onRenderClient.d.ts +0 -0
- /package/dist/{renderer → integration}/ssrEffect.d.ts +0 -0
- /package/dist/{renderer → integration}/styles.css +0 -0
package/dist/+config.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
import './
|
3
|
-
declare const
|
1
|
+
export { config };
|
2
|
+
import { ssrEffect } from './integration/ssrEffect.js';
|
3
|
+
declare const config: {
|
4
4
|
name: string;
|
5
5
|
require: {
|
6
6
|
vike: string;
|
7
7
|
};
|
8
|
-
Loading: "import:vike-react/components/Loading:default";
|
9
|
-
onRenderHtml: "import:vike-react/
|
10
|
-
onRenderClient: "import:vike-react/
|
8
|
+
Loading: "import:vike-react/__internal/components/Loading:default";
|
9
|
+
onRenderHtml: "import:vike-react/__internal/integration/onRenderHtml:onRenderHtml";
|
10
|
+
onRenderClient: "import:vike-react/__internal/integration/onRenderClient:onRenderClient";
|
11
11
|
passToClient: string[];
|
12
12
|
clientRouting: true;
|
13
13
|
hydrationCanBeAborted: true;
|
@@ -58,6 +58,20 @@ declare const _default: {
|
|
58
58
|
client: true;
|
59
59
|
};
|
60
60
|
};
|
61
|
+
bodyHtmlBegin: {
|
62
|
+
env: {
|
63
|
+
server: true;
|
64
|
+
};
|
65
|
+
cumulative: true;
|
66
|
+
global: true;
|
67
|
+
};
|
68
|
+
bodyHtmlEnd: {
|
69
|
+
env: {
|
70
|
+
server: true;
|
71
|
+
};
|
72
|
+
cumulative: true;
|
73
|
+
global: true;
|
74
|
+
};
|
61
75
|
htmlAttributes: {
|
62
76
|
env: {
|
63
77
|
server: true;
|
@@ -88,6 +102,12 @@ declare const _default: {
|
|
88
102
|
server: true;
|
89
103
|
};
|
90
104
|
};
|
105
|
+
onAfterRenderHtml: {
|
106
|
+
env: {
|
107
|
+
server: true;
|
108
|
+
};
|
109
|
+
cumulative: true;
|
110
|
+
};
|
91
111
|
onBeforeRenderClient: {
|
92
112
|
env: {
|
93
113
|
client: true;
|
@@ -121,4 +141,5 @@ declare const _default: {
|
|
121
141
|
};
|
122
142
|
};
|
123
143
|
};
|
124
|
-
|
144
|
+
import './types/Config.js';
|
145
|
+
import './types/PageContext.js';
|
package/dist/+config.js
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
+
export { config };
|
2
|
+
import { ssrEffect } from './integration/ssrEffect.js';
|
1
3
|
import { isNotFalse } from './utils/isNotFalse.js';
|
2
|
-
|
3
|
-
// This is required to make TypeScript load the global interfaces such as 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'`
|
4
|
-
import './types/index.js';
|
5
|
-
export default {
|
4
|
+
const config = {
|
6
5
|
name: 'vike-react',
|
7
6
|
require: {
|
8
|
-
vike: '>=0.4.182'
|
7
|
+
vike: '>=0.4.182',
|
9
8
|
},
|
10
|
-
Loading: 'import:vike-react/components/Loading:default',
|
9
|
+
Loading: 'import:vike-react/__internal/components/Loading:default',
|
11
10
|
// https://vike.dev/onRenderHtml
|
12
|
-
onRenderHtml: 'import:vike-react/
|
11
|
+
onRenderHtml: 'import:vike-react/__internal/integration/onRenderHtml:onRenderHtml',
|
13
12
|
// https://vike.dev/onRenderClient
|
14
|
-
onRenderClient: 'import:vike-react/
|
13
|
+
onRenderClient: 'import:vike-react/__internal/integration/onRenderClient:onRenderClient',
|
15
14
|
passToClient: [
|
16
15
|
'_configFromHook',
|
17
16
|
// https://github.com/vikejs/vike-react/issues/25
|
18
|
-
process.env.NODE_ENV !== 'production' && '$$typeof'
|
17
|
+
process.env.NODE_ENV !== 'production' && '$$typeof',
|
19
18
|
].filter(isNotFalse),
|
20
19
|
// https://vike.dev/clientRouting
|
21
20
|
clientRouting: true,
|
@@ -24,68 +23,85 @@ export default {
|
|
24
23
|
meta: {
|
25
24
|
Head: {
|
26
25
|
env: { server: true },
|
27
|
-
cumulative: true
|
26
|
+
cumulative: true,
|
28
27
|
},
|
29
28
|
Layout: {
|
30
29
|
env: { server: true, client: true },
|
31
|
-
cumulative: true
|
30
|
+
cumulative: true,
|
32
31
|
},
|
33
32
|
title: {
|
34
|
-
env: { server: true, client: true }
|
33
|
+
env: { server: true, client: true },
|
35
34
|
},
|
36
35
|
description: {
|
37
|
-
env: { server: true }
|
36
|
+
env: { server: true },
|
38
37
|
},
|
39
38
|
image: {
|
40
|
-
env: { server: true }
|
39
|
+
env: { server: true },
|
41
40
|
},
|
42
41
|
viewport: {
|
43
|
-
env: { server: true }
|
42
|
+
env: { server: true },
|
44
43
|
},
|
45
44
|
favicon: {
|
46
45
|
env: { server: true },
|
47
|
-
global: true
|
46
|
+
global: true,
|
48
47
|
},
|
49
48
|
lang: {
|
50
|
-
env: { server: true, client: true }
|
49
|
+
env: { server: true, client: true },
|
50
|
+
},
|
51
|
+
bodyHtmlBegin: {
|
52
|
+
env: { server: true },
|
53
|
+
cumulative: true,
|
54
|
+
global: true,
|
55
|
+
},
|
56
|
+
bodyHtmlEnd: {
|
57
|
+
env: { server: true },
|
58
|
+
cumulative: true,
|
59
|
+
global: true,
|
51
60
|
},
|
52
61
|
htmlAttributes: {
|
53
62
|
env: { server: true },
|
54
63
|
global: true,
|
55
|
-
cumulative: true // for Vike extensions
|
64
|
+
cumulative: true, // for Vike extensions
|
56
65
|
},
|
57
66
|
bodyAttributes: {
|
58
67
|
env: { server: true },
|
59
68
|
global: true,
|
60
|
-
cumulative: true // for Vike extensions
|
69
|
+
cumulative: true, // for Vike extensions
|
61
70
|
},
|
62
71
|
ssr: {
|
63
72
|
env: { config: true },
|
64
|
-
effect: ssrEffect
|
73
|
+
effect: ssrEffect,
|
65
74
|
},
|
66
75
|
stream: {
|
67
|
-
env: { server: true }
|
76
|
+
env: { server: true },
|
68
77
|
},
|
69
78
|
streamIsRequired: {
|
70
|
-
env: { server: true }
|
79
|
+
env: { server: true },
|
80
|
+
},
|
81
|
+
onAfterRenderHtml: {
|
82
|
+
env: { server: true },
|
83
|
+
cumulative: true,
|
71
84
|
},
|
72
85
|
onBeforeRenderClient: {
|
73
86
|
env: { client: true },
|
74
|
-
cumulative: true
|
87
|
+
cumulative: true,
|
75
88
|
},
|
76
89
|
onAfterRenderClient: {
|
77
90
|
env: { client: true },
|
78
|
-
cumulative: true
|
91
|
+
cumulative: true,
|
79
92
|
},
|
80
93
|
Wrapper: {
|
81
94
|
cumulative: true,
|
82
|
-
env: { client: true, server: true }
|
95
|
+
env: { client: true, server: true },
|
83
96
|
},
|
84
97
|
reactStrictMode: {
|
85
|
-
env: { client: true, server: true }
|
98
|
+
env: { client: true, server: true },
|
86
99
|
},
|
87
100
|
Loading: {
|
88
|
-
env: { server: true, client: true }
|
89
|
-
}
|
90
|
-
}
|
101
|
+
env: { server: true, client: true },
|
102
|
+
},
|
103
|
+
},
|
91
104
|
};
|
105
|
+
// 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
|
+
import './types/Config.js';
|
107
|
+
import './types/PageContext.js';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export { ClientOnly };
|
2
2
|
import React, { useEffect } from 'react';
|
3
3
|
import type { ReactNode } from 'react';
|
4
|
-
declare function ClientOnly<T>({ load, children, fallback, deps }: {
|
4
|
+
declare function ClientOnly<T>({ load, children, fallback, deps, }: {
|
5
5
|
load: () => Promise<{
|
6
6
|
default: React.ComponentType<T>;
|
7
7
|
} | React.ComponentType<T>>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
export { ClientOnly };
|
2
2
|
import React, { lazy, useEffect, useState, startTransition } from 'react';
|
3
|
-
function ClientOnly({ load, children, fallback, deps = [] }) {
|
3
|
+
function ClientOnly({ load, children, fallback, deps = [], }) {
|
4
4
|
// TODO/next-major-release: 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);
|
@@ -9,7 +9,7 @@ function ClientOnly({ load, children, fallback, deps = [] }) {
|
|
9
9
|
const Component = lazy(() => load()
|
10
10
|
.then((LoadedComponent) => {
|
11
11
|
return {
|
12
|
-
default: () => children('default' in LoadedComponent ? LoadedComponent.default : LoadedComponent)
|
12
|
+
default: () => children('default' in LoadedComponent ? LoadedComponent.default : LoadedComponent),
|
13
13
|
};
|
14
14
|
})
|
15
15
|
.catch((error) => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
export default {
|
3
|
-
component: LoadingComponent
|
3
|
+
component: LoadingComponent,
|
4
4
|
};
|
5
5
|
function LoadingComponent() {
|
6
6
|
return (React.createElement("div", { style: {
|
@@ -11,6 +11,6 @@ function LoadingComponent() {
|
|
11
11
|
borderRadius: '5px',
|
12
12
|
backgroundSize: '200% 100%',
|
13
13
|
animation: '1.3s vike-react-shine linear infinite',
|
14
|
-
aspectRatio: '2.5/1'
|
14
|
+
aspectRatio: '2.5/1',
|
15
15
|
} }));
|
16
16
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export { clientOnly };
|
2
|
-
import React, { Suspense, forwardRef, lazy, useEffect, useState } from 'react';
|
2
|
+
import React, { Suspense, forwardRef, lazy, useEffect, useState, } from 'react';
|
3
3
|
function clientOnly(load) {
|
4
4
|
var _a;
|
5
5
|
// Client side: always bundled by Vite, import.meta.env.SSR === false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export { useConfig };
|
2
2
|
import { usePageContext } from '../usePageContext.js';
|
3
3
|
import { getPageContext } from 'vike/getPageContext';
|
4
|
-
import { applyHeadSettings } from '../../
|
4
|
+
import { applyHeadSettings } from '../../integration/applyHeadSettings.js';
|
5
5
|
function useConfig() {
|
6
6
|
// Vike hook
|
7
7
|
let pageContext = getPageContext();
|
@@ -3,7 +3,7 @@ export { PageContextProvider };
|
|
3
3
|
import React, { useContext } from 'react';
|
4
4
|
import { getGlobalObject } from '../utils/getGlobalObject.js';
|
5
5
|
const globalObject = getGlobalObject('PageContextProvider.ts', {
|
6
|
-
reactContext: React.createContext(undefined)
|
6
|
+
reactContext: React.createContext(undefined),
|
7
7
|
});
|
8
8
|
function PageContextProvider({ pageContext, children }) {
|
9
9
|
const { reactContext } = globalObject;
|
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';
|
@@ -2,7 +2,7 @@ export { getPageElement };
|
|
2
2
|
import React, { Suspense } from 'react';
|
3
3
|
import { PageContextProvider } from '../hooks/usePageContext.js';
|
4
4
|
function getPageElement(pageContext) {
|
5
|
-
const { Page, config: { Loading } } = pageContext;
|
5
|
+
const { Page, config: { Loading }, } = pageContext;
|
6
6
|
let page = Page ? React.createElement(Page, null) : null;
|
7
7
|
// Wrapping
|
8
8
|
const addSuspense = (el) => {
|
@@ -15,7 +15,7 @@ function getPageElement(pageContext) {
|
|
15
15
|
// Inner wrapping
|
16
16
|
...(pageContext.config.Layout || []),
|
17
17
|
// Outer wrapping
|
18
|
-
...(pageContext.config.Wrapper || [])
|
18
|
+
...(pageContext.config.Wrapper || []),
|
19
19
|
].forEach((Wrap) => {
|
20
20
|
page = React.createElement(Wrap, null, page);
|
21
21
|
page = addSuspense(page);
|
@@ -25,7 +25,7 @@ const onRenderClient = async (pageContext) => {
|
|
25
25
|
// First render while using SSR, i.e. [hydration](https://vike.dev/hydration)
|
26
26
|
root = ReactDOM.hydrateRoot(container, page, {
|
27
27
|
// @ts-expect-error
|
28
|
-
onUncaughtError
|
28
|
+
onUncaughtError,
|
29
29
|
});
|
30
30
|
}
|
31
31
|
else {
|
@@ -33,7 +33,7 @@ const onRenderClient = async (pageContext) => {
|
|
33
33
|
// First render without SSR
|
34
34
|
root = ReactDOM.createRoot(container, {
|
35
35
|
// @ts-expect-error
|
36
|
-
onUncaughtError
|
36
|
+
onUncaughtError,
|
37
37
|
});
|
38
38
|
}
|
39
39
|
root.render(page);
|
@@ -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,10 +9,12 @@ 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);
|
15
16
|
const headHtml = getHeadHtml(pageContext);
|
17
|
+
const { bodyHtmlBegin, bodyHtmlEnd } = await getBodyHtmlBoundary(pageContext);
|
16
18
|
const { htmlAttributesString, bodyAttributesString } = getTagAttributes(pageContext);
|
17
19
|
// Not needed on the client-side, thus we remove it to save KBs sent to the client
|
18
20
|
delete pageContext._configFromHook;
|
@@ -23,7 +25,9 @@ const onRenderHtml = async (pageContext) => {
|
|
23
25
|
${headHtml}
|
24
26
|
</head>
|
25
27
|
<body${dangerouslySkipEscape(bodyAttributesString)}>
|
28
|
+
${bodyHtmlBegin}
|
26
29
|
<div id="root">${pageHtml}</div>
|
30
|
+
${bodyHtmlEnd}
|
27
31
|
</body>
|
28
32
|
</html>`;
|
29
33
|
};
|
@@ -36,20 +40,26 @@ async function getPageHtml(pageContext) {
|
|
36
40
|
const page = getPageElement(pageContext);
|
37
41
|
const { stream, streamIsRequired } = pageContext.config;
|
38
42
|
if (!stream && !streamIsRequired) {
|
39
|
-
|
43
|
+
const pageHtmlString = renderToString(page);
|
44
|
+
pageContext.pageHtmlString = pageHtmlString;
|
45
|
+
pageHtml = dangerouslySkipEscape(pageHtmlString);
|
40
46
|
}
|
41
47
|
else {
|
42
48
|
const disable = stream === false ? true : undefined;
|
43
|
-
|
49
|
+
const pageHtmlStream = await renderToStream(page, {
|
44
50
|
webStream: typeof stream === 'string' ? stream === 'web' : undefined,
|
45
51
|
userAgent: pageContext.headers?.['user-agent'] ||
|
46
52
|
// TODO/eventually: remove old way of acccessing the User Agent header.
|
47
53
|
// @ts-ignore
|
48
54
|
pageContext.userAgent,
|
49
|
-
disable
|
55
|
+
disable,
|
50
56
|
});
|
57
|
+
pageContext.pageHtmlStream = pageHtmlStream;
|
58
|
+
pageHtml = pageHtmlStream;
|
51
59
|
}
|
52
60
|
}
|
61
|
+
// https://github.com/vikejs/vike/discussions/1804#discussioncomment-10394481
|
62
|
+
await callCumulativeHooks(pageContext.config.onAfterRenderHtml, pageContext);
|
53
63
|
return pageHtml;
|
54
64
|
}
|
55
65
|
function getHeadHtml(pageContext) {
|
@@ -71,7 +81,7 @@ function getHeadHtml(pageContext) {
|
|
71
81
|
// Added by +Head
|
72
82
|
...(pageContext.config.Head ?? []),
|
73
83
|
// Added by useConfig()
|
74
|
-
...(pageContext._configFromHook?.Head ?? [])
|
84
|
+
...(pageContext._configFromHook?.Head ?? []),
|
75
85
|
]
|
76
86
|
.filter((Head) => Head !== null && Head !== undefined)
|
77
87
|
.map((Head) => getHeadElementHtml(Head, pageContext))
|
@@ -139,3 +149,8 @@ function addEcosystemStamp() {
|
|
139
149
|
// We use an object so that we can eventually, in the future, add helpful information as needed. (E.g. the vike-react version.)
|
140
150
|
{};
|
141
151
|
}
|
152
|
+
async function getBodyHtmlBoundary(pageContext) {
|
153
|
+
const bodyHtmlBegin = dangerouslySkipEscape((await callCumulativeHooks(pageContext.config.bodyHtmlBegin, pageContext)).join(''));
|
154
|
+
const bodyHtmlEnd = dangerouslySkipEscape((await callCumulativeHooks(pageContext.config.bodyHtmlEnd, pageContext)).join(''));
|
155
|
+
return { bodyHtmlBegin, bodyHtmlEnd };
|
156
|
+
}
|
@@ -8,7 +8,7 @@ function ssrEffect({ configDefinedAt, configValue }) {
|
|
8
8
|
// When the SSR flag is false, we want to render the page only on the client-side.
|
9
9
|
// We achieve this by loading `Page` only on the client-side: when onRenderHtml()
|
10
10
|
// gets a `Page` value that is undefined it skip server-side rendering.
|
11
|
-
server: configValue !== false
|
11
|
+
server: configValue !== false,
|
12
12
|
};
|
13
13
|
return {
|
14
14
|
meta: {
|
@@ -16,7 +16,7 @@ function ssrEffect({ configDefinedAt, configValue }) {
|
|
16
16
|
/* We don't do this to enable wraping <Head> with <Wrapper>
|
17
17
|
Wrapper: { env }, */
|
18
18
|
Layout: { env },
|
19
|
-
Loading: { env }
|
20
|
-
}
|
19
|
+
Loading: { env },
|
20
|
+
},
|
21
21
|
};
|
22
22
|
}
|
package/dist/types/Config.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { ImportString,
|
1
|
+
import type { ImportString, PageContextServer, PageContext, PageContextClient } from 'vike/types';
|
2
2
|
import type { TagAttributes } from '../utils/getTagAttributesString.js';
|
3
|
-
import type { Viewport } from '../
|
3
|
+
import type { Viewport } from '../integration/onRenderHtml.js';
|
4
4
|
import type { ConfigsCumulative } from '../hooks/useConfig/configsCumulative.js';
|
5
5
|
declare global {
|
6
6
|
namespace Vike {
|
@@ -102,6 +102,18 @@ declare global {
|
|
102
102
|
* https://vike.dev/lang
|
103
103
|
*/
|
104
104
|
lang?: string | null | ((pageContext: PageContext_) => string | null | undefined);
|
105
|
+
/**
|
106
|
+
* Raw HTML injected at the start of `<body>`.
|
107
|
+
*
|
108
|
+
* https://vike.dev/bodyHtmlBegin
|
109
|
+
*/
|
110
|
+
bodyHtmlBegin?: BodyHtmlBoundary;
|
111
|
+
/**
|
112
|
+
* Raw HTML injected at the end of `<body>`.
|
113
|
+
*
|
114
|
+
* https://vike.dev/bodyHtmlEnd
|
115
|
+
*/
|
116
|
+
bodyHtmlEnd?: BodyHtmlBoundary;
|
105
117
|
/**
|
106
118
|
* Add tag attributes such as `<html class="dark">`.
|
107
119
|
*
|
@@ -152,6 +164,12 @@ declare global {
|
|
152
164
|
* https://vike.dev/reactStrictMode
|
153
165
|
*/
|
154
166
|
reactStrictMode?: boolean;
|
167
|
+
/**
|
168
|
+
* Server-side hook called right after rendering the page's root React component to HTML.
|
169
|
+
*
|
170
|
+
* https://vike.dev/onAfterRenderHtml
|
171
|
+
*/
|
172
|
+
onAfterRenderHtml?: (pageContext: PageContextServer) => void;
|
155
173
|
/**
|
156
174
|
* Client-side hook called before the page is rendered.
|
157
175
|
*
|
@@ -175,13 +193,18 @@ declare global {
|
|
175
193
|
Wrapper?: Wrapper[];
|
176
194
|
Layout?: Layout[];
|
177
195
|
Head?: Head[];
|
196
|
+
bodyHtmlBegin?: BodyHtmlBoundary[];
|
197
|
+
bodyHtmlEnd?: BodyHtmlBoundary[];
|
178
198
|
bodyAttributes?: TagAttributes[];
|
179
199
|
htmlAttributes?: TagAttributes[];
|
200
|
+
onAfterRenderHtml?: Function[];
|
180
201
|
onBeforeRenderClient?: Function[];
|
181
202
|
onAfterRenderClient?: Function[];
|
182
203
|
}
|
183
204
|
}
|
184
205
|
}
|
206
|
+
type PageContext_ = PageContext;
|
207
|
+
type BodyHtmlBoundary = string | ((pageContext: PageContext) => string);
|
185
208
|
export type Head = React.ReactNode | (() => React.ReactNode);
|
186
209
|
type Wrapper = (props: {
|
187
210
|
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 '../integration/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.5",
|
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,27 +18,30 @@
|
|
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
|
-
"./
|
27
|
-
"./
|
28
|
-
"./components/Loading": "./dist/components/Loading.js"
|
25
|
+
"./__internal/integration/onRenderHtml": "./dist/integration/onRenderHtml.js",
|
26
|
+
"./__internal/integration/onRenderClient": "./dist/integration/onRenderClient.js",
|
27
|
+
"./__internal/components/Loading": "./dist/components/Loading.js"
|
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"
|
29
36
|
},
|
30
37
|
"scripts": {
|
31
38
|
"dev": "tsc --watch",
|
32
39
|
"build": "rimraf dist/ && tsc && pnpm run build:css",
|
33
|
-
"build:css": "cp src/
|
40
|
+
"build:css": "cp src/integration/styles.css dist/integration/styles.css",
|
34
41
|
"release": "release-me patch",
|
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": [
|
@@ -86,17 +85,21 @@
|
|
86
85
|
"config": [
|
87
86
|
"./dist/+config.d.ts"
|
88
87
|
],
|
89
|
-
"
|
90
|
-
"./dist/
|
88
|
+
"__/internal/integration/onRenderHtml": [
|
89
|
+
"./dist/integration/onRenderHtml.d.ts"
|
91
90
|
],
|
92
|
-
"
|
93
|
-
"./dist/
|
91
|
+
"__/internal/integration/onRenderClient": [
|
92
|
+
"./dist/integration/onRenderClient.d.ts"
|
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
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|