vike-solid 0.7.1 → 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 CHANGED
@@ -7,7 +7,7 @@ declare function ssrEffect({ configDefinedAt, configValue }: Parameters<ConfigEf
7
7
  declare global {
8
8
  namespace Vike {
9
9
  interface PageContext {
10
- /** The root React component of the page */
10
+ /** The root Solid component of the page */
11
11
  Page?: () => JSX.Element;
12
12
  }
13
13
  }
@@ -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 };
@@ -2,11 +2,6 @@ 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.
7
- *
8
- * https://vike.dev/useConfig
9
- */
10
5
  declare function Config(props: ConfigFromHook): null;
11
6
 
12
7
  export { Config };
@@ -3,12 +3,8 @@ import '../../hooks/usePageContext.js';
3
3
  import 'solid-js/web';
4
4
  import 'solid-js';
5
5
  import 'vike/getPageContext';
6
+ import '../../applyHeadSettings-BwjKVYXB.js';
6
7
 
7
- /**
8
- * Set configurations inside React components.
9
- *
10
- * https://vike.dev/useConfig
11
- */
12
8
  function Config(props) {
13
9
  const config = useConfig();
14
10
  config(props);
@@ -3,7 +3,7 @@ import 'solid-js';
3
3
  import 'vike/types';
4
4
 
5
5
  /**
6
- * Set configurations inside React components.
6
+ * Set configurations inside Solid components.
7
7
  *
8
8
  * https://vike.dev/useConfig
9
9
  */
@@ -3,9 +3,10 @@ import '../../hooks/usePageContext.js';
3
3
  import 'solid-js/web';
4
4
  import 'solid-js';
5
5
  import 'vike/getPageContext';
6
+ import '../../includes-B0OUVLz0.js';
6
7
 
7
8
  /**
8
- * Set configurations inside React components.
9
+ * Set configurations inside Solid components.
9
10
  *
10
11
  * https://vike.dev/useConfig
11
12
  */
@@ -3,6 +3,7 @@ import '../../hooks/usePageContext.js';
3
3
  import 'solid-js/web';
4
4
  import 'solid-js';
5
5
  import 'vike/getPageContext';
6
+ import '../../includes-B0OUVLz0.js';
6
7
 
7
8
  /**
8
9
  * Add arbitrary `<head>` tags.
@@ -2,11 +2,6 @@ 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,25 +1,21 @@
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
8
  // Vike hook
13
9
  let pageContext = getPageContext();
14
10
  if (pageContext) return config => setPageContextConfigFromHook(config, pageContext);
15
11
 
16
- // React component
12
+ // Component
17
13
  pageContext = usePageContext();
18
14
  return config => {
19
15
  if (!("_headAlreadySet" in pageContext)) {
20
16
  setPageContextConfigFromHook(config, pageContext);
21
17
  } else {
22
- apply(config);
18
+ applyHead(config);
23
19
  }
24
20
  };
25
21
  }
@@ -27,11 +23,12 @@ function setPageContextConfigFromHook(config, pageContext) {
27
23
  pageContext._configFromHook ??= {};
28
24
  Object.assign(pageContext._configFromHook, config);
29
25
  }
30
- function apply(config) {
26
+ function applyHead(config) {
31
27
  const {
32
- title
28
+ title,
29
+ lang
33
30
  } = config;
34
- if (title) window.document.title = title;
31
+ applyHeadSettings(title, lang);
35
32
  }
36
33
 
37
34
  export { useConfig };
@@ -2,14 +2,11 @@ import { C as ConfigFromHook } from '../../Config-CVJUysUv.js';
2
2
  import 'solid-js';
3
3
  import 'vike/types';
4
4
 
5
- type ConfigFromHookCumulative = (typeof configsCumulative)[number];
6
-
7
5
  /**
8
- * Set configurations inside React components and Vike hooks.
6
+ * Set configurations inside components and Vike hooks.
9
7
  *
10
8
  * https://vike.dev/useConfig
11
9
  */
12
10
  declare function useConfig(): (config: ConfigFromHook) => void;
13
- declare const configsCumulative: readonly ["Head", "bodyAttributes", "htmlAttributes"];
14
11
 
15
- export { type ConfigFromHookCumulative, useConfig };
12
+ export { useConfig };
@@ -1,5 +1,6 @@
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
 
@@ -10,19 +11,8 @@ function objectKeys(obj) {
10
11
  return Object.keys(obj);
11
12
  }
12
13
 
13
- // https://stackoverflow.com/questions/56565528/typescript-const-assertions-how-to-use-array-prototype-includes/74213179#74213179
14
- /** Same as Array.prototype.includes() but with type inference */
15
- function includes(values, x) {
16
- return values.includes(x);
17
- }
18
- /*
19
- export function includes<Arr extends any[] | readonly any[]>(arr: Arr, el: unknown): el is Arr[number] {
20
- return arr.includes(el as any)
21
- }
22
- */
23
-
24
14
  /**
25
- * Set configurations inside React components and Vike hooks.
15
+ * Set configurations inside components and Vike hooks.
26
16
  *
27
17
  * https://vike.dev/useConfig
28
18
  */
@@ -31,7 +21,7 @@ function useConfig() {
31
21
  let pageContext = getPageContext();
32
22
  if (pageContext) return config => setPageContextConfigFromHook(config, pageContext);
33
23
 
34
- // React component
24
+ // Component
35
25
  pageContext = usePageContext();
36
26
  return config => {
37
27
  if (!pageContext._headAlreadySet) {
@@ -42,7 +32,6 @@ function useConfig() {
42
32
  };
43
33
  }
44
34
  const configsClientSide = ["title"];
45
- const configsCumulative = ["Head", "bodyAttributes", "htmlAttributes"];
46
35
  function setPageContextConfigFromHook(config, pageContext) {
47
36
  pageContext._configFromHook ??= {};
48
37
  objectKeys(config).forEach(configName => {
@@ -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,27 +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
- // We use `any` instead of doing proper validation in order to save KBs sent to the client-side
12
+ // We use `any` instead of doing proper validation in order to save KBs sent to the client-side.
11
13
 
12
- function getHeadSetting(headSetting, pageContext) {
14
+ function getHeadSetting(configName, pageContext) {
13
15
  // Set by useConfig()
14
- {
15
- const val = pageContext._configFromHook?.[headSetting];
16
- if (val !== undefined) return val;
17
- }
18
-
16
+ const valFromUseConfig = pageContext._configFromHook?.[configName];
19
17
  // Set by +configName.js
20
- const val = pageContext.config[headSetting];
21
- if (isCallable(val)) {
22
- return val(pageContext);
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);
23
23
  } else {
24
- return val;
24
+ return [
25
+ //
26
+ ...(valFromConfig ?? []).map(getCallable), ...(valFromUseConfig ?? [])];
25
27
  }
26
28
  }
27
29
 
@@ -88,6 +90,7 @@ const [pageContextStore, setPageContext] = createStore({});
88
90
  let dispose;
89
91
  let rendered = false;
90
92
  const onRenderClient = async pageContext => {
93
+ pageContext._headAlreadySet = pageContext.isHydration;
91
94
  if (!rendered) {
92
95
  // Dispose to prevent duplicate pages when navigating.
93
96
  if (dispose) dispose();
@@ -107,8 +110,8 @@ const onRenderClient = async pageContext => {
107
110
  setPageContext(pageContext);
108
111
  }
109
112
  if (!pageContext.isHydration) {
110
- // E.g. document.title
111
- updateDocument(pageContext);
113
+ pageContext._headAlreadySet = true;
114
+ applyHead(pageContext);
112
115
  }
113
116
 
114
117
  // Use cases:
@@ -116,17 +119,10 @@ const onRenderClient = async pageContext => {
116
119
  // - Testing tools: https://github.com/vikejs/vike-react/issues/95
117
120
  await callCumulativeHooks(pageContext.config.onAfterRenderClient, pageContext);
118
121
  };
119
- function updateDocument(pageContext) {
120
- pageContext._headAlreadySet = true;
122
+ function applyHead(pageContext) {
121
123
  const title = getHeadSetting("title", pageContext);
122
124
  const lang = getHeadSetting("lang", pageContext);
123
-
124
- // - We skip if `undefined` as we shouldn't remove values set by the Head setting.
125
- // - 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.
126
- // - Most of the time, the user sets a default himself (i.e. a value defined at /pages/+config.js)
127
- // - If he doesn't have a default then he can use `null` to opt into Vike's defaults
128
- if (title !== undefined) document.title = title || "";
129
- if (lang !== undefined) document.documentElement.lang = lang || "en";
125
+ applyHeadSettings(title, lang);
130
126
  }
131
127
 
132
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,21 +9,21 @@ function isCallable(thing) {
8
9
  return thing instanceof Function || typeof thing === "function";
9
10
  }
10
11
 
11
- // We use `any` instead of doing proper validation in order to save KBs sent to the client-side
12
+ // We use `any` instead of doing proper validation in order to save KBs sent to the client-side.
12
13
 
13
- function getHeadSetting(headSetting, pageContext) {
14
+ function getHeadSetting(configName, pageContext) {
14
15
  // Set by useConfig()
15
- {
16
- const val = pageContext._configFromHook?.[headSetting];
17
- if (val !== undefined) return val;
18
- }
19
-
16
+ const valFromUseConfig = pageContext._configFromHook?.[configName];
20
17
  // Set by +configName.js
21
- const val = pageContext.config[headSetting];
22
- if (isCallable(val)) {
23
- return val(pageContext);
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);
24
23
  } else {
25
- return val;
24
+ return [
25
+ //
26
+ ...(valFromConfig ?? []).map(getCallable), ...(valFromUseConfig ?? [])];
26
27
  }
27
28
  }
28
29
 
@@ -86,6 +87,9 @@ const onRenderHtml = async pageContext => {
86
87
  htmlAttributesString,
87
88
  bodyAttributesString
88
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;
89
93
  return escapeInject`<!DOCTYPE html>
90
94
  <html${dangerouslySkipEscape(htmlAttributesString)}>
91
95
  <head>
@@ -129,9 +133,6 @@ function getHeadHtml(pageContext) {
129
133
  ...(pageContext.config.Head ?? []),
130
134
  // Added by useConfig()
131
135
  ...(pageContext._configFromHook?.Head ?? [])].filter(Head => Head !== null && Head !== undefined).map(Head => getHeadElementHtml(Head, pageContext)).join("\n"));
132
-
133
- // Not needed on the client-side, thus we remove it to save KBs sent to the client
134
- delete pageContext._configFromHook;
135
136
  const headHtml = escapeInject`
136
137
  ${titleTags}
137
138
  ${viewportTag}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-solid",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "rollup -c rollup.config.js --watch",
@@ -18,22 +18,22 @@
18
18
  "vike": ">=0.4.182"
19
19
  },
20
20
  "devDependencies": {
21
- "@babel/core": "^7.24.9",
22
- "@babel/preset-env": "^7.24.8",
21
+ "@babel/core": "^7.25.2",
22
+ "@babel/preset-env": "^7.25.3",
23
23
  "@babel/preset-typescript": "^7.24.7",
24
- "@brillout/release-me": "^0.3.9",
24
+ "@brillout/release-me": "^0.4.0",
25
25
  "@rollup/plugin-babel": "^6.0.4",
26
26
  "@rollup/plugin-node-resolve": "^15.2.3",
27
- "@types/node": "^20.14.11",
28
- "babel-preset-solid": "^1.8.18",
29
- "bumpp": "^9.4.1",
30
- "rollup": "^4.19.0",
27
+ "@types/node": "^22.4.0",
28
+ "babel-preset-solid": "^1.8.19",
29
+ "bumpp": "^9.5.1",
30
+ "rollup": "^4.20.0",
31
31
  "rollup-plugin-dts": "^6.1.1",
32
- "solid-js": "^1.8.18",
32
+ "solid-js": "^1.8.21",
33
33
  "tslib": "^2.6.3",
34
- "typescript": "^5.5.3",
35
- "vike": "^0.4.183",
36
- "vite": "^5.4.0"
34
+ "typescript": "^5.5.4",
35
+ "vike": "^0.4.184",
36
+ "vite": "^5.4.1"
37
37
  },
38
38
  "exports": {
39
39
  "./config": "./dist/+config.js",