vike-solid 0.2.8 → 0.2.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/dist/+config.js +3 -2
- package/dist/+onRenderClient.js +42 -5
- package/dist/+onRenderHtml.js +41 -6
- package/dist/ClientOnly.js +1 -1
- package/dist/renderer/+config.d.ts +2 -0
- package/package.json +7 -7
package/dist/+config.js
CHANGED
|
@@ -36,7 +36,7 @@ var _config = {
|
|
|
36
36
|
// be used by the renderers.
|
|
37
37
|
// It is a cumulative config option, so a web app using vike-solid can extend
|
|
38
38
|
// this list.
|
|
39
|
-
passToClient: ["pageProps", "title"],
|
|
39
|
+
passToClient: ["pageProps", "title", "lang"],
|
|
40
40
|
clientRouting: true,
|
|
41
41
|
hydrationCanBeAborted: true,
|
|
42
42
|
meta: {
|
|
@@ -69,7 +69,8 @@ var _config = {
|
|
|
69
69
|
},
|
|
70
70
|
lang: {
|
|
71
71
|
env: {
|
|
72
|
-
server: true
|
|
72
|
+
server: true,
|
|
73
|
+
client: true
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
ssr: {
|
package/dist/+onRenderClient.js
CHANGED
|
@@ -3,6 +3,10 @@ import { P as PageContextProvider, u as usePageContext } from './PageContextProv
|
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
import 'solid-js';
|
|
5
5
|
|
|
6
|
+
function isCallable(thing) {
|
|
7
|
+
return thing instanceof Function || typeof thing === 'function';
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Get the page's title if defined, either from the additional data fetched by
|
|
8
12
|
* the page's data() and onBeforeRender() hook or from the config.
|
|
@@ -32,14 +36,12 @@ function getTitle(pageContext) {
|
|
|
32
36
|
const {
|
|
33
37
|
configDefinedAt
|
|
34
38
|
} = titleConfig;
|
|
35
|
-
if (
|
|
39
|
+
if (isCallable(title)) {
|
|
36
40
|
const val = title(pageContext);
|
|
37
|
-
if (typeof val
|
|
38
|
-
return val;
|
|
39
|
-
}
|
|
40
|
-
if (val) {
|
|
41
|
+
if (typeof val !== "string") {
|
|
41
42
|
throw new Error(configDefinedAt + " should return a string");
|
|
42
43
|
}
|
|
44
|
+
return val;
|
|
43
45
|
}
|
|
44
46
|
throw new Error(configDefinedAt + " should be a string or a function returning a string");
|
|
45
47
|
}
|
|
@@ -81,6 +83,39 @@ function Passthrough(props) {
|
|
|
81
83
|
return memo(() => props.children);
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Get the page's lang if defined, either from the config, the additional data fetched by
|
|
88
|
+
* the page's data() and onBeforeRender() hooks or from other hooks.
|
|
89
|
+
*/
|
|
90
|
+
function getLang(pageContext) {
|
|
91
|
+
// from onBeforeRoute() hook & other hooks, e.g. onPrerenderStart() hook
|
|
92
|
+
if (pageContext.lang !== undefined) {
|
|
93
|
+
return pageContext.lang;
|
|
94
|
+
}
|
|
95
|
+
const langConfig = pageContext.configEntries.lang?.[0];
|
|
96
|
+
if (!langConfig) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const lang = langConfig.configValue;
|
|
100
|
+
if (typeof lang === 'string') {
|
|
101
|
+
return lang;
|
|
102
|
+
}
|
|
103
|
+
if (!lang) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const {
|
|
107
|
+
configDefinedAt
|
|
108
|
+
} = langConfig;
|
|
109
|
+
if (isCallable(lang)) {
|
|
110
|
+
const val = lang(pageContext);
|
|
111
|
+
if (typeof val !== 'string') {
|
|
112
|
+
throw new Error(configDefinedAt + ' should return a string');
|
|
113
|
+
}
|
|
114
|
+
return val;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(configDefinedAt + ' should be a string or a function returning a string');
|
|
117
|
+
}
|
|
118
|
+
|
|
84
119
|
// https://vike.dev/onRenderClient
|
|
85
120
|
const [pageContextStore, setPageContext] = createStore({});
|
|
86
121
|
let dispose;
|
|
@@ -109,7 +144,9 @@ const onRenderClient = async pageContext => {
|
|
|
109
144
|
// previous page. It can even be null, in which case we should unset the
|
|
110
145
|
// document title.
|
|
111
146
|
const title = getTitle(pageContext);
|
|
147
|
+
const lang = getLang(pageContext) || 'en';
|
|
112
148
|
document.title = title || "";
|
|
149
|
+
document.documentElement.lang = lang;
|
|
113
150
|
}
|
|
114
151
|
};
|
|
115
152
|
|
package/dist/+onRenderHtml.js
CHANGED
|
@@ -3,6 +3,10 @@ import { version, escapeInject, dangerouslySkipEscape, stampPipe } from 'vike/se
|
|
|
3
3
|
import { P as PageContextProvider, u as usePageContext } from './PageContextProvider-OTjP33FZ.js';
|
|
4
4
|
import 'solid-js';
|
|
5
5
|
|
|
6
|
+
function isCallable(thing) {
|
|
7
|
+
return thing instanceof Function || typeof thing === 'function';
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Get the page's title if defined, either from the additional data fetched by
|
|
8
12
|
* the page's data() and onBeforeRender() hook or from the config.
|
|
@@ -32,14 +36,12 @@ function getTitle(pageContext) {
|
|
|
32
36
|
const {
|
|
33
37
|
configDefinedAt
|
|
34
38
|
} = titleConfig;
|
|
35
|
-
if (
|
|
39
|
+
if (isCallable(title)) {
|
|
36
40
|
const val = title(pageContext);
|
|
37
|
-
if (typeof val
|
|
38
|
-
return val;
|
|
39
|
-
}
|
|
40
|
-
if (val) {
|
|
41
|
+
if (typeof val !== "string") {
|
|
41
42
|
throw new Error(configDefinedAt + " should return a string");
|
|
42
43
|
}
|
|
44
|
+
return val;
|
|
43
45
|
}
|
|
44
46
|
throw new Error(configDefinedAt + " should be a string or a function returning a string");
|
|
45
47
|
}
|
|
@@ -81,6 +83,39 @@ function Passthrough(props) {
|
|
|
81
83
|
return props.children;
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Get the page's lang if defined, either from the config, the additional data fetched by
|
|
88
|
+
* the page's data() and onBeforeRender() hooks or from other hooks.
|
|
89
|
+
*/
|
|
90
|
+
function getLang(pageContext) {
|
|
91
|
+
// from onBeforeRoute() hook & other hooks, e.g. onPrerenderStart() hook
|
|
92
|
+
if (pageContext.lang !== undefined) {
|
|
93
|
+
return pageContext.lang;
|
|
94
|
+
}
|
|
95
|
+
const langConfig = pageContext.configEntries.lang?.[0];
|
|
96
|
+
if (!langConfig) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const lang = langConfig.configValue;
|
|
100
|
+
if (typeof lang === 'string') {
|
|
101
|
+
return lang;
|
|
102
|
+
}
|
|
103
|
+
if (!lang) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const {
|
|
107
|
+
configDefinedAt
|
|
108
|
+
} = langConfig;
|
|
109
|
+
if (isCallable(lang)) {
|
|
110
|
+
const val = lang(pageContext);
|
|
111
|
+
if (typeof val !== 'string') {
|
|
112
|
+
throw new Error(configDefinedAt + ' should return a string');
|
|
113
|
+
}
|
|
114
|
+
return val;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(configDefinedAt + ' should be a string or a function returning a string');
|
|
117
|
+
}
|
|
118
|
+
|
|
84
119
|
checkVikeVersion();
|
|
85
120
|
const onRenderHtml = async pageContext => {
|
|
86
121
|
const {
|
|
@@ -108,7 +143,7 @@ const onRenderHtml = async pageContext => {
|
|
|
108
143
|
stampPipe(pageView, "node-stream");
|
|
109
144
|
}
|
|
110
145
|
}
|
|
111
|
-
const lang = pageContext
|
|
146
|
+
const lang = getLang(pageContext) || "en";
|
|
112
147
|
const documentHtml = escapeInject`<!DOCTYPE html>
|
|
113
148
|
<html lang='${lang}'>
|
|
114
149
|
<head>
|
package/dist/ClientOnly.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createComponent, Dynamic, ssr, ssrHydrationKey } from 'solid-js/web';
|
|
2
2
|
import { createSignal, createEffect, Suspense, lazy } from 'solid-js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var _tmpl$ = ["<p", ">Error loading component.</p>"];
|
|
5
5
|
function ClientOnlyError() {
|
|
6
6
|
return ssr(_tmpl$, ssrHydrationKey());
|
|
7
7
|
}
|
|
@@ -11,6 +11,7 @@ declare global {
|
|
|
11
11
|
pageProps?: Record<string, unknown>;
|
|
12
12
|
/** <title>${title}</title> - set by onBeforeRender() hook, has precedence over the config */
|
|
13
13
|
title?: string;
|
|
14
|
+
lang?: string;
|
|
14
15
|
data?: {
|
|
15
16
|
/** <title>${title}</title> - set by data() hook, has precedence over the onBeforeRender() hook */
|
|
16
17
|
title?: string;
|
|
@@ -56,6 +57,7 @@ declare const _default: {
|
|
|
56
57
|
lang: {
|
|
57
58
|
env: {
|
|
58
59
|
server: true;
|
|
60
|
+
client: true;
|
|
59
61
|
};
|
|
60
62
|
};
|
|
61
63
|
ssr: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-solid",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"vite-plugin-solid": "^2.8.0"
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@babel/core": "^7.23.7",
|
|
15
|
-
"@babel/preset-env": "^7.23.
|
|
15
|
+
"@babel/preset-env": "^7.23.8",
|
|
16
16
|
"@babel/preset-typescript": "^7.23.3",
|
|
17
17
|
"@rollup/plugin-babel": "^6.0.4",
|
|
18
18
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
19
19
|
"@types/node": "^18.17.4",
|
|
20
|
-
"babel-preset-solid": "^1.8.
|
|
20
|
+
"babel-preset-solid": "^1.8.9",
|
|
21
21
|
"bumpp": "^9.2.1",
|
|
22
|
-
"rollup": "^4.9.
|
|
22
|
+
"rollup": "^4.9.5",
|
|
23
23
|
"rollup-plugin-dts": "^6.1.0",
|
|
24
|
-
"solid-js": "^1.8.
|
|
24
|
+
"solid-js": "^1.8.11",
|
|
25
25
|
"tslib": "^2.6.2",
|
|
26
26
|
"typescript": "^5.3.3",
|
|
27
|
-
"vite": "^5.0.
|
|
28
|
-
"vike": "^0.4.
|
|
27
|
+
"vite": "^5.0.11",
|
|
28
|
+
"vike": "^0.4.156"
|
|
29
29
|
},
|
|
30
30
|
"exports": {
|
|
31
31
|
".": "./dist/+config.js",
|