vike-solid 0.2.0 → 0.2.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/README.md CHANGED
@@ -1,12 +1,11 @@
1
- [<img src="https://avatars.githubusercontent.com/u/86403530?s=200&v=4" align="right" width="64" height="64">](https://vike.dev)
1
+ [<img src="https://vike.dev/vike-readme.svg" align="right" height="90">](https://vike.dev)
2
2
  [![npm version](https://img.shields.io/npm/v/vike-solid)](https://www.npmjs.com/package/vike-solid)
3
3
 
4
4
  # `vike-solid`
5
5
 
6
- SolidJS integration for [Vike](https://github.com/vikejs/vike/issues/736) (using the
7
- [V1 design](https://vike.dev/migration/v1-design)).
6
+ SolidJS integration for [Vike](https://github.com/vikejs/vike) (using the [V1 design](https://vike.dev/migration/v1-design)).
8
7
 
9
8
  > [!NOTE]
10
9
  > For integrations with React and Vue, see the other [`vike-*` packages](https://vike.dev/vike-packages).
11
10
 
12
- See [examples/](https://github.com/magne4000/vike-solid/tree/main/examples).
11
+ See [examples/](https://github.com/vikejs/vike-solid/tree/main/examples).
package/dist/+config.js CHANGED
@@ -1,5 +1,3 @@
1
- // We purposely define the ConfigVikeSolid interface in this file: that way we ensure it's always applied whenever the user `import vikeSolid from 'vike-solid'`
2
-
3
1
  // Depending on the value of `config.meta.ssr`, set other config options' `env`
4
2
  // accordingly.
5
3
  // See https://vike.dev/meta#modify-existing-configurations
@@ -23,8 +21,14 @@ const toggleSsrRelatedConfig = ({
23
21
  };
24
22
  };
25
23
  var _config = {
26
- onRenderHtml: "import:vike-solid/renderer/onRenderHtml",
27
- onRenderClient: "import:vike-solid/renderer/onRenderClient",
24
+ onRenderHtml: "import:vike-solid/renderer/onRenderHtml:onRenderHtml",
25
+ onRenderClient: "import:vike-solid/renderer/onRenderClient:onRenderClient",
26
+ // A page can define an onBeforeRender() hook to be run on the server, which
27
+ // can fetch data and return it as additional page context. Typically it will
28
+ // return the page's root Solid component's props and additional data that can
29
+ // be used by the renderers.
30
+ // It is a cumulative config option, so a web app using vike-solid can extend
31
+ // this list.
28
32
  passToClient: ["pageProps", "title"],
29
33
  clientRouting: true,
30
34
  hydrationCanBeAborted: true,
@@ -41,6 +45,9 @@ var _config = {
41
45
  description: {
42
46
  env: "server-only"
43
47
  },
48
+ favicon: {
49
+ env: "server-only"
50
+ },
44
51
  lang: {
45
52
  env: "server-only"
46
53
  },
@@ -51,4 +58,6 @@ var _config = {
51
58
  }
52
59
  };
53
60
 
61
+ // We purposely define the ConfigVikeSolid interface in this file: that way we ensure it's always applied whenever the user `import vikeSolid from 'vike-solid'`
62
+
54
63
  export { _config as default };
@@ -1,18 +1,21 @@
1
1
  import { createComponent, Dynamic, mergeProps, memo, hydrate, render } from 'solid-js/web';
2
- import { P as PageContextProvider, u as usePageContext } from './usePageContext-a90cda5a.js';
2
+ import { P as PageContextProvider, u as usePageContext } from './usePageContext-gFteWsFt.js';
3
3
  import { createStore, reconcile } from 'solid-js/store';
4
4
  import 'solid-js';
5
5
 
6
+ /**
7
+ * Get the page's title if defined, either from the additional data fetched by
8
+ * the page's onBeforeRender() hook or from the config.
9
+ */
6
10
  function getTitle(pageContext) {
7
- if (typeof pageContext.title === "string") {
11
+ if (pageContext.title !== undefined) {
8
12
  return pageContext.title;
9
13
  }
10
- if (pageContext.title) {
11
- throw new Error("pageContext.title should be a string");
14
+ const titleConfig = pageContext.configEntries.title?.[0];
15
+ if (!titleConfig) {
16
+ return null;
12
17
  }
13
- const {
14
- title
15
- } = pageContext.config;
18
+ const title = titleConfig.configValue;
16
19
  if (typeof title === "string") {
17
20
  return title;
18
21
  }
@@ -21,7 +24,7 @@ function getTitle(pageContext) {
21
24
  }
22
25
  const {
23
26
  configDefinedAt
24
- } = pageContext.configEntries.title[0];
27
+ } = titleConfig;
25
28
  if (typeof title === "function") {
26
29
  const val = title(pageContext);
27
30
  if (typeof val === "string") {
@@ -70,10 +73,11 @@ function Passthrough(props) {
70
73
  return memo(() => props.children);
71
74
  }
72
75
 
76
+ // https://vike.dev/onRenderClient
73
77
  const [pageContextStore, setPageContext] = createStore({});
74
78
  let dispose;
75
79
  let rendered = false;
76
- async function onRenderClient(pageContext) {
80
+ const onRenderClient = async pageContext => {
77
81
  if (!rendered) {
78
82
  // Dispose to prevent duplicate pages when navigating.
79
83
  if (dispose) dispose();
@@ -92,6 +96,6 @@ async function onRenderClient(pageContext) {
92
96
  if (title !== null) {
93
97
  document.title = title;
94
98
  }
95
- }
99
+ };
96
100
 
97
- export { onRenderClient as default };
101
+ export { onRenderClient };
@@ -1,18 +1,21 @@
1
1
  import { createComponent, Dynamic, mergeProps, renderToString, renderToStream, generateHydrationScript } from 'solid-js/web';
2
2
  import { escapeInject, stampPipe, dangerouslySkipEscape } from 'vike/server';
3
- import { P as PageContextProvider, u as usePageContext } from './usePageContext-a90cda5a.js';
3
+ import { P as PageContextProvider, u as usePageContext } from './usePageContext-gFteWsFt.js';
4
4
  import 'solid-js';
5
5
 
6
+ /**
7
+ * Get the page's title if defined, either from the additional data fetched by
8
+ * the page's onBeforeRender() hook or from the config.
9
+ */
6
10
  function getTitle(pageContext) {
7
- if (typeof pageContext.title === "string") {
11
+ if (pageContext.title !== undefined) {
8
12
  return pageContext.title;
9
13
  }
10
- if (pageContext.title) {
11
- throw new Error("pageContext.title should be a string");
14
+ const titleConfig = pageContext.configEntries.title?.[0];
15
+ if (!titleConfig) {
16
+ return null;
12
17
  }
13
- const {
14
- title
15
- } = pageContext.config;
18
+ const title = titleConfig.configValue;
16
19
  if (typeof title === "string") {
17
20
  return title;
18
21
  }
@@ -21,7 +24,7 @@ function getTitle(pageContext) {
21
24
  }
22
25
  const {
23
26
  configDefinedAt
24
- } = pageContext.configEntries.title[0];
27
+ } = titleConfig;
25
28
  if (typeof title === "function") {
26
29
  const val = title(pageContext);
27
30
  if (typeof val === "string") {
@@ -70,7 +73,7 @@ function Passthrough(props) {
70
73
  return props.children;
71
74
  }
72
75
 
73
- async function onRenderHtml(pageContext) {
76
+ const onRenderHtml = async pageContext => {
74
77
  const title = getTitle(pageContext);
75
78
  const titleTag = !title ? "" : escapeInject`<title>${title}</title>`;
76
79
  const {
@@ -84,6 +87,8 @@ async function onRenderHtml(pageContext) {
84
87
  return createComponent(Head, {});
85
88
  }
86
89
  }));
90
+ const favicon = pageContext.config.favicon;
91
+ const faviconTag = !favicon ? '' : escapeInject`<link rel="icon" href="${favicon}" />`;
87
92
  const {
88
93
  pipe
89
94
  } = renderToStream(() => !pageContext.Page ? [] // the ssr config flag is false
@@ -96,6 +101,7 @@ async function onRenderHtml(pageContext) {
96
101
  <head>
97
102
  <meta charset="UTF-8" />
98
103
  ${titleTag}
104
+ ${faviconTag}
99
105
  ${descriptionTag}
100
106
  ${dangerouslySkipEscape(headHtml)}
101
107
  ${dangerouslySkipEscape(generateHydrationScript())}
@@ -104,9 +110,7 @@ async function onRenderHtml(pageContext) {
104
110
  <div id="page-view">${pipe}</div>
105
111
  </body>
106
112
  </html>`;
107
- return {
108
- documentHtml
109
- };
110
- }
113
+ return documentHtml;
114
+ };
111
115
 
112
- export { onRenderHtml as default };
116
+ export { onRenderHtml };
@@ -1,5 +1,5 @@
1
1
  import { build } from 'vite';
2
- import { c as config } from './vite.config-2b9e1d28.js';
2
+ import { c as config } from './vite.config-xLAJ7-PR.js';
3
3
  import 'vite-plugin-solid';
4
4
  import 'vike/plugin';
5
5
 
@@ -1,42 +1,6 @@
1
- import * as vike_dist_esm_shared_types from 'vike/dist/esm/shared/types';
2
- import * as vike_dist_esm_shared_addUrlComputedProps from 'vike/dist/esm/shared/addUrlComputedProps';
3
- import * as vike_dist_esm_shared_getPageFiles_getExports from 'vike/dist/esm/shared/getPageFiles/getExports';
4
- import * as vike_dist_esm_shared_page_configs_Config_PageContextConfig from 'vike/dist/esm/shared/page-configs/Config/PageContextConfig';
1
+ import { PageContext } from 'vike/types';
5
2
 
6
3
  /** Access the pageContext from any SolidJS component */
7
- declare function usePageContext(): (Partial<{
8
- Page: unknown;
9
- routeParams: Record<string, string>;
10
- config: vike_dist_esm_shared_page_configs_Config_PageContextConfig.PageContextConfig;
11
- configEntries: vike_dist_esm_shared_getPageFiles_getExports.ConfigEntries;
12
- exports: Record<string, unknown>;
13
- exportsAll: vike_dist_esm_shared_getPageFiles_getExports.ExportsAll;
14
- urlOriginal: string;
15
- is404: boolean | null;
16
- isClientSideNavigation: boolean;
17
- abortReason?: unknown;
18
- abortStatusCode?: undefined;
19
- errorWhileRendering?: unknown;
20
- url: string;
21
- pageExports: Record<string, unknown>;
22
- }> & Pick<{
23
- Page: unknown;
24
- routeParams: Record<string, string>;
25
- config: vike_dist_esm_shared_page_configs_Config_PageContextConfig.PageContextConfig;
26
- configEntries: vike_dist_esm_shared_getPageFiles_getExports.ConfigEntries;
27
- exports: Record<string, unknown>;
28
- exportsAll: vike_dist_esm_shared_getPageFiles_getExports.ExportsAll;
29
- urlOriginal: string;
30
- is404: boolean | null;
31
- isClientSideNavigation: boolean;
32
- abortReason?: unknown;
33
- abortStatusCode?: undefined;
34
- errorWhileRendering?: unknown;
35
- url: string;
36
- pageExports: Record<string, unknown>;
37
- }, "Page" | "pageExports" | "config" | "configEntries" | "exports" | "exportsAll" | "abortReason"> & {
38
- isHydration: boolean;
39
- isBackwardNavigation: boolean | null;
40
- } & vike_dist_esm_shared_addUrlComputedProps.PageContextUrlComputedPropsClient & Vike.PageContext) | vike_dist_esm_shared_types.PageContextServer;
4
+ declare function usePageContext(): PageContext;
41
5
 
42
6
  export { usePageContext };
@@ -1,5 +1,5 @@
1
1
  import { createServer } from 'vite';
2
- import { c as config } from './vite.config-2b9e1d28.js';
2
+ import { c as config } from './vite.config-xLAJ7-PR.js';
3
3
  import 'vite-plugin-solid';
4
4
  import 'vike/plugin';
5
5
 
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@ const cmd = parseCliArgs();
3
3
  cli();
4
4
  async function cli() {
5
5
  if (cmd === "dev") {
6
- await import('./dev-dfbf584d.js');
6
+ await import('./dev-WJHjvirM.js');
7
7
  }
8
8
  if (cmd === "build") {
9
- await import('./build-4b79b655.js');
9
+ await import('./build-CLDbE5Ld.js');
10
10
  }
11
11
  if (cmd === "preview") {
12
- await import('./preview-535a0307.js');
12
+ await import('./preview-Bir7ASwQ.js');
13
13
  }
14
14
  }
15
15
  function parseCliArgs() {
@@ -1,5 +1,5 @@
1
1
  import { preview } from 'vite';
2
- import { c as config } from './vite.config-2b9e1d28.js';
2
+ import { c as config } from './vite.config-xLAJ7-PR.js';
3
3
  import 'vite-plugin-solid';
4
4
  import 'vike/plugin';
5
5
 
@@ -6,16 +6,18 @@ type PageProps = Record<string, unknown>;
6
6
  declare global {
7
7
  namespace Vike {
8
8
  interface PageContext {
9
- Page: Page;
10
- pageProps: Record<string, unknown>;
9
+ Page?: Page;
10
+ /** Properties of the page's root Solid component. */
11
+ pageProps?: Record<string, unknown>;
12
+ /** &lt;title>${title}&lt;/title> - has precedence over the config */
11
13
  title?: string;
12
14
  }
13
15
  }
14
16
  }
15
17
 
16
18
  declare const _default: {
17
- onRenderHtml: "import:vike-solid/renderer/onRenderHtml";
18
- onRenderClient: "import:vike-solid/renderer/onRenderClient";
19
+ onRenderHtml: "import:vike-solid/renderer/onRenderHtml:onRenderHtml";
20
+ onRenderClient: "import:vike-solid/renderer/onRenderClient:onRenderClient";
19
21
  passToClient: string[];
20
22
  clientRouting: true;
21
23
  hydrationCanBeAborted: true;
@@ -32,6 +34,9 @@ declare const _default: {
32
34
  description: {
33
35
  env: "server-only";
34
36
  };
37
+ favicon: {
38
+ env: "server-only";
39
+ };
35
40
  lang: {
36
41
  env: "server-only";
37
42
  };
@@ -50,6 +55,7 @@ declare global {
50
55
  Layout?: Component;
51
56
  title?: string | ((pageContext: PageContext) => string);
52
57
  description?: string;
58
+ favicon?: string;
53
59
  /**
54
60
  * @default 'en'
55
61
  */
@@ -1,3 +1,3 @@
1
- export { u as usePageContext } from './usePageContext-a90cda5a.js';
1
+ export { u as usePageContext } from './usePageContext-gFteWsFt.js';
2
2
  import 'solid-js/web';
3
3
  import 'solid-js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-solid",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/+config.js",
@@ -10,29 +10,29 @@
10
10
  "./renderer/onRenderClient": "./dist/+onRenderClient.js"
11
11
  },
12
12
  "dependencies": {
13
- "vite-plugin-solid": "^2.7.0"
13
+ "vite-plugin-solid": "^2.7.2"
14
14
  },
15
15
  "peerDependencies": {
16
- "solid-js": "^1.7.12",
17
- "vite": "^4.4.9",
18
- "vike": "^0.4.142"
16
+ "solid-js": "^1.8.3",
17
+ "vite": "^4.5.0",
18
+ "vike": "^0.4.144"
19
19
  },
20
20
  "devDependencies": {
21
- "@babel/core": "^7.22.20",
22
- "@babel/preset-env": "^7.22.20",
23
- "@babel/preset-typescript": "^7.22.15",
24
- "@rollup/plugin-babel": "^6.0.3",
25
- "@rollup/plugin-node-resolve": "^15.2.1",
21
+ "@babel/core": "^7.23.2",
22
+ "@babel/preset-env": "^7.23.2",
23
+ "@babel/preset-typescript": "^7.23.2",
24
+ "@rollup/plugin-babel": "^6.0.4",
25
+ "@rollup/plugin-node-resolve": "^15.2.3",
26
26
  "@types/node": "^18.17.4",
27
- "babel-preset-solid": "^1.7.12",
27
+ "babel-preset-solid": "^1.8.2",
28
28
  "bumpp": "^9.2.0",
29
- "rollup": "^3.29.2",
30
- "rollup-plugin-dts": "^6.0.2",
31
- "solid-js": "^1.7.12",
29
+ "rollup": "^4.1.4",
30
+ "rollup-plugin-dts": "^6.1.0",
31
+ "solid-js": "^1.8.3",
32
32
  "tslib": "^2.6.2",
33
33
  "typescript": "^5.2.2",
34
- "vite": "^4.4.9",
35
- "vike": "^0.4.142"
34
+ "vite": "^4.5.0",
35
+ "vike": "^0.4.144"
36
36
  },
37
37
  "typesVersions": {
38
38
  "*": {
@@ -57,7 +57,7 @@
57
57
  "bin": "./cli/entry.js",
58
58
  "main": "dist/+config.js",
59
59
  "types": "dist/renderer/+config.d.ts",
60
- "repository": "github:magne4000/vike-solid",
60
+ "repository": "github:vikejs/vike-solid",
61
61
  "license": "MIT",
62
62
  "scripts": {
63
63
  "dev": "rollup -c rollup.config.js --watch",