vike-react 0.5.4 → 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 +18 -4
- package/dist/+config.js +37 -27
- 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/{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.js +10 -2
- package/dist/{renderer → integration}/ssrEffect.js +3 -3
- package/dist/types/Config.d.ts +16 -1
- package/dist/types/PageContext.d.ts +1 -1
- package/package.json +9 -9
- /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}/onRenderHtml.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
1
|
export { config };
|
2
|
-
import { ssrEffect } from './
|
2
|
+
import { ssrEffect } from './integration/ssrEffect.js';
|
3
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 config: {
|
|
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;
|
package/dist/+config.js
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
export { config };
|
2
|
-
import { ssrEffect } from './
|
2
|
+
import { ssrEffect } from './integration/ssrEffect.js';
|
3
3
|
import { isNotFalse } from './utils/isNotFalse.js';
|
4
4
|
const config = {
|
5
5
|
name: 'vike-react',
|
6
6
|
require: {
|
7
|
-
vike: '>=0.4.182'
|
7
|
+
vike: '>=0.4.182',
|
8
8
|
},
|
9
|
-
Loading: 'import:vike-react/components/Loading:default',
|
9
|
+
Loading: 'import:vike-react/__internal/components/Loading:default',
|
10
10
|
// https://vike.dev/onRenderHtml
|
11
|
-
onRenderHtml: 'import:vike-react/
|
11
|
+
onRenderHtml: 'import:vike-react/__internal/integration/onRenderHtml:onRenderHtml',
|
12
12
|
// https://vike.dev/onRenderClient
|
13
|
-
onRenderClient: 'import:vike-react/
|
13
|
+
onRenderClient: 'import:vike-react/__internal/integration/onRenderClient:onRenderClient',
|
14
14
|
passToClient: [
|
15
15
|
'_configFromHook',
|
16
16
|
// https://github.com/vikejs/vike-react/issues/25
|
17
|
-
process.env.NODE_ENV !== 'production' && '$$typeof'
|
17
|
+
process.env.NODE_ENV !== 'production' && '$$typeof',
|
18
18
|
].filter(isNotFalse),
|
19
19
|
// https://vike.dev/clientRouting
|
20
20
|
clientRouting: true,
|
@@ -23,74 +23,84 @@ const config = {
|
|
23
23
|
meta: {
|
24
24
|
Head: {
|
25
25
|
env: { server: true },
|
26
|
-
cumulative: true
|
26
|
+
cumulative: true,
|
27
27
|
},
|
28
28
|
Layout: {
|
29
29
|
env: { server: true, client: true },
|
30
|
-
cumulative: true
|
30
|
+
cumulative: true,
|
31
31
|
},
|
32
32
|
title: {
|
33
|
-
env: { server: true, client: true }
|
33
|
+
env: { server: true, client: true },
|
34
34
|
},
|
35
35
|
description: {
|
36
|
-
env: { server: true }
|
36
|
+
env: { server: true },
|
37
37
|
},
|
38
38
|
image: {
|
39
|
-
env: { server: true }
|
39
|
+
env: { server: true },
|
40
40
|
},
|
41
41
|
viewport: {
|
42
|
-
env: { server: true }
|
42
|
+
env: { server: true },
|
43
43
|
},
|
44
44
|
favicon: {
|
45
45
|
env: { server: true },
|
46
|
-
global: true
|
46
|
+
global: true,
|
47
47
|
},
|
48
48
|
lang: {
|
49
|
-
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,
|
50
60
|
},
|
51
61
|
htmlAttributes: {
|
52
62
|
env: { server: true },
|
53
63
|
global: true,
|
54
|
-
cumulative: true // for Vike extensions
|
64
|
+
cumulative: true, // for Vike extensions
|
55
65
|
},
|
56
66
|
bodyAttributes: {
|
57
67
|
env: { server: true },
|
58
68
|
global: true,
|
59
|
-
cumulative: true // for Vike extensions
|
69
|
+
cumulative: true, // for Vike extensions
|
60
70
|
},
|
61
71
|
ssr: {
|
62
72
|
env: { config: true },
|
63
|
-
effect: ssrEffect
|
73
|
+
effect: ssrEffect,
|
64
74
|
},
|
65
75
|
stream: {
|
66
|
-
env: { server: true }
|
76
|
+
env: { server: true },
|
67
77
|
},
|
68
78
|
streamIsRequired: {
|
69
|
-
env: { server: true }
|
79
|
+
env: { server: true },
|
70
80
|
},
|
71
81
|
onAfterRenderHtml: {
|
72
82
|
env: { server: true },
|
73
|
-
cumulative: true
|
83
|
+
cumulative: true,
|
74
84
|
},
|
75
85
|
onBeforeRenderClient: {
|
76
86
|
env: { client: true },
|
77
|
-
cumulative: true
|
87
|
+
cumulative: true,
|
78
88
|
},
|
79
89
|
onAfterRenderClient: {
|
80
90
|
env: { client: true },
|
81
|
-
cumulative: true
|
91
|
+
cumulative: true,
|
82
92
|
},
|
83
93
|
Wrapper: {
|
84
94
|
cumulative: true,
|
85
|
-
env: { client: true, server: true }
|
95
|
+
env: { client: true, server: true },
|
86
96
|
},
|
87
97
|
reactStrictMode: {
|
88
|
-
env: { client: true, server: true }
|
98
|
+
env: { client: true, server: true },
|
89
99
|
},
|
90
100
|
Loading: {
|
91
|
-
env: { server: true, client: true }
|
92
|
-
}
|
93
|
-
}
|
101
|
+
env: { server: true, client: true },
|
102
|
+
},
|
103
|
+
},
|
94
104
|
};
|
95
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'`
|
96
106
|
import './types/Config.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;
|
@@ -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);
|
@@ -14,6 +14,7 @@ addEcosystemStamp();
|
|
14
14
|
const onRenderHtml = async (pageContext) => {
|
15
15
|
const pageHtml = await getPageHtml(pageContext);
|
16
16
|
const headHtml = getHeadHtml(pageContext);
|
17
|
+
const { bodyHtmlBegin, bodyHtmlEnd } = await getBodyHtmlBoundary(pageContext);
|
17
18
|
const { htmlAttributesString, bodyAttributesString } = getTagAttributes(pageContext);
|
18
19
|
// Not needed on the client-side, thus we remove it to save KBs sent to the client
|
19
20
|
delete pageContext._configFromHook;
|
@@ -24,7 +25,9 @@ const onRenderHtml = async (pageContext) => {
|
|
24
25
|
${headHtml}
|
25
26
|
</head>
|
26
27
|
<body${dangerouslySkipEscape(bodyAttributesString)}>
|
28
|
+
${bodyHtmlBegin}
|
27
29
|
<div id="root">${pageHtml}</div>
|
30
|
+
${bodyHtmlEnd}
|
28
31
|
</body>
|
29
32
|
</html>`;
|
30
33
|
};
|
@@ -49,7 +52,7 @@ async function getPageHtml(pageContext) {
|
|
49
52
|
// TODO/eventually: remove old way of acccessing the User Agent header.
|
50
53
|
// @ts-ignore
|
51
54
|
pageContext.userAgent,
|
52
|
-
disable
|
55
|
+
disable,
|
53
56
|
});
|
54
57
|
pageContext.pageHtmlStream = pageHtmlStream;
|
55
58
|
pageHtml = pageHtmlStream;
|
@@ -78,7 +81,7 @@ function getHeadHtml(pageContext) {
|
|
78
81
|
// Added by +Head
|
79
82
|
...(pageContext.config.Head ?? []),
|
80
83
|
// Added by useConfig()
|
81
|
-
...(pageContext._configFromHook?.Head ?? [])
|
84
|
+
...(pageContext._configFromHook?.Head ?? []),
|
82
85
|
]
|
83
86
|
.filter((Head) => Head !== null && Head !== undefined)
|
84
87
|
.map((Head) => getHeadElementHtml(Head, pageContext))
|
@@ -146,3 +149,8 @@ function addEcosystemStamp() {
|
|
146
149
|
// We use an object so that we can eventually, in the future, add helpful information as needed. (E.g. the vike-react version.)
|
147
150
|
{};
|
148
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
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
|
*
|
@@ -181,6 +193,8 @@ declare global {
|
|
181
193
|
Wrapper?: Wrapper[];
|
182
194
|
Layout?: Layout[];
|
183
195
|
Head?: Head[];
|
196
|
+
bodyHtmlBegin?: BodyHtmlBoundary[];
|
197
|
+
bodyHtmlEnd?: BodyHtmlBoundary[];
|
184
198
|
bodyAttributes?: TagAttributes[];
|
185
199
|
htmlAttributes?: TagAttributes[];
|
186
200
|
onAfterRenderHtml?: Function[];
|
@@ -190,6 +204,7 @@ declare global {
|
|
190
204
|
}
|
191
205
|
}
|
192
206
|
type PageContext_ = PageContext;
|
207
|
+
type BodyHtmlBoundary = string | ((pageContext: PageContext) => string);
|
193
208
|
export type Head = React.ReactNode | (() => React.ReactNode);
|
194
209
|
type Wrapper = (props: {
|
195
210
|
children: React.ReactNode;
|
@@ -2,7 +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 '../
|
5
|
+
import type { PageHtmlStream } from '../integration/onRenderHtml.js';
|
6
6
|
declare global {
|
7
7
|
namespace Vike {
|
8
8
|
interface PageContext {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "vike-react",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.5",
|
4
4
|
"repository": "https://github.com/vikejs/vike-react",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -22,9 +22,9 @@
|
|
22
22
|
"./ClientOnly": "./dist/components/ClientOnly.js",
|
23
23
|
".": "./dist/index.js",
|
24
24
|
"./config": "./dist/+config.js",
|
25
|
-
"./
|
26
|
-
"./
|
27
|
-
"./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
28
|
},
|
29
29
|
"dependencies": {
|
30
30
|
"react-streaming": "^0.3.42"
|
@@ -37,7 +37,7 @@
|
|
37
37
|
"scripts": {
|
38
38
|
"dev": "tsc --watch",
|
39
39
|
"build": "rimraf dist/ && tsc && pnpm run build:css",
|
40
|
-
"build:css": "cp src/
|
40
|
+
"build:css": "cp src/integration/styles.css dist/integration/styles.css",
|
41
41
|
"release": "release-me patch",
|
42
42
|
"release:minor": "release-me minor",
|
43
43
|
"release:commit": "release-me commit"
|
@@ -85,11 +85,11 @@
|
|
85
85
|
"config": [
|
86
86
|
"./dist/+config.d.ts"
|
87
87
|
],
|
88
|
-
"
|
89
|
-
"./dist/
|
88
|
+
"__/internal/integration/onRenderHtml": [
|
89
|
+
"./dist/integration/onRenderHtml.d.ts"
|
90
90
|
],
|
91
|
-
"
|
92
|
-
"./dist/
|
91
|
+
"__/internal/integration/onRenderClient": [
|
92
|
+
"./dist/integration/onRenderClient.d.ts"
|
93
93
|
]
|
94
94
|
}
|
95
95
|
},
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|