Skip to content

Commit c2ed103

Browse files
committed
fix: pre-bundle the dev toolbar's CommonJS dependencies
1 parent bf589cb commit c2ed103

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

.changeset/olive-donkeys-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
Pre-bundle the dev toolbar's CommonJS dependencies so it no longer throws on every dev page load
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
import type { Plugin } from "vite";
5+
import { afterEach, expect, it } from "vitest";
6+
7+
import { solidStart, type SolidStartOptions } from "./index.ts";
8+
9+
const cwd = process.cwd();
10+
const roots: string[] = [];
11+
12+
afterEach(() => {
13+
process.chdir(cwd);
14+
for (const root of roots.splice(0)) rmSync(root, { recursive: true });
15+
});
16+
17+
async function resolveDevConfig(options?: SolidStartOptions) {
18+
const root = realpathSync.native(mkdtempSync(join(tmpdir(), "solid-start-dev-toolbar-deps-")));
19+
roots.push(root);
20+
mkdirSync(join(root, "src"));
21+
writeFileSync(join(root, "package.json"), "{}");
22+
writeFileSync(join(root, "src/app.tsx"), "export default function App() {}");
23+
process.chdir(root);
24+
25+
const plugin = solidStart(options).find(
26+
(candidate): candidate is Plugin =>
27+
typeof candidate === "object" &&
28+
candidate !== null &&
29+
"name" in candidate &&
30+
candidate.name === "solid-start:config",
31+
);
32+
const config = plugin?.config;
33+
const handler = typeof config === "function" ? config : config?.handler;
34+
return (await handler?.call({} as never, {}, { command: "serve", mode: "development" })) as
35+
| { environments?: { client?: { optimizeDeps?: { include?: string[] } } } }
36+
| undefined;
37+
}
38+
39+
it("pre-bundles the dev toolbar's CommonJS dependencies", async () => {
40+
const config = await resolveDevConfig();
41+
42+
expect(config?.environments?.client?.optimizeDeps?.include).toEqual([
43+
"@solidjs/start > source-map-js",
44+
"@solidjs/start > error-stack-parser",
45+
]);
46+
});
47+
48+
it("leaves them alone when the dev toolbar is disabled", async () => {
49+
const config = await resolveDevConfig({ devOverlay: false });
50+
51+
expect(config?.environments?.client?.optimizeDeps).toBeUndefined();
52+
});

packages/start/src/config/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ export interface SolidStartOptions {
199199
};
200200
}
201201

202+
const DEV_TOOLBAR_COMMONJS_DEPENDENCIES = [
203+
"@solidjs/start > source-map-js",
204+
"@solidjs/start > error-stack-parser",
205+
];
206+
202207
const absolute = (path: string, root: string) =>
203208
path ? (isAbsolute(path) ? path : join(root, path)) : path;
204209

@@ -291,6 +296,9 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
291296
environments: {
292297
[VITE_ENVIRONMENTS.client]: {
293298
consumer: "client",
299+
...(start.devOverlay
300+
? { optimizeDeps: { include: DEV_TOOLBAR_COMMONJS_DEPENDENCIES } }
301+
: {}),
294302
build: {
295303
write: true,
296304
manifest: true,

0 commit comments

Comments
 (0)