Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

dedupe family, render same family assets as multiple src

Oleg Isonen913cf52b8616
diff --git a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
index d0e1b9fe70..dee3bb088d 100644
--- a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
+++ b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx
@@ -11,15 +11,14 @@ import { SYSTEM_FONTS } from "@webstudio-is/fonts";
const getItems = (assets: Array<Asset | PreviewAsset>) => {
const system = SYSTEM_FONTS.map((item) => ({ label: item.family }));
-
- const uploaded = assets.map((asset) => ({
- label:
- "meta" in asset && "family" in asset.meta
- ? asset.meta.family
- : asset.name,
- }));
-
- return [...system, ...uploaded];
+ // We can have 2+ assets with the same family name, so we use a map to dedupe.
+ const uploaded = new Map();
+ for (const asset of assets) {
+ if ("meta" in asset && "family" in asset.meta) {
+ uploaded.set(asset.meta.family, { label: asset.meta.family });
+ }
+ }
+ return [...system, ...uploaded.values()];
};
type FontsManagerProps = {
diff --git a/apps/designer/app/routes/designer/_assets.tsx b/apps/designer/app/routes/designer/_assets.tsx
index 2752311e52..32d379bedd 100644
--- a/apps/designer/app/routes/designer/_assets.tsx
+++ b/apps/designer/app/routes/designer/_assets.tsx
@@ -4,7 +4,6 @@
import { ActionFunction } from "@remix-run/node";
import { useActionData } from "@remix-run/react";
-import { captureException } from "@sentry/remix";
import {
deleteAsset,
uploadAssets,
diff --git a/packages/fonts/src/get-font-faces.ts b/packages/fonts/src/get-font-faces.ts
index f17a94400c..c14d0c5a4a 100644
--- a/packages/fonts/src/get-font-faces.ts
+++ b/packages/fonts/src/get-font-faces.ts
@@ -1,17 +1,28 @@
import { FONT_FORMATS } from "./constants";
import type { FontMeta } from "./schema";
+import type { FontFormat } from "./types";
export const getFontFaces = (
- fontAssets: Array<{ format: string; meta: FontMeta; path: string }>
+ assets: Array<{ format: string; meta: FontMeta; path: string }>
) => {
- return fontAssets.map((asset) => {
- const format = FONT_FORMATS[asset.format as keyof typeof FONT_FORMATS];
- return {
- fontFamily: asset.meta.family,
- fontStyle: asset.meta.style,
- fontWeight: asset.meta.weight,
- fontDisplay: "swap" as const,
- src: `url('${asset.path}') format('${format}')`,
- };
- });
+ const faces = new Map();
+ for (const asset of assets) {
+ const face = faces.get(asset.meta.family);
+ const format = FONT_FORMATS[asset.format as FontFormat];
+
+ if (face === undefined) {
+ faces.set(asset.meta.family, {
+ fontFamily: asset.meta.family,
+ fontStyle: asset.meta.style,
+ fontWeight: asset.meta.weight,
+ fontDisplay: "swap" as const,
+ src: `url('${asset.path}') format('${format}')`,
+ });
+ continue;
+ }
+
+ // We already have that font face, so we need to add the new src
+ face.src += `, url('${asset.path}') format('${format}')`;
+ }
+ return Array.from(faces.values());
};