Skip to content

Commit 8fbda55

Browse files
authored
fix: autocomplete properties with invalid values (#5118)
The logic assumed invalid values should become custom properties. Here replaced that heuristic with property name check. <img width="294" alt="Screenshot 2025-04-11 at 19 11 54" src="https://github.com/user-attachments/assets/d2f08fbf-93ab-47c6-a075-3f4d311cc718" />
1 parent 2366abe commit 8fbda55

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ describe("parseStyleInput", () => {
8787
new Map([["color", { type: "keyword", value: "red" }]])
8888
);
8989
});
90+
91+
test("output property with invalid value", () => {
92+
const result = parseStyleInput("rotate: z 0;");
93+
expect(result).toEqual(
94+
new Map([["rotate", { type: "invalid", value: "z 0" }]])
95+
);
96+
});
9097
});

apps/builder/app/builder/shared/css-editor/parse-style-input.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,20 @@ const ensureValue = (css: string) => {
4343
*/
4444
export const parseStyleInput = (css: string): CssStyleMap => {
4545
css = ensureValue(css);
46-
4746
const styles = parseCss(`selector{${css}}`);
48-
4947
const styleMap: CssStyleMap = new Map();
50-
5148
for (const { property, value } of styles) {
49+
if (property.startsWith("--")) {
50+
styleMap.set(property, value);
51+
continue;
52+
}
5253
// somethingunknown: red; -> --somethingunknown: red;
53-
if (
54-
// Note: currently in tests it returns unparsed, but in the client it returns invalid,
55-
// because we use native APIs when available in parseCss.
56-
value.type === "invalid" ||
57-
(value.type === "unparsed" && property.startsWith("--") === false)
58-
) {
54+
if (propertiesData[property] === undefined) {
5955
styleMap.set(`--${property}`, value);
60-
} else {
61-
// @todo This should be returning { type: "guaranteedInvalid" }
62-
styleMap.set(property, value);
56+
continue;
6357
}
58+
// @todo This should be returning { type: "guaranteedInvalid" }
59+
styleMap.set(property, value);
6460
}
6561
return styleMap;
6662
};

0 commit comments

Comments
 (0)