Skip to content

Commit d48149f

Browse files
authored
fix: handle invalid or unknown properties (#4151)
Fixes the issue with non existent "before" and "after" https://discord.com/channels/955905230107738152/1286696101076009031/1286696101076009031
1 parent adf473b commit d48149f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

apps/builder/app/shared/style-object-model.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,32 @@ test("fallback cascaded value to inherited computed value", () => {
843843
).toEqual({ type: "keyword", value: "currentColor" });
844844
});
845845

846+
test("work with unknown or invalid properties", () => {
847+
const model = createModel({
848+
css: `
849+
bodyLocal {
850+
unknown-property: [object Object];
851+
}
852+
`,
853+
jsx: <$.Body ws:id="body" class="bodyLocal"></$.Body>,
854+
});
855+
const instanceSelector = ["body"];
856+
expect(
857+
getComputedStyleDecl({
858+
model,
859+
instanceSelector,
860+
property: "unknownProperty",
861+
}).usedValue
862+
).toEqual({ type: "unparsed", value: "[object Object]" });
863+
expect(
864+
getComputedStyleDecl({
865+
model,
866+
instanceSelector,
867+
property: "undefinedProperty",
868+
}).usedValue
869+
).toEqual({ type: "invalid", value: "" });
870+
});
871+
846872
describe("selected style", () => {
847873
test("access selected style source value within cascade", () => {
848874
const model = createModel({

apps/builder/app/shared/style-object-model.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ const customPropertyData = {
236236
initial: guaranteedInvalidValue,
237237
};
238238

239+
const invalidPropertyData = {
240+
inherited: false,
241+
initial: invalidValue,
242+
};
243+
239244
export type ComputedStyleDecl = {
240245
property: string;
241246
source: StyleValueSource;
@@ -269,7 +274,7 @@ export const getComputedStyleDecl = ({
269274
const isCustomProperty = property.startsWith("--");
270275
const propertyData = isCustomProperty
271276
? customPropertyData
272-
: properties[property as keyof typeof properties];
277+
: (properties[property as keyof typeof properties] ?? invalidPropertyData);
273278
const inherited = propertyData.inherited;
274279
const initialValue: StyleValue = propertyData.initial;
275280
let computedValue: StyleValue = initialValue;

0 commit comments

Comments
 (0)