Skip to content

Commit 925ea10

Browse files
authored
feat: avoid generating unused preset styles (#5121)
Now we have first-class support for html tags and able to figure out which tags are rendered so unused preset styles can be removed from websites. For example ``` <Box ws:tag="div"> <Box ws:tag="span"> </Box> </Box> ``` will render only div.w-box and span.w-box though there are more presets for for other tags like main, section etc. Before all tags were generated
1 parent 6151138 commit 925ea10

File tree

12 files changed

+171
-424
lines changed

12 files changed

+171
-424
lines changed

apps/builder/app/shared/copy-paste.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "./instance-utils";
2929
import { $project } from "./nano-states";
3030
import { findAvailableVariables } from "./data-variables";
31+
import { camelCaseProperty } from "@webstudio-is/css-data";
3132

3233
$project.set({ id: "current_project" } as Project);
3334

@@ -83,8 +84,14 @@ const insertStyles = ({
8384
styleSourceId: string;
8485
style: TemplateStyleDecl[];
8586
}) => {
86-
for (const styleDecl of style) {
87-
const newStyleDecl = { breakpointId, styleSourceId, ...styleDecl };
87+
for (const { state, property, value } of style) {
88+
const newStyleDecl = {
89+
breakpointId,
90+
styleSourceId,
91+
state,
92+
property: camelCaseProperty(property),
93+
value,
94+
};
8895
data.styles.set(getStyleDeclKey(newStyleDecl), newStyleDecl);
8996
}
9097
};

fixtures/react-router-docker/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-netlify/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-vercel/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/ssg-netlify-by-project-id/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/ssg/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/webstudio-cloudflare-template/app/__generated__/index.css

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)