vike-solid 0.7.14 → 0.7.16

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
@@ -29,7 +29,22 @@ declare const _default: {
29
29
  onRenderClient: "import:vike-solid/__internal/integration/onRenderClient:onRenderClient";
30
30
  clientRouting: true;
31
31
  hydrationCanBeAborted: true;
32
- passToClient: string[];
32
+ passToClient: "_configFromHook"[];
33
+ staticReplace: {
34
+ env: "server";
35
+ filter: string;
36
+ type: "call";
37
+ match: {
38
+ function: string;
39
+ args: {
40
+ 0: string;
41
+ };
42
+ };
43
+ remove: {
44
+ arg: number;
45
+ prop: string;
46
+ };
47
+ }[];
33
48
  meta: {
34
49
  Head: {
35
50
  env: {
package/dist/+config.js CHANGED
@@ -22,7 +22,7 @@ function ssrEffect({
22
22
  var _config = {
23
23
  name: "vike-solid",
24
24
  require: {
25
- vike: ">=0.4.195"
25
+ vike: ">=0.4.250"
26
26
  },
27
27
  vite: {
28
28
  ssr: {
@@ -39,6 +39,21 @@ var _config = {
39
39
  clientRouting: true,
40
40
  hydrationCanBeAborted: true,
41
41
  passToClient: ["_configFromHook"],
42
+ staticReplace: [{
43
+ env: "server",
44
+ filter: "vike-solid/ClientOnly",
45
+ type: "call",
46
+ match: {
47
+ function: "import:solid-js/web:createComponent",
48
+ args: {
49
+ 0: "import:vike-solid/ClientOnly:ClientOnly"
50
+ }
51
+ },
52
+ remove: {
53
+ arg: 1,
54
+ prop: "children"
55
+ }
56
+ }],
42
57
  // https://vike.dev/meta
43
58
  meta: {
44
59
  Head: {
@@ -0,0 +1,15 @@
1
+ import { JSX } from 'solid-js';
2
+
3
+ /**
4
+ * Render children only on the client-side.
5
+ *
6
+ * Children are completely removed and never loaded on the server.
7
+ *
8
+ * https://vike.dev/ClientOnly
9
+ */
10
+ declare function ClientOnly(props: {
11
+ children?: JSX.Element;
12
+ fallback?: JSX.Element;
13
+ }): JSX.Element;
14
+
15
+ export { ClientOnly };
@@ -0,0 +1,40 @@
1
+ import { createComponent } from 'solid-js/web';
2
+ import { Show, children } from 'solid-js';
3
+ import { useHydrated } from '../hooks/useHydrated.js';
4
+ import { usePageContext } from '../hooks/usePageContext.js';
5
+
6
+ function assert(condition) {
7
+ if (condition) return;
8
+ throw new Error("You stumbled upon a vike-solid bug, reach out on GitHub.");
9
+ }
10
+
11
+ /**
12
+ * Render children only on the client-side.
13
+ *
14
+ * Children are completely removed and never loaded on the server.
15
+ *
16
+ * https://vike.dev/ClientOnly
17
+ */
18
+ function ClientOnly(props) {
19
+ const pageContext = usePageContext();
20
+
21
+ // Assert tree-shaking: children should be statically removed on the server-side
22
+ if (!pageContext.isClientSide) {
23
+ // eslint-disable-next-line solid/reactivity
24
+ assert(props.children === undefined);
25
+ }
26
+ const hydrated = useHydrated();
27
+ return createComponent(Show, {
28
+ get when() {
29
+ return hydrated();
30
+ },
31
+ get fallback() {
32
+ return props.fallback;
33
+ },
34
+ get children() {
35
+ return children(() => props.children)();
36
+ }
37
+ });
38
+ }
39
+
40
+ export { ClientOnly };
@@ -1,6 +1,10 @@
1
1
  import { createSignal, splitProps, sharedConfig, onMount, createMemo, untrack } from 'solid-js';
2
2
  import { isServer } from 'solid-js/web';
3
3
 
4
+ // TODO/soon: add deprecation warning in favor of <ClientOnly>
5
+ // TO-DO/breaking-change: remove it
6
+
7
+
4
8
  // Copied from https://github.com/solidjs/solid-start/blob/2d75d5fedfd11f739b03ca34decf23865868ac09/packages/start/src/shared/clientOnly.tsx#L7
5
9
  /**
6
10
  * Load and render a component only on the client-side.
@@ -0,0 +1,22 @@
1
+ import { Accessor } from 'solid-js';
2
+
3
+ /**
4
+ * Whether the page has already been hydrated.
5
+ *
6
+ * On the server, it always returns `false`. On the client, it returns `false` on first render and `true` after hydration completes.
7
+ *
8
+ * https://vike.dev/useHydrated
9
+ *
10
+ * Example: Disable a button that needs JavaScript to work.
11
+ * ```tsx
12
+ * const hydrated = useHydrated();
13
+ * return (
14
+ * <button type="button" disabled={!hydrated()} onClick={doSomething}>
15
+ * Click me
16
+ * </button>
17
+ * );
18
+ * ```
19
+ */
20
+ declare function useHydrated(): Accessor<boolean>;
21
+
22
+ export { useHydrated };
@@ -0,0 +1,33 @@
1
+ import { createSignal, onMount } from 'solid-js';
2
+ import { usePageContext } from './usePageContext.js';
3
+ import 'solid-js/web';
4
+
5
+ /**
6
+ * Whether the page has already been hydrated.
7
+ *
8
+ * On the server, it always returns `false`. On the client, it returns `false` on first render and `true` after hydration completes.
9
+ *
10
+ * https://vike.dev/useHydrated
11
+ *
12
+ * Example: Disable a button that needs JavaScript to work.
13
+ * ```tsx
14
+ * const hydrated = useHydrated();
15
+ * return (
16
+ * <button type="button" disabled={!hydrated()} onClick={doSomething}>
17
+ * Click me
18
+ * </button>
19
+ * );
20
+ * ```
21
+ */
22
+ function useHydrated() {
23
+ const pageContext = usePageContext();
24
+ const [hydrated, setHydrated] = createSignal(pageContext.isClientSide && !pageContext.isHydration);
25
+ if (pageContext.isClientSide && pageContext.isHydration) {
26
+ onMount(() => {
27
+ setHydrated(true);
28
+ });
29
+ }
30
+ return hydrated;
31
+ }
32
+
33
+ export { useHydrated };
@@ -11,8 +11,9 @@ function overrideConfig() {
11
11
  })
12
12
  };
13
13
  }
14
+ // Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
14
15
  function vitePluginVikeSolid (options = {}) {
15
- return [solidPlugin(mergeConfig({
16
+ const plugins = [solidPlugin(mergeConfig({
16
17
  ssr: true,
17
18
  typescript: {
18
19
  onlyRemoveTypeImports: true
@@ -21,6 +22,7 @@ function vitePluginVikeSolid (options = {}) {
21
22
  hydratable: true
22
23
  }
23
24
  }, options ?? {})), overrideConfig()];
25
+ return plugins;
24
26
  }
25
27
 
26
28
  export { vitePluginVikeSolid as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-solid",
3
- "version": "0.7.14",
3
+ "version": "0.7.16",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "isbot-fast": "^1.2.0",
@@ -8,8 +8,7 @@
8
8
  },
9
9
  "peerDependencies": {
10
10
  "solid-js": "^1.8.7",
11
- "vike": ">=0.4.195",
12
- "vite": ">=5.0.0"
11
+ "vike": ">=0.4.250"
13
12
  },
14
13
  "devDependencies": {
15
14
  "@babel/core": "^7.28.5",
@@ -26,13 +25,14 @@
26
25
  "solid-js": "^1.9.10",
27
26
  "tslib": "^2.8.1",
28
27
  "typescript": "^5.9.3",
29
- "vike": "^0.4.249",
28
+ "vike": "^0.4.250",
30
29
  "vite": "^7.2.7"
31
30
  },
32
31
  "exports": {
33
32
  "./config": "./dist/+config.js",
34
33
  "./vite": "./dist/vite-plugin-vike-solid.js",
35
34
  "./usePageContext": "./dist/hooks/usePageContext.js",
35
+ "./useHydrated": "./dist/hooks/useHydrated.js",
36
36
  "./useData": "./dist/hooks/useData.js",
37
37
  "./useConfig": {
38
38
  "browser": "./dist/hooks/useConfig/useConfig-client.js",
@@ -47,6 +47,7 @@
47
47
  "default": "./dist/components/Head/Head-server.js"
48
48
  },
49
49
  "./clientOnly": "./dist/helpers/clientOnly.js",
50
+ "./ClientOnly": "./dist/components/ClientOnly.js",
50
51
  "./__internal/integration/onRenderHtml": "./dist/integration/onRenderHtml.js",
51
52
  "./__internal/integration/onRenderClient": "./dist/integration/onRenderClient.js",
52
53
  "./client": {
@@ -67,6 +68,9 @@
67
68
  "usePageContext": [
68
69
  "dist/hooks/usePageContext.d.ts"
69
70
  ],
71
+ "useHydrated": [
72
+ "dist/hooks/useHydrated.d.ts"
73
+ ],
70
74
  "useData": [
71
75
  "dist/hooks/useData.d.ts"
72
76
  ],
@@ -81,6 +85,9 @@
81
85
  ],
82
86
  "clientOnly": [
83
87
  "dist/helpers/clientOnly.d.ts"
88
+ ],
89
+ "ClientOnly": [
90
+ "dist/components/ClientOnly.d.ts"
84
91
  ]
85
92
  }
86
93
  },