vike-solid 0.7.0 → 0.7.2
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 +2 -2
- package/dist/+config.js +1 -3
- package/dist/{Config-DEYhmA4K.d.ts → Config-CVJUysUv.d.ts} +9 -9
- package/dist/applyHeadSettings-BwjKVYXB.js +11 -0
- package/dist/components/Config/Config-client.d.ts +7 -0
- package/dist/components/Config/Config-client.js +14 -0
- package/dist/components/Config/Config-server.d.ts +12 -0
- package/dist/components/Config/Config-server.js +19 -0
- package/dist/components/Head/Head-client.d.ts +3 -0
- package/dist/components/Head/Head-client.js +6 -0
- package/dist/components/Head/Head-server.d.ts +14 -0
- package/dist/components/Head/Head-server.js +25 -0
- package/dist/hooks/useConfig/useConfig-client.d.ts +1 -6
- package/dist/hooks/useConfig/useConfig-client.js +11 -23
- package/dist/hooks/useConfig/useConfig-server.d.ts +2 -2
- package/dist/hooks/useConfig/useConfig-server.js +29 -28
- package/dist/includes-B0OUVLz0.js +14 -0
- package/dist/renderer/onRenderClient.js +21 -28
- package/dist/renderer/onRenderHtml.js +21 -20
- package/package.json +28 -15
package/dist/+config.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ConfigEffect } from 'vike/types';
|
|
2
2
|
import { JSX } from 'solid-js';
|
|
3
|
-
import './Config-
|
|
3
|
+
import './Config-CVJUysUv.js';
|
|
4
4
|
|
|
5
5
|
declare function ssrEffect({ configDefinedAt, configValue }: Parameters<ConfigEffect>[0]): ReturnType<ConfigEffect>;
|
|
6
6
|
|
|
7
7
|
declare global {
|
|
8
8
|
namespace Vike {
|
|
9
9
|
interface PageContext {
|
|
10
|
-
/** The root
|
|
10
|
+
/** The root Solid component of the page */
|
|
11
11
|
Page?: () => JSX.Element;
|
|
12
12
|
}
|
|
13
13
|
}
|
package/dist/+config.js
CHANGED
|
@@ -22,14 +22,12 @@ function ssrEffect({
|
|
|
22
22
|
var _config = {
|
|
23
23
|
name: "vike-solid",
|
|
24
24
|
require: {
|
|
25
|
-
vike: ">=0.4.
|
|
25
|
+
vike: ">=0.4.182"
|
|
26
26
|
},
|
|
27
27
|
// https://vike.dev/onRenderHtml
|
|
28
28
|
onRenderHtml: "import:vike-solid/renderer/onRenderHtml:onRenderHtml",
|
|
29
29
|
// https://vike.dev/onRenderClient
|
|
30
30
|
onRenderClient: "import:vike-solid/renderer/onRenderClient:onRenderClient",
|
|
31
|
-
// https://vike.dev/clientRouting
|
|
32
|
-
|
|
33
31
|
// https://vike.dev/clientRouting
|
|
34
32
|
clientRouting: true,
|
|
35
33
|
hydrationCanBeAborted: true,
|
|
@@ -41,7 +41,7 @@ declare global {
|
|
|
41
41
|
*
|
|
42
42
|
* https://vike.dev/title
|
|
43
43
|
*/
|
|
44
|
-
title?: string | ((pageContext: PageContext) => string);
|
|
44
|
+
title?: string | null | ((pageContext: PageContext) => string | null | undefined);
|
|
45
45
|
/**
|
|
46
46
|
* Set the page's description.
|
|
47
47
|
*
|
|
@@ -55,7 +55,7 @@ declare global {
|
|
|
55
55
|
*
|
|
56
56
|
* https://vike.dev/description
|
|
57
57
|
*/
|
|
58
|
-
description?: string | ((pageContext: PageContextServer) => string);
|
|
58
|
+
description?: string | null | ((pageContext: PageContextServer) => string | null | undefined);
|
|
59
59
|
/**
|
|
60
60
|
* Set the page's preview image upon URL sharing.
|
|
61
61
|
*
|
|
@@ -69,7 +69,7 @@ declare global {
|
|
|
69
69
|
*
|
|
70
70
|
* https://vike.dev/image
|
|
71
71
|
*/
|
|
72
|
-
image?: string | ((pageContext: PageContextServer) => string);
|
|
72
|
+
image?: string | null | ((pageContext: PageContextServer) => string | null | undefined);
|
|
73
73
|
/**
|
|
74
74
|
* Set the page's width shown to the user on mobile/tablet devices.
|
|
75
75
|
*
|
|
@@ -77,7 +77,7 @@ declare global {
|
|
|
77
77
|
*
|
|
78
78
|
* https://vike.dev/viewport
|
|
79
79
|
*/
|
|
80
|
-
viewport?: Viewport;
|
|
80
|
+
viewport?: Viewport | ((pageContext: PageContextServer) => Viewport | undefined);
|
|
81
81
|
/**
|
|
82
82
|
* Set the page's favicon.
|
|
83
83
|
*
|
|
@@ -90,7 +90,7 @@ declare global {
|
|
|
90
90
|
*
|
|
91
91
|
* https://vike.dev/favicon
|
|
92
92
|
*/
|
|
93
|
-
favicon?: string;
|
|
93
|
+
favicon?: string | null | ((pageContext: PageContextServer) => string | null | undefined);
|
|
94
94
|
/**
|
|
95
95
|
* Set the page's language (`<html lang>`).
|
|
96
96
|
*
|
|
@@ -98,19 +98,19 @@ declare global {
|
|
|
98
98
|
*
|
|
99
99
|
* https://vike.dev/lang
|
|
100
100
|
*/
|
|
101
|
-
lang?: string | ((pageContext: PageContext) => string
|
|
101
|
+
lang?: string | null | ((pageContext: PageContext) => string | null | undefined);
|
|
102
102
|
/**
|
|
103
103
|
* Add tag attributes such as `<html class="dark">`.
|
|
104
104
|
*
|
|
105
105
|
* https://vike.dev/htmlAttributes
|
|
106
106
|
*/
|
|
107
|
-
htmlAttributes?: TagAttributes;
|
|
107
|
+
htmlAttributes?: TagAttributes | ((pageContext: PageContextServer) => TagAttributes | undefined);
|
|
108
108
|
/**
|
|
109
109
|
* Add tag attributes such as `<body class="dark">`.
|
|
110
110
|
*
|
|
111
111
|
* https://vike.dev/bodyAttributes
|
|
112
112
|
*/
|
|
113
|
-
bodyAttributes?: TagAttributes;
|
|
113
|
+
bodyAttributes?: TagAttributes | ((pageContext: PageContextServer) => TagAttributes | undefined);
|
|
114
114
|
/**
|
|
115
115
|
* If `true`, the page is rendered twice: on the server-side (to HTML) and on the client-side (hydration).
|
|
116
116
|
*
|
|
@@ -151,6 +151,6 @@ type Head = Component | JSX.Element;
|
|
|
151
151
|
type PickWithoutGetter<T, K extends keyof T> = {
|
|
152
152
|
[P in K]: Exclude<T[P], Function>;
|
|
153
153
|
};
|
|
154
|
-
type ConfigFromHook = PickWithoutGetter<Vike.Config, "Head" | "title" | "description" | "image">;
|
|
154
|
+
type ConfigFromHook = PickWithoutGetter<Vike.Config, "Head" | "title" | "description" | "image" | "favicon" | "lang" | "viewport" | "bodyAttributes" | "htmlAttributes">;
|
|
155
155
|
|
|
156
156
|
export type { ConfigFromHook as C };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// - We skip if `undefined` as we shouldn't remove values set by the Head setting.
|
|
2
|
+
// - Setting a default prevents the previous value to be leaked: upon client-side navigation, the value set by the previous page won't be removed if the next page doesn't override it.
|
|
3
|
+
// - Most of the time, the user sets a default himself (i.e. a value defined at /pages/+config.js)
|
|
4
|
+
// - If he doesn't have a default then he can use `null` to opt into Vike's defaults
|
|
5
|
+
|
|
6
|
+
function applyHeadSettings(title, lang) {
|
|
7
|
+
if (title !== undefined) document.title = title || "";
|
|
8
|
+
if (lang !== undefined) document.documentElement.lang = lang || "en";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { applyHeadSettings as a };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useConfig } from '../../hooks/useConfig/useConfig-client.js';
|
|
2
|
+
import '../../hooks/usePageContext.js';
|
|
3
|
+
import 'solid-js/web';
|
|
4
|
+
import 'solid-js';
|
|
5
|
+
import 'vike/getPageContext';
|
|
6
|
+
import '../../applyHeadSettings-BwjKVYXB.js';
|
|
7
|
+
|
|
8
|
+
function Config(props) {
|
|
9
|
+
const config = useConfig();
|
|
10
|
+
config(props);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { Config };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { C as ConfigFromHook } from '../../Config-CVJUysUv.js';
|
|
2
|
+
import 'solid-js';
|
|
3
|
+
import 'vike/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set configurations inside Solid components.
|
|
7
|
+
*
|
|
8
|
+
* https://vike.dev/useConfig
|
|
9
|
+
*/
|
|
10
|
+
declare function Config(props: ConfigFromHook): null;
|
|
11
|
+
|
|
12
|
+
export { Config };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useConfig } from '../../hooks/useConfig/useConfig-server.js';
|
|
2
|
+
import '../../hooks/usePageContext.js';
|
|
3
|
+
import 'solid-js/web';
|
|
4
|
+
import 'solid-js';
|
|
5
|
+
import 'vike/getPageContext';
|
|
6
|
+
import '../../includes-B0OUVLz0.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Set configurations inside Solid components.
|
|
10
|
+
*
|
|
11
|
+
* https://vike.dev/useConfig
|
|
12
|
+
*/
|
|
13
|
+
function Config(props) {
|
|
14
|
+
const config = useConfig();
|
|
15
|
+
config(props);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Config };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { JSX } from 'solid-js/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add arbitrary `<head>` tags.
|
|
5
|
+
*
|
|
6
|
+
* (The children are teleported to `<head>`.)
|
|
7
|
+
*
|
|
8
|
+
* https://vike.dev/Head
|
|
9
|
+
*/
|
|
10
|
+
declare function Head({ children }: {
|
|
11
|
+
children: JSX.Element;
|
|
12
|
+
}): null;
|
|
13
|
+
|
|
14
|
+
export { Head };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useConfig } from '../../hooks/useConfig/useConfig-server.js';
|
|
2
|
+
import '../../hooks/usePageContext.js';
|
|
3
|
+
import 'solid-js/web';
|
|
4
|
+
import 'solid-js';
|
|
5
|
+
import 'vike/getPageContext';
|
|
6
|
+
import '../../includes-B0OUVLz0.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Add arbitrary `<head>` tags.
|
|
10
|
+
*
|
|
11
|
+
* (The children are teleported to `<head>`.)
|
|
12
|
+
*
|
|
13
|
+
* https://vike.dev/Head
|
|
14
|
+
*/
|
|
15
|
+
function Head({
|
|
16
|
+
children
|
|
17
|
+
}) {
|
|
18
|
+
const config = useConfig();
|
|
19
|
+
config({
|
|
20
|
+
Head: children
|
|
21
|
+
});
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { Head };
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { C as ConfigFromHook } from '../../Config-
|
|
1
|
+
import { C as ConfigFromHook } from '../../Config-CVJUysUv.js';
|
|
2
2
|
import 'solid-js';
|
|
3
3
|
import 'vike/types';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Set configurations inside React components and Vike hooks.
|
|
7
|
-
*
|
|
8
|
-
* https://vike.dev/useConfig
|
|
9
|
-
*/
|
|
10
5
|
declare function useConfig(): (config: ConfigFromHook) => void;
|
|
11
6
|
|
|
12
7
|
export { useConfig };
|
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
import { usePageContext } from '../usePageContext.js';
|
|
2
2
|
import { getPageContext } from 'vike/getPageContext';
|
|
3
|
+
import { a as applyHeadSettings } from '../../applyHeadSettings-BwjKVYXB.js';
|
|
3
4
|
import 'solid-js/web';
|
|
4
5
|
import 'solid-js';
|
|
5
6
|
|
|
6
|
-
/**
|
|
7
|
-
* Set configurations inside React components and Vike hooks.
|
|
8
|
-
*
|
|
9
|
-
* https://vike.dev/useConfig
|
|
10
|
-
*/
|
|
11
7
|
function useConfig() {
|
|
12
|
-
const configSetter = config => setConfigOverPageContext(config, pageContext);
|
|
13
|
-
|
|
14
8
|
// Vike hook
|
|
15
9
|
let pageContext = getPageContext();
|
|
16
|
-
if (pageContext) return
|
|
10
|
+
if (pageContext) return config => setPageContextConfigFromHook(config, pageContext);
|
|
17
11
|
|
|
18
|
-
//
|
|
12
|
+
// Component
|
|
19
13
|
pageContext = usePageContext();
|
|
20
14
|
return config => {
|
|
21
15
|
if (!("_headAlreadySet" in pageContext)) {
|
|
22
|
-
|
|
16
|
+
setPageContextConfigFromHook(config, pageContext);
|
|
23
17
|
} else {
|
|
24
|
-
|
|
18
|
+
applyHead(config);
|
|
25
19
|
}
|
|
26
20
|
};
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
function setConfigOverPageContext(config, pageContext) {
|
|
22
|
+
function setPageContextConfigFromHook(config, pageContext) {
|
|
30
23
|
pageContext._configFromHook ??= {};
|
|
31
|
-
|
|
32
|
-
const configValue = config[configName];
|
|
33
|
-
if (!configValue) return;
|
|
34
|
-
pageContext._configFromHook[configName] = configValue;
|
|
35
|
-
});
|
|
24
|
+
Object.assign(pageContext._configFromHook, config);
|
|
36
25
|
}
|
|
37
|
-
function
|
|
26
|
+
function applyHead(config) {
|
|
38
27
|
const {
|
|
39
|
-
title
|
|
28
|
+
title,
|
|
29
|
+
lang
|
|
40
30
|
} = config;
|
|
41
|
-
|
|
42
|
-
window.document.title = title;
|
|
43
|
-
}
|
|
31
|
+
applyHeadSettings(title, lang);
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
export { useConfig };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as ConfigFromHook } from '../../Config-
|
|
1
|
+
import { C as ConfigFromHook } from '../../Config-CVJUysUv.js';
|
|
2
2
|
import 'solid-js';
|
|
3
3
|
import 'vike/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Set configurations inside
|
|
6
|
+
* Set configurations inside components and Vike hooks.
|
|
7
7
|
*
|
|
8
8
|
* https://vike.dev/useConfig
|
|
9
9
|
*/
|
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
import { usePageContext } from '../usePageContext.js';
|
|
2
2
|
import { getPageContext } from 'vike/getPageContext';
|
|
3
|
+
import { i as includes, c as configsCumulative } from '../../includes-B0OUVLz0.js';
|
|
3
4
|
import 'solid-js/web';
|
|
4
5
|
import 'solid-js';
|
|
5
6
|
|
|
7
|
+
// https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
|
|
8
|
+
// https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
|
|
9
|
+
/** Same as Object.keys() but with type inference */
|
|
10
|
+
function objectKeys(obj) {
|
|
11
|
+
return Object.keys(obj);
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
/**
|
|
7
|
-
* Set configurations inside
|
|
15
|
+
* Set configurations inside components and Vike hooks.
|
|
8
16
|
*
|
|
9
17
|
* https://vike.dev/useConfig
|
|
10
18
|
*/
|
|
11
19
|
function useConfig() {
|
|
12
|
-
const configSetter = config => setConfigOverPageContext(config, pageContext);
|
|
13
|
-
|
|
14
20
|
// Vike hook
|
|
15
21
|
let pageContext = getPageContext();
|
|
16
|
-
if (pageContext) return
|
|
22
|
+
if (pageContext) return config => setPageContextConfigFromHook(config, pageContext);
|
|
17
23
|
|
|
18
|
-
//
|
|
24
|
+
// Component
|
|
19
25
|
pageContext = usePageContext();
|
|
20
26
|
return config => {
|
|
21
27
|
if (!pageContext._headAlreadySet) {
|
|
22
|
-
|
|
28
|
+
setPageContextConfigFromHook(config, pageContext);
|
|
23
29
|
} else {
|
|
24
30
|
throw new Error("Using useConfig() with HTML streaming isn't supported yet");
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const configsOverridable = ["title", "description", "image"];
|
|
31
|
-
function setConfigOverPageContext(config, pageContext) {
|
|
34
|
+
const configsClientSide = ["title"];
|
|
35
|
+
function setPageContextConfigFromHook(config, pageContext) {
|
|
32
36
|
pageContext._configFromHook ??= {};
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const configValue = config[configName];
|
|
49
|
-
if (!configValue) return;
|
|
50
|
-
pageContext._configFromHook[configName] = configValue;
|
|
37
|
+
objectKeys(config).forEach(configName => {
|
|
38
|
+
// Skip HTML only configs which the client-side doesn't need, saving KBs sent to the client as well as avoiding serialization errors.
|
|
39
|
+
if (pageContext.isClientSideNavigation && !configsClientSide.includes(configName)) return;
|
|
40
|
+
if (!includes(configsCumulative, configName)) {
|
|
41
|
+
// Overridable config
|
|
42
|
+
const configValue = config[configName];
|
|
43
|
+
if (configValue === undefined) return;
|
|
44
|
+
pageContext._configFromHook[configName] = configValue;
|
|
45
|
+
} else {
|
|
46
|
+
// Cumulative config
|
|
47
|
+
const configValue = config[configName];
|
|
48
|
+
if (!configValue) return;
|
|
49
|
+
pageContext._configFromHook[configName] ??= [];
|
|
50
|
+
pageContext._configFromHook[configName].push(configValue);
|
|
51
|
+
}
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const configsCumulative = ["Head", "bodyAttributes", "htmlAttributes"];
|
|
2
|
+
|
|
3
|
+
// https://stackoverflow.com/questions/56565528/typescript-const-assertions-how-to-use-array-prototype-includes/74213179#74213179
|
|
4
|
+
/** Same as Array.prototype.includes() but with type inference */
|
|
5
|
+
function includes(values, x) {
|
|
6
|
+
return values.includes(x);
|
|
7
|
+
}
|
|
8
|
+
/*
|
|
9
|
+
export function includes<Arr extends any[] | readonly any[]>(arr: Arr, el: unknown): el is Arr[number] {
|
|
10
|
+
return arr.includes(el as any)
|
|
11
|
+
}
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export { configsCumulative as c, includes as i };
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { createComponent, Dynamic, memo, hydrate, render } from 'solid-js/web';
|
|
2
|
+
import { i as includes, c as configsCumulative } from '../includes-B0OUVLz0.js';
|
|
2
3
|
import { PageContextProvider, usePageContext } from '../hooks/usePageContext.js';
|
|
3
4
|
import { createComputed, createComponent as createComponent$1 } from 'solid-js';
|
|
4
5
|
import { createStore, reconcile } from 'solid-js/store';
|
|
6
|
+
import { a as applyHeadSettings } from '../applyHeadSettings-BwjKVYXB.js';
|
|
5
7
|
|
|
6
8
|
function isCallable(thing) {
|
|
7
9
|
return thing instanceof Function || typeof thing === "function";
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const valStr = val(pageContext);
|
|
22
|
-
if (typeof valStr !== "string") {
|
|
23
|
-
throw new Error(config.configDefinedAt + " should return a string");
|
|
24
|
-
}
|
|
25
|
-
return valStr;
|
|
12
|
+
// We use `any` instead of doing proper validation in order to save KBs sent to the client-side.
|
|
13
|
+
|
|
14
|
+
function getHeadSetting(configName, pageContext) {
|
|
15
|
+
// Set by useConfig()
|
|
16
|
+
const valFromUseConfig = pageContext._configFromHook?.[configName];
|
|
17
|
+
// Set by +configName.js
|
|
18
|
+
const valFromConfig = pageContext.config[configName];
|
|
19
|
+
const getCallable = val => isCallable(val) ? val(pageContext) : val;
|
|
20
|
+
if (!includes(configsCumulative, configName)) {
|
|
21
|
+
if (valFromUseConfig !== undefined) return valFromUseConfig;
|
|
22
|
+
return getCallable(valFromConfig);
|
|
26
23
|
} else {
|
|
27
|
-
|
|
24
|
+
return [
|
|
25
|
+
//
|
|
26
|
+
...(valFromConfig ?? []).map(getCallable), ...(valFromUseConfig ?? [])];
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -91,6 +90,7 @@ const [pageContextStore, setPageContext] = createStore({});
|
|
|
91
90
|
let dispose;
|
|
92
91
|
let rendered = false;
|
|
93
92
|
const onRenderClient = async pageContext => {
|
|
93
|
+
pageContext._headAlreadySet = pageContext.isHydration;
|
|
94
94
|
if (!rendered) {
|
|
95
95
|
// Dispose to prevent duplicate pages when navigating.
|
|
96
96
|
if (dispose) dispose();
|
|
@@ -110,8 +110,8 @@ const onRenderClient = async pageContext => {
|
|
|
110
110
|
setPageContext(pageContext);
|
|
111
111
|
}
|
|
112
112
|
if (!pageContext.isHydration) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
pageContext._headAlreadySet = true;
|
|
114
|
+
applyHead(pageContext);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// Use cases:
|
|
@@ -119,17 +119,10 @@ const onRenderClient = async pageContext => {
|
|
|
119
119
|
// - Testing tools: https://github.com/vikejs/vike-react/issues/95
|
|
120
120
|
await callCumulativeHooks(pageContext.config.onAfterRenderClient, pageContext);
|
|
121
121
|
};
|
|
122
|
-
function
|
|
123
|
-
pageContext._headAlreadySet = true;
|
|
122
|
+
function applyHead(pageContext) {
|
|
124
123
|
const title = getHeadSetting("title", pageContext);
|
|
125
124
|
const lang = getHeadSetting("lang", pageContext);
|
|
126
|
-
|
|
127
|
-
// - We skip if `undefined` as we shouldn't remove values set by the Head setting.
|
|
128
|
-
// - Setting a default prevents the previous value to be leaked: upon client-side navigation, the value set by the previous page won't be removed if the next page doesn't override it.
|
|
129
|
-
// - Most of the time, the user sets a default himself (i.e. a value defined at /pages/+config.js)
|
|
130
|
-
// - If he doesn't have a default then he can use `null` to opt into Vike's defaults
|
|
131
|
-
if (title !== undefined) document.title = title || "";
|
|
132
|
-
if (lang !== undefined) document.documentElement.lang = lang || "en";
|
|
125
|
+
applyHeadSettings(title, lang);
|
|
133
126
|
}
|
|
134
127
|
|
|
135
128
|
export { onRenderClient };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createComponent, Dynamic, generateHydrationScript, renderToString, renderToStream } from 'solid-js/web';
|
|
2
2
|
import { escapeInject, dangerouslySkipEscape, stampPipe } from 'vike/server';
|
|
3
|
+
import { i as includes, c as configsCumulative } from '../includes-B0OUVLz0.js';
|
|
3
4
|
import { PageContextProvider, usePageContext } from '../hooks/usePageContext.js';
|
|
4
5
|
import { createComputed, createComponent as createComponent$1 } from 'solid-js';
|
|
5
6
|
import { createStore, reconcile } from 'solid-js/store';
|
|
@@ -8,24 +9,21 @@ function isCallable(thing) {
|
|
|
8
9
|
return thing instanceof Function || typeof thing === "function";
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const valStr = val(pageContext);
|
|
23
|
-
if (typeof valStr !== "string") {
|
|
24
|
-
throw new Error(config.configDefinedAt + " should return a string");
|
|
25
|
-
}
|
|
26
|
-
return valStr;
|
|
12
|
+
// We use `any` instead of doing proper validation in order to save KBs sent to the client-side.
|
|
13
|
+
|
|
14
|
+
function getHeadSetting(configName, pageContext) {
|
|
15
|
+
// Set by useConfig()
|
|
16
|
+
const valFromUseConfig = pageContext._configFromHook?.[configName];
|
|
17
|
+
// Set by +configName.js
|
|
18
|
+
const valFromConfig = pageContext.config[configName];
|
|
19
|
+
const getCallable = val => isCallable(val) ? val(pageContext) : val;
|
|
20
|
+
if (!includes(configsCumulative, configName)) {
|
|
21
|
+
if (valFromUseConfig !== undefined) return valFromUseConfig;
|
|
22
|
+
return getCallable(valFromConfig);
|
|
27
23
|
} else {
|
|
28
|
-
|
|
24
|
+
return [
|
|
25
|
+
//
|
|
26
|
+
...(valFromConfig ?? []).map(getCallable), ...(valFromUseConfig ?? [])];
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
|
|
@@ -89,6 +87,9 @@ const onRenderHtml = async pageContext => {
|
|
|
89
87
|
htmlAttributesString,
|
|
90
88
|
bodyAttributesString
|
|
91
89
|
} = getTagAttributes(pageContext);
|
|
90
|
+
|
|
91
|
+
// Not needed on the client-side, thus we remove it to save KBs sent to the client
|
|
92
|
+
delete pageContext._configFromHook;
|
|
92
93
|
return escapeInject`<!DOCTYPE html>
|
|
93
94
|
<html${dangerouslySkipEscape(htmlAttributesString)}>
|
|
94
95
|
<head>
|
|
@@ -126,7 +127,7 @@ function getHeadHtml(pageContext) {
|
|
|
126
127
|
const faviconTag = !favicon ? "" : escapeInject`<link rel="icon" href="${favicon}" />`;
|
|
127
128
|
const descriptionTags = !description ? "" : escapeInject`<meta name="description" content="${description}"><meta property="og:description" content="${description}">`;
|
|
128
129
|
const imageTags = !image ? "" : escapeInject`<meta property="og:image" content="${image}"><meta name="twitter:card" content="summary_large_image">`;
|
|
129
|
-
const viewportTag = dangerouslySkipEscape(getViewportTag(pageContext
|
|
130
|
+
const viewportTag = dangerouslySkipEscape(getViewportTag(getHeadSetting("viewport", pageContext)));
|
|
130
131
|
const headElementsHtml = dangerouslySkipEscape([
|
|
131
132
|
// Added by +Head
|
|
132
133
|
...(pageContext.config.Head ?? []),
|
|
@@ -164,8 +165,8 @@ function getTagAttributes(pageContext) {
|
|
|
164
165
|
let lang = getHeadSetting("lang", pageContext);
|
|
165
166
|
// Don't set `lang` to its default value if it's `null` (so that users can set it to `null` in order to remove the default value)
|
|
166
167
|
if (lang === undefined) lang = "en";
|
|
167
|
-
const bodyAttributes = mergeTagAttributesList(pageContext
|
|
168
|
-
const htmlAttributes = mergeTagAttributesList(pageContext
|
|
168
|
+
const bodyAttributes = mergeTagAttributesList(getHeadSetting("bodyAttributes", pageContext));
|
|
169
|
+
const htmlAttributes = mergeTagAttributesList(getHeadSetting("htmlAttributes", pageContext));
|
|
169
170
|
const bodyAttributesString = getTagAttributesString(bodyAttributes);
|
|
170
171
|
const htmlAttributesString = getTagAttributesString({
|
|
171
172
|
...htmlAttributes,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-solid",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "rollup -c rollup.config.js --watch",
|
|
7
|
-
"dev:
|
|
7
|
+
"dev:typecheck": "tsc --noEmit --watch",
|
|
8
8
|
"build": "tsc --noEmit && rollup -c rollup.config.js",
|
|
9
9
|
"release": "LANG=en_US release-me patch",
|
|
10
10
|
"release:minor": "LANG=en_US release-me minor",
|
|
@@ -15,26 +15,25 @@
|
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"solid-js": "^1.8.7",
|
|
18
|
-
"vike": "
|
|
19
|
-
"vite": "^4.4 || ^5.0.2"
|
|
18
|
+
"vike": ">=0.4.182"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@babel/core": "^7.
|
|
23
|
-
"@babel/preset-env": "^7.
|
|
21
|
+
"@babel/core": "^7.25.2",
|
|
22
|
+
"@babel/preset-env": "^7.25.3",
|
|
24
23
|
"@babel/preset-typescript": "^7.24.7",
|
|
25
|
-
"@brillout/release-me": "^0.
|
|
24
|
+
"@brillout/release-me": "^0.4.0",
|
|
26
25
|
"@rollup/plugin-babel": "^6.0.4",
|
|
27
26
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
28
|
-
"@types/node": "^
|
|
29
|
-
"babel-preset-solid": "^1.8.
|
|
30
|
-
"bumpp": "^9.
|
|
31
|
-
"rollup": "^4.
|
|
27
|
+
"@types/node": "^22.4.0",
|
|
28
|
+
"babel-preset-solid": "^1.8.19",
|
|
29
|
+
"bumpp": "^9.5.1",
|
|
30
|
+
"rollup": "^4.20.0",
|
|
32
31
|
"rollup-plugin-dts": "^6.1.1",
|
|
33
|
-
"solid-js": "^1.8.
|
|
32
|
+
"solid-js": "^1.8.21",
|
|
34
33
|
"tslib": "^2.6.3",
|
|
35
|
-
"typescript": "^5.5.
|
|
36
|
-
"vike": "^0.4.
|
|
37
|
-
"vite": "^5.
|
|
34
|
+
"typescript": "^5.5.4",
|
|
35
|
+
"vike": "^0.4.184",
|
|
36
|
+
"vite": "^5.4.1"
|
|
38
37
|
},
|
|
39
38
|
"exports": {
|
|
40
39
|
"./config": "./dist/+config.js",
|
|
@@ -45,6 +44,14 @@
|
|
|
45
44
|
"browser": "./dist/hooks/useConfig/useConfig-client.js",
|
|
46
45
|
"default": "./dist/hooks/useConfig/useConfig-server.js"
|
|
47
46
|
},
|
|
47
|
+
"./Config": {
|
|
48
|
+
"browser": "./dist/components/Config/Config-client.js",
|
|
49
|
+
"default": "./dist/components/Config/Config-server.js"
|
|
50
|
+
},
|
|
51
|
+
"./Head": {
|
|
52
|
+
"browser": "./dist/components/Head/Head-client.js",
|
|
53
|
+
"default": "./dist/components/Head/Head-server.js"
|
|
54
|
+
},
|
|
48
55
|
"./clientOnly": "./dist/helpers/clientOnly.js",
|
|
49
56
|
"./renderer/onRenderHtml": "./dist/renderer/onRenderHtml.js",
|
|
50
57
|
"./renderer/onRenderClient": "./dist/renderer/onRenderClient.js",
|
|
@@ -72,6 +79,12 @@
|
|
|
72
79
|
"useConfig": [
|
|
73
80
|
"dist/hooks/useConfig/useConfig-server.d.ts"
|
|
74
81
|
],
|
|
82
|
+
"Config": [
|
|
83
|
+
"./dist/components/Config/Config-server.d.ts"
|
|
84
|
+
],
|
|
85
|
+
"Head": [
|
|
86
|
+
"./dist/components/Head/Head-server.d.ts"
|
|
87
|
+
],
|
|
75
88
|
"clientOnly": [
|
|
76
89
|
"dist/helpers/clientOnly.d.ts"
|
|
77
90
|
]
|