vike-react 0.4.2 → 0.4.3
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 +64 -0
- package/dist/{renderer/+config.js → +config.js} +7 -25
- package/dist/hooks/useData.d.ts +2 -0
- package/dist/hooks/useData.js +6 -0
- package/dist/{renderer/PageContextProvider.d.ts → hooks/usePageContext.d.ts} +1 -3
- package/dist/{renderer/PageContextProvider.js → hooks/usePageContext.js} +3 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/renderer/getHeadSetting.js +1 -1
- package/dist/renderer/getPageElement.js +1 -1
- package/dist/renderer/onRenderHtml.js +1 -2
- package/dist/renderer/ssrEffect.d.ts +3 -0
- package/dist/renderer/ssrEffect.js +19 -0
- package/dist/types/Config.d.ts +46 -0
- package/dist/types/Config.js +1 -0
- package/dist/types/PageContext.d.ts +9 -0
- package/dist/types/PageContext.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/{renderer/utils → utils}/getGlobalObject.d.ts +0 -3
- package/dist/utils/getGlobalObject.js +9 -0
- package/dist/utils/isNotFalse.d.ts +1 -0
- package/dist/utils/isNotFalse.js +3 -0
- package/package.json +23 -17
- package/dist/components/useData.d.ts +0 -1
- package/dist/components/useData.js +0 -1
- package/dist/components/usePageContext.d.ts +0 -1
- package/dist/components/usePageContext.js +0 -1
- package/dist/renderer/+config.d.ts +0 -107
- package/dist/renderer/utils/getGlobalObject.js +0 -7
- /package/dist/{renderer/utils → utils}/assert.d.ts +0 -0
- /package/dist/{renderer/utils → utils}/assert.js +0 -0
- /package/dist/{renderer/utils → utils}/isCallable.d.ts +0 -0
- /package/dist/{renderer/utils → utils}/isCallable.js +0 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
export { config };
|
2
|
+
import { ssrEffect } from './renderer/ssrEffect.js';
|
3
|
+
import './types/index.js';
|
4
|
+
declare const config: {
|
5
|
+
onRenderHtml: "import:vike-react/renderer/onRenderHtml:onRenderHtml";
|
6
|
+
onRenderClient: "import:vike-react/renderer/onRenderClient:onRenderClient";
|
7
|
+
passToClient: string[];
|
8
|
+
clientRouting: true;
|
9
|
+
hydrationCanBeAborted: true;
|
10
|
+
meta: {
|
11
|
+
Head: {
|
12
|
+
env: {
|
13
|
+
server: true;
|
14
|
+
};
|
15
|
+
};
|
16
|
+
Layout: {
|
17
|
+
env: {
|
18
|
+
server: true;
|
19
|
+
client: true;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
title: {
|
23
|
+
env: {
|
24
|
+
server: true;
|
25
|
+
client: true;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
favicon: {
|
29
|
+
env: {
|
30
|
+
server: true;
|
31
|
+
client: true;
|
32
|
+
};
|
33
|
+
};
|
34
|
+
lang: {
|
35
|
+
env: {
|
36
|
+
server: true;
|
37
|
+
client: true;
|
38
|
+
};
|
39
|
+
};
|
40
|
+
ssr: {
|
41
|
+
env: {
|
42
|
+
config: true;
|
43
|
+
};
|
44
|
+
effect: typeof ssrEffect;
|
45
|
+
};
|
46
|
+
stream: {
|
47
|
+
env: {
|
48
|
+
server: true;
|
49
|
+
};
|
50
|
+
};
|
51
|
+
VikeReactQueryWrapper: {
|
52
|
+
env: {
|
53
|
+
client: true;
|
54
|
+
server: true;
|
55
|
+
};
|
56
|
+
};
|
57
|
+
Wrapper: {
|
58
|
+
env: {
|
59
|
+
client: true;
|
60
|
+
server: true;
|
61
|
+
};
|
62
|
+
};
|
63
|
+
};
|
64
|
+
};
|
@@ -1,24 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
return {
|
9
|
-
meta: {
|
10
|
-
// When the SSR flag is false, we want to render the page only in the
|
11
|
-
// browser. We achieve this by then making the `Page` implementation
|
12
|
-
// accessible only in the client's renderer.
|
13
|
-
Page: {
|
14
|
-
env: configValue
|
15
|
-
? { server: true, client: true } // default
|
16
|
-
: { client: true }
|
17
|
-
}
|
18
|
-
}
|
19
|
-
};
|
20
|
-
};
|
21
|
-
export default {
|
1
|
+
export { config };
|
2
|
+
import { isNotFalse } from './utils/isNotFalse.js';
|
3
|
+
import { ssrEffect } from './renderer/ssrEffect.js';
|
4
|
+
// 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'`
|
5
|
+
import './types/index.js';
|
6
|
+
const config = {
|
22
7
|
// https://vike.dev/onRenderHtml
|
23
8
|
onRenderHtml: 'import:vike-react/renderer/onRenderHtml:onRenderHtml',
|
24
9
|
// https://vike.dev/onRenderClient
|
@@ -49,7 +34,7 @@ export default {
|
|
49
34
|
},
|
50
35
|
ssr: {
|
51
36
|
env: { config: true },
|
52
|
-
effect:
|
37
|
+
effect: ssrEffect
|
53
38
|
},
|
54
39
|
stream: {
|
55
40
|
env: { server: true }
|
@@ -62,6 +47,3 @@ export default {
|
|
62
47
|
}
|
63
48
|
}
|
64
49
|
};
|
65
|
-
function isNotFalse(val) {
|
66
|
-
return val !== false;
|
67
|
-
}
|
@@ -1,6 +1,5 @@
|
|
1
|
-
export { PageContextProvider };
|
2
1
|
export { usePageContext };
|
3
|
-
export {
|
2
|
+
export { PageContextProvider };
|
4
3
|
import React from 'react';
|
5
4
|
import type { PageContext } from 'vike/types';
|
6
5
|
declare function PageContextProvider({ pageContext, children }: {
|
@@ -9,4 +8,3 @@ declare function PageContextProvider({ pageContext, children }: {
|
|
9
8
|
}): React.JSX.Element;
|
10
9
|
/** Access the pageContext from any React component */
|
11
10
|
declare function usePageContext(): PageContext;
|
12
|
-
declare function useData<Data>(): Data;
|
@@ -1,9 +1,8 @@
|
|
1
|
-
export { PageContextProvider };
|
2
1
|
export { usePageContext };
|
3
|
-
export {
|
2
|
+
export { PageContextProvider };
|
4
3
|
import React, { useContext } from 'react';
|
5
|
-
import { getGlobalObject } from '
|
6
|
-
import { assert } from '
|
4
|
+
import { getGlobalObject } from '../utils/getGlobalObject.js';
|
5
|
+
import { assert } from '../utils/assert.js';
|
7
6
|
const globalObject = getGlobalObject('PageContextProvider.ts', {
|
8
7
|
reactContext: React.createContext(undefined)
|
9
8
|
});
|
@@ -22,7 +21,3 @@ function usePageContext() {
|
|
22
21
|
assert(pageContext);
|
23
22
|
return pageContext;
|
24
23
|
}
|
25
|
-
function useData() {
|
26
|
-
const { data } = usePageContext();
|
27
|
-
return data;
|
28
|
-
}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { config } from './+config.js';
|
package/dist/index.js
ADDED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { getPageElement };
|
2
2
|
import React from 'react';
|
3
|
-
import { PageContextProvider } from '
|
3
|
+
import { PageContextProvider } from '../hooks/usePageContext.js';
|
4
4
|
function getPageElement(pageContext) {
|
5
5
|
const Layout = pageContext.config.Layout ?? PassThrough;
|
6
6
|
const Wrapper = pageContext.config.Wrapper ?? PassThrough;
|
@@ -5,7 +5,7 @@ import { renderToStream } from 'react-streaming/server';
|
|
5
5
|
import { escapeInject, dangerouslySkipEscape, version } from 'vike/server';
|
6
6
|
import { getHeadSetting } from './getHeadSetting.js';
|
7
7
|
import { getPageElement } from './getPageElement.js';
|
8
|
-
import { PageContextProvider } from '
|
8
|
+
import { PageContextProvider } from '../hooks/usePageContext.js';
|
9
9
|
import React from 'react';
|
10
10
|
checkVikeVersion();
|
11
11
|
const onRenderHtml = async (pageContext) => {
|
@@ -40,7 +40,6 @@ const onRenderHtml = async (pageContext) => {
|
|
40
40
|
<body>
|
41
41
|
<div id="page-view">${pageView}</div>
|
42
42
|
</body>
|
43
|
-
<!-- built with https://github.com/vikejs/vike-react -->
|
44
43
|
</html>`;
|
45
44
|
return documentHtml;
|
46
45
|
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export { ssrEffect };
|
2
|
+
function ssrEffect({ configDefinedAt, configValue }) {
|
3
|
+
if (typeof configValue !== 'boolean')
|
4
|
+
throw new Error(`${configDefinedAt} should be a boolean`);
|
5
|
+
return {
|
6
|
+
meta: {
|
7
|
+
Page: {
|
8
|
+
env: {
|
9
|
+
// Always load `Page` on the client-side.
|
10
|
+
client: true,
|
11
|
+
// When the SSR flag is false, we want to render the page only on the client-side.
|
12
|
+
// We achieve this by loading `Page` only on the client-side: when onRenderHtml()
|
13
|
+
// gets a `Page` value that is undefined it skip server-side rendering.
|
14
|
+
server: configValue !== false
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
};
|
19
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
declare global {
|
2
|
+
namespace VikePackages {
|
3
|
+
interface ConfigVikeReact {
|
4
|
+
/** The page's root React component */
|
5
|
+
Page?: () => React.ReactNode;
|
6
|
+
/** React element rendered and appended into <head></head> */
|
7
|
+
Head?: () => React.ReactNode;
|
8
|
+
/** A component, usually common to several pages, that wraps the root component `Page` */
|
9
|
+
Layout?: (props: {
|
10
|
+
children: React.ReactNode;
|
11
|
+
}) => React.ReactNode;
|
12
|
+
/** <title>${title}</title> */
|
13
|
+
title?: string;
|
14
|
+
/** <link rel="icon" href="${favicon}" /> */
|
15
|
+
favicon?: string;
|
16
|
+
/** <html lang="${lang}">
|
17
|
+
*
|
18
|
+
* @default 'en'
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
lang?: string;
|
22
|
+
/**
|
23
|
+
* If true, render mode is SSR or pre-rendering (aka SSG). In other words, the
|
24
|
+
* page's HTML will be rendered at build-time or request-time.
|
25
|
+
* If false, render mode is SPA. In other words, the page will only be
|
26
|
+
* rendered in the browser.
|
27
|
+
*
|
28
|
+
* See https://vike.dev/render-modes
|
29
|
+
*
|
30
|
+
* @default true
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
ssr?: boolean;
|
34
|
+
/**
|
35
|
+
* Whether to stream the page's HTML. Requires Server-Side Rendering (`ssr: true`).
|
36
|
+
*
|
37
|
+
* @default false
|
38
|
+
*
|
39
|
+
*/
|
40
|
+
stream?: boolean;
|
41
|
+
VikeReactQueryWrapper?: React.ReactNode;
|
42
|
+
Wrapper?: () => React.ReactNode;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export function getGlobalObject(
|
2
|
+
// We use the filename as key; each `getGlobalObject()` call should live inside a file with a unique filename.
|
3
|
+
key, defaultValue) {
|
4
|
+
// @ts-ignore
|
5
|
+
const globalObjectsAll = (globalThis[projectKey] = globalThis[projectKey] || {});
|
6
|
+
const globalObject = (globalObjectsAll[key] = globalObjectsAll[key] || defaultValue);
|
7
|
+
return globalObject;
|
8
|
+
}
|
9
|
+
const projectKey = '_vike_react';
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function isNotFalse<T>(val: T | false): val is T;
|
package/package.json
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "vike-react",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.3",
|
4
4
|
"type": "module",
|
5
|
-
"main": "./dist/
|
6
|
-
"types": "./dist/
|
5
|
+
"main": "./dist/index.js",
|
6
|
+
"types": "./dist/index.d.ts",
|
7
7
|
"exports": {
|
8
|
-
"
|
8
|
+
"./useData": "./dist/hooks/useData.js",
|
9
|
+
"./usePageContext": "./dist/hooks/usePageContext.js",
|
10
|
+
"./ClientOnly": "./dist/components/ClientOnly.js",
|
11
|
+
".": "./dist/index.js",
|
12
|
+
"./config": "./dist/+config.js",
|
9
13
|
"./renderer/onRenderHtml": "./dist/renderer/onRenderHtml.js",
|
10
|
-
"./renderer/onRenderClient": "./dist/renderer/onRenderClient.js"
|
11
|
-
"./usePageContext": "./dist/components/usePageContext.js",
|
12
|
-
"./useData": "./dist/components/useData.js",
|
13
|
-
"./ClientOnly": "./dist/components/ClientOnly.js"
|
14
|
+
"./renderer/onRenderClient": "./dist/renderer/onRenderClient.js"
|
14
15
|
},
|
15
16
|
"scripts": {
|
16
17
|
"dev": "tsc --watch",
|
@@ -22,7 +23,7 @@
|
|
22
23
|
"peerDependencies": {
|
23
24
|
"react": "18.x.x",
|
24
25
|
"react-dom": "18.x.x",
|
25
|
-
"vike": "^0.4.
|
26
|
+
"vike": "^0.4.160",
|
26
27
|
"vite": "^4.3.8 || ^5.0.10"
|
27
28
|
},
|
28
29
|
"devDependencies": {
|
@@ -33,21 +34,27 @@
|
|
33
34
|
"react": "^18.2.0",
|
34
35
|
"react-dom": "^18.2.0",
|
35
36
|
"typescript": "^5.3.3",
|
36
|
-
"vike": "^0.4.
|
37
|
+
"vike": "^0.4.160"
|
37
38
|
},
|
38
39
|
"dependencies": {
|
39
40
|
"react-streaming": "^0.3.19"
|
40
41
|
},
|
41
42
|
"typesVersions": {
|
42
43
|
"*": {
|
43
|
-
"
|
44
|
-
"./dist/
|
44
|
+
"useData": [
|
45
|
+
"./dist/hooks/useData.d.ts"
|
45
46
|
],
|
46
47
|
"usePageContext": [
|
47
|
-
"./dist/
|
48
|
+
"./dist/hooks/usePageContext.d.ts"
|
48
49
|
],
|
49
|
-
"
|
50
|
-
"./dist/components/
|
50
|
+
"ClientOnly": [
|
51
|
+
"./dist/components/ClientOnly.d.ts"
|
52
|
+
],
|
53
|
+
".": [
|
54
|
+
"./dist/index.d.ts"
|
55
|
+
],
|
56
|
+
"config": [
|
57
|
+
"./dist/+config.d.ts"
|
51
58
|
],
|
52
59
|
"renderer/onRenderHtml": [
|
53
60
|
"./dist/renderer/onRenderHtml.d.ts"
|
@@ -58,8 +65,7 @@
|
|
58
65
|
}
|
59
66
|
},
|
60
67
|
"files": [
|
61
|
-
"dist/"
|
62
|
-
"types.d.ts"
|
68
|
+
"dist/"
|
63
69
|
],
|
64
70
|
"repository": "github:vikejs/vike-react",
|
65
71
|
"license": "MIT"
|
@@ -1 +0,0 @@
|
|
1
|
-
export { useData } from '../renderer/PageContextProvider.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export { useData } from '../renderer/PageContextProvider.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export { usePageContext } from '../renderer/PageContextProvider.js';
|
@@ -1 +0,0 @@
|
|
1
|
-
export { usePageContext } from '../renderer/PageContextProvider.js';
|
@@ -1,107 +0,0 @@
|
|
1
|
-
import type { ConfigEffect } from 'vike/types';
|
2
|
-
declare const _default: {
|
3
|
-
onRenderHtml: "import:vike-react/renderer/onRenderHtml:onRenderHtml";
|
4
|
-
onRenderClient: "import:vike-react/renderer/onRenderClient:onRenderClient";
|
5
|
-
passToClient: string[];
|
6
|
-
clientRouting: true;
|
7
|
-
hydrationCanBeAborted: true;
|
8
|
-
meta: {
|
9
|
-
Head: {
|
10
|
-
env: {
|
11
|
-
server: true;
|
12
|
-
};
|
13
|
-
};
|
14
|
-
Layout: {
|
15
|
-
env: {
|
16
|
-
server: true;
|
17
|
-
client: true;
|
18
|
-
};
|
19
|
-
};
|
20
|
-
title: {
|
21
|
-
env: {
|
22
|
-
server: true;
|
23
|
-
client: true;
|
24
|
-
};
|
25
|
-
};
|
26
|
-
favicon: {
|
27
|
-
env: {
|
28
|
-
server: true;
|
29
|
-
client: true;
|
30
|
-
};
|
31
|
-
};
|
32
|
-
lang: {
|
33
|
-
env: {
|
34
|
-
server: true;
|
35
|
-
client: true;
|
36
|
-
};
|
37
|
-
};
|
38
|
-
ssr: {
|
39
|
-
env: {
|
40
|
-
config: true;
|
41
|
-
};
|
42
|
-
effect: ConfigEffect;
|
43
|
-
};
|
44
|
-
stream: {
|
45
|
-
env: {
|
46
|
-
server: true;
|
47
|
-
};
|
48
|
-
};
|
49
|
-
VikeReactQueryWrapper: {
|
50
|
-
env: {
|
51
|
-
client: true;
|
52
|
-
server: true;
|
53
|
-
};
|
54
|
-
};
|
55
|
-
Wrapper: {
|
56
|
-
env: {
|
57
|
-
client: true;
|
58
|
-
server: true;
|
59
|
-
};
|
60
|
-
};
|
61
|
-
};
|
62
|
-
};
|
63
|
-
export default _default;
|
64
|
-
import type { Component } from './types.d.ts';
|
65
|
-
declare global {
|
66
|
-
namespace VikePackages {
|
67
|
-
interface ConfigVikeReact {
|
68
|
-
/** The page's root React component */
|
69
|
-
Page?: Component;
|
70
|
-
/** React element rendered and appended into <head></head> */
|
71
|
-
Head?: Component;
|
72
|
-
/** A component, usually common to several pages, that wraps the root component `Page` */
|
73
|
-
Layout?: Component;
|
74
|
-
/** <title>${title}</title> */
|
75
|
-
title?: string;
|
76
|
-
/** <link rel="icon" href="${favicon}" /> */
|
77
|
-
favicon?: string;
|
78
|
-
/** <html lang="${lang}">
|
79
|
-
*
|
80
|
-
* @default 'en'
|
81
|
-
*
|
82
|
-
*/
|
83
|
-
lang?: string;
|
84
|
-
/**
|
85
|
-
* If true, render mode is SSR or pre-rendering (aka SSG). In other words, the
|
86
|
-
* page's HTML will be rendered at build-time or request-time.
|
87
|
-
* If false, render mode is SPA. In other words, the page will only be
|
88
|
-
* rendered in the browser.
|
89
|
-
*
|
90
|
-
* See https://vike.dev/render-modes
|
91
|
-
*
|
92
|
-
* @default true
|
93
|
-
*
|
94
|
-
*/
|
95
|
-
ssr?: boolean;
|
96
|
-
/**
|
97
|
-
* Whether to stream the page's HTML. Requires Server-Side Rendering (`ssr: true`).
|
98
|
-
*
|
99
|
-
* @default false
|
100
|
-
*
|
101
|
-
*/
|
102
|
-
stream?: boolean;
|
103
|
-
VikeReactQueryWrapper?: Component;
|
104
|
-
Wrapper?: Component;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
export function getGlobalObject(
|
2
|
-
// We use the filename as key; each `getGlobalObject()` call should live in a unique filename.
|
3
|
-
key, defaultValue) {
|
4
|
-
const allGlobalObjects = (globalThis.__vite_plugin_ssr = globalThis.__vite_plugin_ssr || {});
|
5
|
-
const globalObject = (allGlobalObjects[key] = allGlobalObjects[key] || defaultValue);
|
6
|
-
return globalObject;
|
7
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|