Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qual: Use config interface merging #12

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"cross-fetch": "^3.1.8",
"node-fetch": "^3.3.2",
"solid-js": "^1.7.11",
"vite-plugin-ssr": "^0.4.136",
"vike-solid": "workspace:*"
"vike-solid": "workspace:*",
"vite-plugin-ssr": "^0.4.141"
},
"devDependencies": {
"typescript": "^5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/pages/+config.h.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from "vike-solid";
import type { Config } from "vite-plugin-ssr/types";
import vikeSolid from "vike-solid";
import Layout from "../layouts/LayoutDefault";
import Head from "./Head";
Expand Down
3 changes: 2 additions & 1 deletion examples/ssr-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"dependencies": {
"solid-js": "^1.7.11",
"vike-solid": "workspace:*"
"vike-solid": "workspace:*",
"vite-plugin-ssr": "^0.4.141"
},
"devDependencies": {
"typescript": "^5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion examples/ssr-spa/pages/+config.h.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from "vike-solid";
import type { Config } from "vite-plugin-ssr/types";
import vikeSolid from "vike-solid";
import Layout from "../layouts/LayoutDefault";
import Head from "./Head";
Expand Down
2 changes: 1 addition & 1 deletion examples/ssr-spa/pages/spa/+config.h.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from "vike-solid";
import type { Config } from "vite-plugin-ssr/types";

export default {
ssr: false, // SPA
Expand Down
33 changes: 18 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vike-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"peerDependencies": {
"solid-js": "^1.7.11",
"vite-plugin-ssr": "^0.4.136"
"vite-plugin-ssr": "^0.4.141"
},
"devDependencies": {
"@babel/core": "^7.22.10",
Expand All @@ -36,7 +36,7 @@
"solid-js": "^1.7.11",
"tslib": "^2.6.1",
"typescript": "^5.1.6",
"vite-plugin-ssr": "^0.4.136"
"vite-plugin-ssr": "^0.4.141"
},
"typesVersions": {
"*": {
Expand Down
71 changes: 37 additions & 34 deletions vike-solid/renderer/+config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
import type { Config as ConfigCore } from "vite-plugin-ssr/types";
import type { Component } from "./types.js";

import type { Effect } from "vite-plugin-ssr/types";

export type Config = ConfigCore & {
/** Solid element renderer and appended into <head></head> */
Head?: Component;
Layout?: Component;
title?: string;
description?: string;
/**
* @default 'en'
*/
lang?: string;
/**
* If true, render mode is SSR or pre-rendering (aka SSG). In other words, the
* page's HTML will be rendered at build-time or request-time.
* If false, render mode is SPA. In other words, the page will only be
* rendered in the browser.
*
* See https://vite-plugin-ssr.com/render-modes
*
* @default true
*
*/
ssr?: boolean;
Page?: Component;
};

// alias
export type UserConfig = Config;
import type { Config, ConfigEffect } from "vite-plugin-ssr/types";

// Depending on the value of `config.meta.ssr`, set other config options' `env`
// accordingly.
// See https://vite-plugin-ssr.com/meta#modify-existing-configurations
const toggleSsrRelatedConfig: Effect = ({ configDefinedAt, configValue }) => {
const toggleSsrRelatedConfig: ConfigEffect = ({
configDefinedAt,
configValue,
}) => {
if (typeof configValue !== "boolean") {
throw new Error(`${configDefinedAt} should be a boolean`);
}
Expand Down Expand Up @@ -80,4 +52,35 @@ export default {
effect: toggleSsrRelatedConfig,
},
},
} satisfies ConfigCore;
} satisfies Config;

// 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'`
import type { Component } from "./types.js";
declare global {
namespace VikePackages {
export interface ConfigVikeSolid {
/** Solid element renderer and appended into <head></head> */
Head?: Component;
Layout?: Component;
title?: string;
description?: string;
/**
* @default 'en'
*/
lang?: string;
/**
* If true, render mode is SSR or pre-rendering (aka SSG). In other words, the
* page's HTML will be rendered at build-time or request-time.
* If false, render mode is SPA. In other words, the page will only be
* rendered in the browser.
*
* See https://vite-plugin-ssr.com/render-modes
*
* @default true
*
*/
ssr?: boolean;
Page?: Component;
}
}
}
8 changes: 2 additions & 6 deletions vike-solid/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export type { PageProps };
export type { Page };

import type {
PageContextBuiltIn,
PageContextBuiltInServer,
PageContextBuiltInClientWithClientRouting as PageContextBuiltInClient,
} from "vite-plugin-ssr/types";
import type { Config } from "./+config";
import type { JSX } from "solid-js";

export type { Component } from "solid-js";
Expand All @@ -26,9 +25,6 @@ export type PageContextCommon = {
};
};

type PageContextServer = PageContextBuiltIn<Page> &
PageContextCommon & {
config: Partial<Config>;
};
type PageContextServer = PageContextBuiltInServer<Page> & PageContextCommon;
type PageContextClient = PageContextBuiltInClient<Page> & PageContextCommon;
type PageContext = PageContextClient | PageContextServer;