Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/devtools-css-in-prod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Stop the dev toolbar's CSS from shipping in production builds. The error boundary statically imports the dev toolbar, whose module imports its stylesheet as a side effect. The toolbar is dead code in production, but the stylesheet survived because the package declared no `sideEffects`, so its styles were bundled into the client CSS. The package now marks only CSS files as having side effects, letting the bundler drop the toolbar and its styles from production output.
23 changes: 23 additions & 0 deletions apps/tests/src/routes/treeshaking/devtools-css.server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { getBuildOutputDirs, getFiles, readFileContent } from "~/utils/build-output-utils";

// Regression test for https://github.com/solidjs/solid-start/issues/2327.
// ErrorBoundary statically imports the dev toolbar, whose module imports its
// CSS as a side effect. The toolbar branch is dead code in production, so the
// "sideEffects" field in @solidjs/start lets the bundler drop the module and
// its CSS. Without it, the toolbar styles leak into the client bundle.
describe("dev toolbar is excluded from the production bundle", () => {
it("does not ship the dev toolbar CSS to the client", async () => {
const { clientOutputRoot } = getBuildOutputDirs();
const files = await getFiles(clientOutputRoot, /\.css(\.gz|\.br)?$/);

expect(files.length, "No client CSS files found").toBeGreaterThan(0);

for (const targetFile of files) {
const css = await readFileContent(targetFile);
expect(css, `Dev toolbar CSS leaked into: ${targetFile}`).not.toContain(
"data-start-dev-toolbar",
);
}
});
});
3 changes: 3 additions & 0 deletions packages/start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"CHANGELOG.md"
],
"type": "module",
"sideEffects": [
"**/*.css"
],
"exports": {
".": "./src/index.tsx",
"./config": "./dist/config/index.js",
Expand Down
Loading