diff --git a/.changeset/brave-baboons-talk.md b/.changeset/brave-baboons-talk.md
new file mode 100644
index 000000000..fb31c265e
--- /dev/null
+++ b/.changeset/brave-baboons-talk.md
@@ -0,0 +1,5 @@
+---
+"@solidjs/start": patch
+---
+
+Rework `@solidjs/start/env`
diff --git a/apps/fixtures/bare/src/global.d.ts b/apps/fixtures/bare/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/bare/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/bare/tsconfig.json b/apps/fixtures/bare/tsconfig.json
index 4ea27f698..411ce3ba8 100644
--- a/apps/fixtures/bare/tsconfig.json
+++ b/apps/fixtures/bare/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/basic/src/global.d.ts b/apps/fixtures/basic/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/basic/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/basic/tsconfig.json b/apps/fixtures/basic/tsconfig.json
index 4ea27f698..411ce3ba8 100644
--- a/apps/fixtures/basic/tsconfig.json
+++ b/apps/fixtures/basic/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/css/src/global.d.ts b/apps/fixtures/css/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/css/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/css/tsconfig.json b/apps/fixtures/css/tsconfig.json
index 1f0bda6da..e4bb71b1e 100644
--- a/apps/fixtures/css/tsconfig.json
+++ b/apps/fixtures/css/tsconfig.json
@@ -12,8 +12,8 @@
"noEmit": true,
"isolatedModules": true,
"paths": {
- "~/*": ["./src/*"]
+ "~/*": ["./src/*"],
},
- "types": ["vite/client"]
- }
+ "types": ["@solidjs/start/env"],
+ },
}
diff --git a/apps/fixtures/experiments/src/global.d.ts b/apps/fixtures/experiments/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/experiments/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/experiments/tsconfig.json b/apps/fixtures/experiments/tsconfig.json
index b9f69f64a..411ce3ba8 100644
--- a/apps/fixtures/experiments/tsconfig.json
+++ b/apps/fixtures/experiments/tsconfig.json
@@ -11,9 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
- "types": ["vite/client"],
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/hackernews/src/global.d.ts b/apps/fixtures/hackernews/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/hackernews/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/hackernews/tsconfig.json b/apps/fixtures/hackernews/tsconfig.json
index 4ea27f698..411ce3ba8 100644
--- a/apps/fixtures/hackernews/tsconfig.json
+++ b/apps/fixtures/hackernews/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/nitro-3/src/global.d.ts b/apps/fixtures/nitro-3/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/nitro-3/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/nitro-3/tsconfig.json b/apps/fixtures/nitro-3/tsconfig.json
index 26b08446a..434f11a9f 100644
--- a/apps/fixtures/nitro-3/tsconfig.json
+++ b/apps/fixtures/nitro-3/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/notes/src/global.d.ts b/apps/fixtures/notes/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/fixtures/notes/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/fixtures/notes/tsconfig.json b/apps/fixtures/notes/tsconfig.json
index 4ea27f698..411ce3ba8 100644
--- a/apps/fixtures/notes/tsconfig.json
+++ b/apps/fixtures/notes/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/fixtures/todomvc/src/global.d.ts b/apps/fixtures/todomvc/src/global.d.ts
deleted file mode 100644
index 0682c3c14..000000000
--- a/apps/fixtures/todomvc/src/global.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-declare module App {
- interface RequestEventLocals {
- /**
- * Declare your getRequestEvent().locals here
- */
- }
-}
diff --git a/apps/fixtures/todomvc/tsconfig.json b/apps/fixtures/todomvc/tsconfig.json
index 4ea27f698..411ce3ba8 100644
--- a/apps/fixtures/todomvc/tsconfig.json
+++ b/apps/fixtures/todomvc/tsconfig.json
@@ -11,8 +11,9 @@
"strict": true,
"noEmit": true,
"isolatedModules": true,
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/landing-page/src/global.d.ts b/apps/landing-page/src/global.d.ts
index c7e166948..3b0dd1dd2 100644
--- a/apps/landing-page/src/global.d.ts
+++ b/apps/landing-page/src/global.d.ts
@@ -1,5 +1,3 @@
-///
-
import { Session, User } from "lucia";
import { lucia } from "./db/auth";
diff --git a/apps/landing-page/tsconfig.json b/apps/landing-page/tsconfig.json
index efcfe7f66..c95b9e538 100644
--- a/apps/landing-page/tsconfig.json
+++ b/apps/landing-page/tsconfig.json
@@ -8,8 +8,9 @@
"jsxImportSource": "solid-js",
"jsx": "preserve",
"baseUrl": "./",
+ "types": ["@solidjs/start/env"],
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/apps/tests/src/global.d.ts b/apps/tests/src/global.d.ts
deleted file mode 100644
index dc6f10c22..000000000
--- a/apps/tests/src/global.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/apps/tests/tsconfig.json b/apps/tests/tsconfig.json
index 72133a12d..376a974e4 100644
--- a/apps/tests/tsconfig.json
+++ b/apps/tests/tsconfig.json
@@ -10,10 +10,10 @@
"allowJs": true,
"strict": true,
"noEmit": true,
- "types": ["vitest/globals", "@testing-library/jest-dom"],
+ "types": ["vitest/globals", "@testing-library/jest-dom", "@solidjs/start/env"],
"isolatedModules": true,
"paths": {
- "~/*": ["./src/*"]
- }
- }
+ "~/*": ["./src/*"],
+ },
+ },
}
diff --git a/packages/start-nitro-v2-vite-plugin/tsconfig.json b/packages/start-nitro-v2-vite-plugin/tsconfig.json
index 93ff01e43..9a394befc 100644
--- a/packages/start-nitro-v2-vite-plugin/tsconfig.json
+++ b/packages/start-nitro-v2-vite-plugin/tsconfig.json
@@ -17,7 +17,7 @@
"types": ["vite/client"],
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
- "rootDir": "./src"
+ "rootDir": "./src",
},
- "include": ["./src", "./src/env.d.ts"]
+ "include": ["./src", "./src/env.d.ts"],
}
diff --git a/packages/start/env.d.ts b/packages/start/env.d.ts
new file mode 100644
index 000000000..2c9155d1c
--- /dev/null
+++ b/packages/start/env.d.ts
@@ -0,0 +1,9 @@
+// This file contains global type definitions that are exported as @solidjs/start/env
+
+///
+
+declare namespace App {
+ export interface RequestEventLocals {
+ [key: string | symbol]: any;
+ }
+}
diff --git a/packages/start/package.json b/packages/start/package.json
index 82caf790e..79a129894 100644
--- a/packages/start/package.json
+++ b/packages/start/package.json
@@ -18,7 +18,8 @@
"./server/spa": "./src/server/spa/index.tsx",
"./client/spa": "./src/client/spa/index.tsx",
"./middleware": "./src/middleware/index.ts",
- "./http": "./src/http/index.ts"
+ "./http": "./src/http/index.ts",
+ "./env": "./env.d.ts"
},
"publishConfig": {
"access": "public",
@@ -31,7 +32,8 @@
"./server/spa": "./dist/server/spa/index.jsx",
"./client/spa": "./dist/client/spa/index.jsx",
"./middleware": "./dist/middleware/index.js",
- "./http": "./dist/http/index.js"
+ "./http": "./dist/http/index.js",
+ "./env": "./env.d.ts"
}
},
"dependencies": {
diff --git a/packages/start/src/client/mount.ts b/packages/start/src/client/mount.ts
index 744e759a9..7e17df7c7 100644
--- a/packages/start/src/client/mount.ts
+++ b/packages/start/src/client/mount.ts
@@ -1,114 +1 @@
-import type { JSX } from "solid-js";
-import { createStore } from "solid-js/store";
-import {
- createComponent,
- getHydrationKey,
- getOwner,
- hydrate,
- type MountableElement,
-} from "solid-js/web";
-
-/**
- *
- * Read more: https://docs.solidjs.com/solid-start/reference/client/mount
- */
-export function mount(fn: () => JSX.Element, el: MountableElement) {
- if (import.meta.env.START_ISLANDS) {
- const map = new WeakMap();
- async function mountIsland(el: HTMLElement) {
- if (el.dataset.css) {
- let css = JSON.parse(el.dataset.css);
- for (let href of css) {
- if (!document.querySelector(`link[href="${href}"]`)) {
- let link = document.createElement("link");
- link.rel = "stylesheet";
- link.href = href;
- document.head.appendChild(link);
- }
- }
- }
-
- let mod = await import(
- /* @vite-ignore */
- import.meta.env.MANIFEST["client"]!.chunks[el.dataset.id!.split("#")[0] as string]!.output
- .path
- );
- if (!mod || !el.dataset.hk) return;
-
- let Component = mod[el.dataset.id!.split("#")[1] as string];
- let hk = el.dataset.hk;
- // _$DEBUG("hydrating island", el.dataset.island, hk.slice(0, hk.length - 1) + `1-`, el);
-
- let props = createStore({
- ...JSON.parse(el.dataset.props!),
- get children() {
- const p = el.getElementsByTagName("solid-children");
- getHydrationKey();
- [...p].forEach(a => {
- (a as any).__$owner = getOwner();
- });
- return;
- },
- });
-
- map.set(el, props);
-
- hydrate(() => createComponent(Component, props[0]), el, {
- renderId: hk.slice(0, hk.length - 1) + `${1 + Number(el.dataset.offset)}-`,
- owner: lookupOwner(el),
- });
-
- delete el.dataset.hk;
- el.dataset.hkk = hk;
- }
-
- let queue: HTMLElement[] = [];
- let queued = false;
- function runTaskQueue(info: any) {
- while (info.timeRemaining() > 0 && queue.length) {
- mountIsland(queue.shift()!);
- }
- if (queue.length) {
- requestIdleCallback(runTaskQueue);
- } else queued = false;
- }
-
- const hydrateIslands = () => {
- const islands: NodeListOf = document.querySelectorAll("solid-island[data-hk]");
- const assets = new Set();
- islands.forEach((el: HTMLElement) => el.dataset.id && assets.add(el.dataset.id));
- Promise.all(
- [...assets].map(
- asset =>
- import(
- /* @vite-ignore */ import.meta.env.MANIFEST["client"]!.chunks[
- asset.split("#")[0] as string
- ]!.output.path
- ),
- ),
- )
- .then(() => {
- islands.forEach((el: HTMLElement) => {
- if (el.dataset.when === "idle" && "requestIdleCallback" in window) {
- if (!queued) {
- queued = true;
- requestIdleCallback(runTaskQueue);
- }
- queue.push(el);
- } else mountIsland(el as HTMLElement);
- });
- })
- .catch(e => console.error(e));
- };
-
- function lookupOwner(el: HTMLElement) {
- const parent = el.closest("solid-children");
- return parent && (parent as any).__$owner;
- }
-
- hydrateIslands();
-
- return;
- }
- return hydrate(fn, el);
-}
+export { hydrate as mount } from "solid-js/web"
diff --git a/packages/start/src/config/index.ts b/packages/start/src/config/index.ts
index 39a1d0afd..2523f2b6d 100644
--- a/packages/start/src/config/index.ts
+++ b/packages/start/src/config/index.ts
@@ -56,9 +56,6 @@ export function solidStart(options?: SolidStartOptions): Array {
enforce: "pre",
configEnvironment(name) {
return {
- define: {
- "import.meta.env.SSR": JSON.stringify(name === VITE_ENVIRONMENTS.server),
- },
resolve: {
// remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
externalConditions: ["solid", "node"],
diff --git a/packages/start/src/env.d.ts b/packages/start/src/env.d.ts
index a2c99e4fb..fad2a39ab 100644
--- a/packages/start/src/env.d.ts
+++ b/packages/start/src/env.d.ts
@@ -1,33 +1,17 @@
-// This file is an augmentation to the built-in ImportMeta interface
-// Thus cannot contain any top-level imports
-//
-
-/* eslint-disable @typescript-eslint/consistent-type-imports */
-
-declare namespace App {
- export interface RequestEventLocals {
- [key: string | symbol]: any;
- }
-}
+// This file contains global type definitions that are internal to SolidStart and are not exported
declare module "solidstart:server-fn-manifest" {
type ServerFn = (...args: Array) => Promise;
export function getServerFnById(id: string): Promise;
}
-interface ImportMetaEnv extends Record<`VITE_${string}`, any>, SolidStartMetaEnv {
- BASE_URL: string;
- MODE: string;
- DEV: boolean;
- PROD: boolean;
- SSR: boolean;
-}
+interface ImportMetaEnv extends SolidStartMetaEnv {}
interface SolidStartMetaEnv {
START_SSR: boolean;
START_APP_ENTRY: string;
START_CLIENT_ENTRY: string;
- // START_ISLANDS: boolean;
+ START_ISLANDS: boolean;
// START_DEV_OVERLAY: boolean;
// SERVER_BASE_URL: string;
}
diff --git a/packages/start/src/server/handler.ts b/packages/start/src/server/handler.ts
index 333ad60f4..d91453d93 100644
--- a/packages/start/src/server/handler.ts
+++ b/packages/start/src/server/handler.ts
@@ -71,7 +71,7 @@ export function createBaseHandler(
const html = renderToString(() => {
(sharedConfig.context as any).event = context;
return fn(context);
- });
+ }, resolvedOptions);
context.complete = true;
if (context.response && context.response.headers.get("Location")) {
diff --git a/packages/start/tsconfig.json b/packages/start/tsconfig.json
index 6eb9ea069..f0939803d 100644
--- a/packages/start/tsconfig.json
+++ b/packages/start/tsconfig.json
@@ -17,7 +17,7 @@
"types": ["vite/client"],
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
- "rootDir": "./src"
+ "rootDir": "./src",
},
- "include": ["./src", "./src/env.d.ts"]
+ "include": ["env.d.ts", "./src", "./src/env.d.ts"],
}