vike-solid 0.8.2 → 0.8.4

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/README.md CHANGED
@@ -1,2 +1,6 @@
1
- Docs: [vike.dev/vike-solid](https://vike.dev/vike-solid)
1
+ <!-- WARNING: keep links absolute in this file so they work on NPM too: https://www.npmjs.com/package/vike-solid -->
2
+
3
+ [![npm version](https://img.shields.io/npm/v/vike-solid)](https://www.npmjs.com/package/vike-solid)
4
+
5
+ Docs: see [vike.dev/vike-solid](https://vike.dev/vike-solid)
2
6
  Source code: [GitHub > vikejs/vike-solid](https://github.com/vikejs/vike-solid)
@@ -6,4 +6,4 @@ function assertWarning(condition, message) {
6
6
  console.warn(new Error(message));
7
7
  }
8
8
 
9
- export { assertWarning as a, assert as b };
9
+ export { assert as a, assertWarning as b };
@@ -3,7 +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
+ import '../../configsCumulative-VCpzeMWX.js';
7
7
 
8
8
  /**
9
9
  * Set configurations inside Solid components.
@@ -3,7 +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
+ import '../../configsCumulative-VCpzeMWX.js';
7
7
 
8
8
  /**
9
9
  * Add arbitrary `<head>` tags.
@@ -0,0 +1,24 @@
1
+ // https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
2
+ // https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
3
+ /** Same as Object.keys() but with type inference */
4
+ function objectKeys(obj) {
5
+ return Object.keys(obj);
6
+ }
7
+
8
+ // https://stackoverflow.com/questions/56565528/typescript-const-assertions-how-to-use-array-prototype-includes/74213179#74213179
9
+ /** Same as Array.prototype.includes() but with type inference */
10
+ function includes(values, x) {
11
+ return values.includes(x);
12
+ }
13
+ /*
14
+ export function includes<Arr extends any[] | readonly any[]>(arr: Arr, el: unknown): el is Arr[number] {
15
+ return arr.includes(el as any)
16
+ }
17
+ */
18
+
19
+ const configsCumulative = ["Head", "bodyAttributes", "htmlAttributes"];
20
+
21
+ // Settings the client-side applies upon navigation, see applyHeadSettings(). The others are HTML-only.
22
+ const configsClientSide = ["title", "lang"];
23
+
24
+ export { configsCumulative as a, configsClientSide as c, includes as i, objectKeys as o };
@@ -1,6 +1,6 @@
1
1
  import { createSignal, splitProps, sharedConfig, onMount, createMemo, untrack } from 'solid-js';
2
2
  import { isServer } from 'solid-js/web';
3
- import { a as assertWarning } from '../assert-DxoZsFMo.js';
3
+ import { b as assertWarning } from '../assert-Ti2177O-.js';
4
4
 
5
5
  // TO-DO/breaking-change: remove it
6
6
 
@@ -1,6 +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
+ import { i as includes, c as configsCumulative } from '../../configsCumulative-VCpzeMWX.js';
4
4
  import 'solid-js/web';
5
5
  import 'solid-js';
6
6
 
@@ -11,6 +11,22 @@ function objectKeys(obj) {
11
11
  return Object.keys(obj);
12
12
  }
13
13
 
14
+ /**
15
+ * Escapes a JavaScript expression (e.g. the output of `JSON.stringify()`) so that it can be safely embedded inside an inline `<script>`.
16
+ *
17
+ * https://github.com/vikejs/vike/issues/3463
18
+ */
19
+ function escapeJavaScriptExpression(js) {
20
+ return js
21
+ // `<` is escaped so that the HTML parser never encounters `</script>` nor `<!--` inside the `<script>` — the JavaScript parser decodes `\u003c` back to `<`. (The input must be a JavaScript expression whose `<` only ever occurs inside string literals, such as `JSON.stringify()` output.)
22
+ .replace(/</g, "\\u003c")
23
+ // U+2028/U+2029 are escaped because a raw U+2028/U+2029 inside a JavaScript string literal is a syntax error in pre-ES2019 browsers.
24
+ .replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
25
+ }
26
+
27
+ // Settings the client-side applies upon navigation, see applyHeadSettings(). The others are HTML-only.
28
+ const configsClientSide = ["title", "lang"];
29
+
14
30
  /**
15
31
  * Set configurations inside components and Vike hooks.
16
32
  *
@@ -34,12 +50,11 @@ function useConfig() {
34
50
  }
35
51
  };
36
52
  }
37
- const configsClientSide = ["title"];
38
53
  function setPageContextConfigFromHook(config, pageContext) {
39
54
  pageContext._configFromHook ??= {};
40
55
  objectKeys(config).forEach(configName => {
41
56
  // Skip HTML only configs which the client-side doesn't need, saving KBs sent to the client as well as avoiding serialization errors.
42
- if (pageContext.isClientSideNavigation && !configsClientSide.includes(configName)) return;
57
+ if (pageContext.isClientSideNavigation && !includes(configsClientSide, configName)) return;
43
58
  if (!includes(configsCumulative, configName)) {
44
59
  // Overridable config
45
60
  const configValue = config[configName];
@@ -59,7 +74,8 @@ function apply(config, stream) {
59
74
  title
60
75
  } = config;
61
76
  if (title) {
62
- const htmlSnippet = `<script>document.title = ${JSON.stringify(title)}</script>`;
77
+ const titleJs = escapeJavaScriptExpression(JSON.stringify(title));
78
+ const htmlSnippet = `<script>document.title = ${titleJs}</script>`;
63
79
  stream.write(htmlSnippet);
64
80
  }
65
81
  }
@@ -1,5 +1,5 @@
1
1
  import { createComponent, memo, Dynamic, hydrate, render } from 'solid-js/web';
2
- import { i as includes, c as configsCumulative } from '../includes-B0OUVLz0.js';
2
+ import { i as includes, c as configsCumulative } from '../configsCumulative-VCpzeMWX.js';
3
3
  import { PageContextProvider, usePageContext } from '../hooks/usePageContext.js';
4
4
  import { createComputed, createComponent as createComponent$1 } from 'solid-js';
5
5
  import { createStore, reconcile } from 'solid-js/store';
@@ -2,7 +2,7 @@ import { createComponent, Dynamic, generateHydrationScript, renderToStringAsync,
2
2
  import isBot from 'isbot-fast';
3
3
  import { dangerouslySkipEscape, escapeInject, stampPipe } from 'vike/server';
4
4
  import { PageContextProvider, usePageContext } from '../hooks/usePageContext.js';
5
- import { i as includes, c as configsCumulative } from '../includes-B0OUVLz0.js';
5
+ import { i as includes, a as configsCumulative, o as objectKeys, c as configsClientSide } from '../configsClientSide-ByDxapiw.js';
6
6
  import { createComputed, createComponent as createComponent$1 } from 'solid-js';
7
7
  import { createStore, reconcile } from 'solid-js/store';
8
8
 
@@ -106,8 +106,9 @@ const onRenderHtml = async pageContext => {
106
106
  bodyAttributesString
107
107
  } = getTagAttributes(pageContext);
108
108
 
109
- // Not needed on the client-side, thus we remove it to save KBs sent to the client
110
- delete pageContext._configFromHook;
109
+ // Keep only what the client-side applies upon navigation, and remove the rest (HTML-only and/or
110
+ // non-serializable values such as <Head> components). https://github.com/vikejs/vike-vue/issues/233
111
+ removeServerOnlyConfigFromHook(pageContext);
111
112
  return escapeInject`<!DOCTYPE html>
112
113
  <html${dangerouslySkipEscape(htmlAttributesString)}>
113
114
  <head>
@@ -120,6 +121,15 @@ const onRenderHtml = async pageContext => {
120
121
  </body>
121
122
  </html>`;
122
123
  };
124
+ function removeServerOnlyConfigFromHook(pageContext) {
125
+ const configFromHook = pageContext._configFromHook;
126
+ if (!configFromHook) return;
127
+ objectKeys(configFromHook).forEach(configName => {
128
+ if (!includes(configsClientSide, configName)) delete configFromHook[configName];
129
+ });
130
+ // Remove it altogether if there isn't anything left, saving KBs sent to the client
131
+ if (objectKeys(configFromHook).length === 0) delete pageContext._configFromHook;
132
+ }
123
133
  async function getPageHtml(pageContext) {
124
134
  let pageHtml = "";
125
135
  const userAgent = pageContext.headers?.["user-agent"] ||
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "vike-solid",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
+ "repository": "https://github.com/vikejs/vike-solid",
4
5
  "type": "module",
5
6
  "dependencies": {
6
7
  "isbot-fast": "^1.2.0"
@@ -11,23 +12,23 @@
11
12
  "vite-plugin-solid": "^2.11.10"
12
13
  },
13
14
  "devDependencies": {
14
- "@babel/core": "^7.29.0",
15
- "@babel/preset-env": "^7.29.2",
16
- "@babel/preset-typescript": "^7.28.5",
17
- "@brillout/release-me": "^0.4.13",
18
- "@rollup/plugin-babel": "^7.0.0",
15
+ "@babel/core": "^8.0.1",
16
+ "@babel/preset-env": "^8.0.2",
17
+ "@babel/preset-typescript": "^8.0.1",
18
+ "@brillout/release-me": "^0.4.16",
19
+ "@rollup/plugin-babel": "^7.1.0",
19
20
  "@rollup/plugin-node-resolve": "^16.0.3",
20
21
  "@types/node": "^22.19.7",
21
22
  "babel-preset-solid": "^1.9.12",
22
- "bumpp": "^11.0.1",
23
- "rollup": "^4.60.1",
23
+ "bumpp": "^11.1.0",
24
+ "rollup": "^4.62.2",
24
25
  "rollup-plugin-dts": "^6.4.1",
25
- "solid-js": "^1.9.12",
26
+ "solid-js": "^1.9.14",
26
27
  "tslib": "^2.8.1",
27
- "typescript": "^5.9.3",
28
- "vike": "^0.4.255",
29
- "vite": "^7.3.1",
30
- "vite-plugin-solid": "^2.11.11"
28
+ "typescript": "^6.0.3",
29
+ "vike": "^0.4.260",
30
+ "vite": "^8.1.3",
31
+ "vite-plugin-solid": "^2.11.12"
31
32
  },
32
33
  "exports": {
33
34
  "./config": "./dist/+config.js",
@@ -99,8 +100,11 @@
99
100
  "dist/",
100
101
  "client.d.ts"
101
102
  ],
102
- "repository": "github:vikejs/vike-solid",
103
103
  "license": "MIT",
104
+ "keywords": [
105
+ "solid",
106
+ "solidjs"
107
+ ],
104
108
  "scripts": {
105
109
  "dev": "rollup -c rollup.config.js --watch",
106
110
  "dev:typecheck": "tsc --noEmit --watch",
@@ -1,5 +1,3 @@
1
- const configsCumulative = ["Head", "bodyAttributes", "htmlAttributes"];
2
-
3
1
  // https://stackoverflow.com/questions/56565528/typescript-const-assertions-how-to-use-array-prototype-includes/74213179#74213179
4
2
  /** Same as Array.prototype.includes() but with type inference */
5
3
  function includes(values, x) {
@@ -11,4 +9,6 @@ export function includes<Arr extends any[] | readonly any[]>(arr: Arr, el: unkno
11
9
  }
12
10
  */
13
11
 
12
+ const configsCumulative = ["Head", "bodyAttributes", "htmlAttributes"];
13
+
14
14
  export { configsCumulative as c, includes as i };