Skip to content

Commit 654c134

Browse files
authored
fix: fix unknown font family support (#4136)
## Description Last pr introduced a regression when font family is used that isn't in the stakcs ## Steps for reproduction 1. type a random font family 2. expect it to land in the dom ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 7889513 commit 654c134

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/css-engine/src/core/to-value.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("Convert WS CSS Values to native CSS strings", () => {
4646
expect(value).toBe("var(--namespace, normal, 10px)");
4747
});
4848

49-
test("fontFamily", () => {
49+
test("fontFamily stack", () => {
5050
expect(
5151
toValue({
5252
type: "fontFamily",
@@ -57,6 +57,15 @@ describe("Convert WS CSS Values to native CSS strings", () => {
5757
);
5858
});
5959

60+
test("fontFamily unknown", () => {
61+
expect(
62+
toValue({
63+
type: "fontFamily",
64+
value: ["something-random"],
65+
})
66+
).toBe("something-random, sans-serif");
67+
});
68+
6069
test("Transform font family value to override default fallback", () => {
6170
const value = toValue(
6271
{

packages/css-engine/src/core/to-value.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type TransformValue = (styleValue: StyleValue) => undefined | StyleValue;
77
const fallbackTransform: TransformValue = (styleValue) => {
88
if (styleValue.type === "fontFamily") {
99
const fonts = SYSTEM_FONTS.get(styleValue.value[0])?.stack ?? [
10+
styleValue.value[0],
1011
DEFAULT_FONT_FALLBACK,
1112
];
1213
const value = Array.from(new Set(fonts));

0 commit comments

Comments
 (0)