Repository: withastro/astro
File: packages/astro/src/assets/fonts/load.ts (TypeScript)

Code before:

		// When going through the urls/filepaths returned by providers,
		// We save the hash and the associated original value so we can use
		// it in the vite middleware during development
		const collect: (
			parameters: Parameters<ProxyURLOptions['collect']>[0] & {
				data: Partial<unifont.FontFaceData>;
			},
			collectPreload: boolean,
		) => ReturnType<ProxyURLOptions['collect']> = ({ hash, type, value, data }, collectPreload) => {
			const url = base + hash;
			if (!hashToUrlMap.has(hash)) {
				hashToUrlMap.set(hash, value);
				if (collectPreload) {
					preloadData.push({ url, type });
				}
			}
			// If a family has fallbacks, we store the first url we get that may
			// be used for the fallback generation, if capsize doesn't have this
			// family in its built-in collection
			if (
				fallbacks &&
				fallbacks.length > 0 &&
				// If the same data has already been sent for this family, we don't want to have duplicate fallbacks
				// Such scenario can occur with unicode ranges
				!fallbackFontData.some((f) => JSON.stringify(f) === JSON.stringify(data))
			) {
				fallbackFontData.push({
					hash,
					url: value,
					data,
				});
			}
			return url;
		};

		let fonts: Array<unifont.FontFaceData>;

		if (family.provider === LOCAL_PROVIDER_NAME) {
			const result = resolveLocalFont({
				family,
				proxyURL: ({ value, data }) => {
					return proxyURL({
						value,
						// We hash based on the filepath and the contents, since the user could replace
						// a given font file with completely different contents.
						hashString: (v) => {
							let content: string;
							try {
								content = readFileSync(value, 'utf-8');
							} catch (e) {

Review comment (suggestion):
```suggestion
				!fallbackFontData.some((f) => JSON.stringify(f.data) === JSON.stringify(data))
```

Code after:

		// When going through the urls/filepaths returned by providers,
		// We save the hash and the associated original value so we can use
		// it in the vite middleware during development
		const collect: (
			parameters: Parameters<ProxyURLOptions['collect']>[0] & {
				data: Partial<unifont.FontFaceData>;
			},
			collectPreload: boolean,
		) => ReturnType<ProxyURLOptions['collect']> = ({ hash, type, value, data }, collectPreload) => {
			const url = base + hash;
			if (!hashToUrlMap.has(hash)) {
				hashToUrlMap.set(hash, value);
				if (collectPreload) {
					preloadData.push({ url, type });
				}
			}
			// If a family has fallbacks, we store the first url we get that may
			// be used for the fallback generation
			if (
				fallbacks &&
				fallbacks.length > 0 &&
				// If the same data has already been sent for this family, we don't want to have duplicate fallbacks
				// Such scenario can occur with unicode ranges
				!fallbackFontData.some((f) => JSON.stringify(f.data) === JSON.stringify(data))
			) {
				fallbackFontData.push({
					hash,
					url: value,
					data,
				});
			}
			return url;
		};

		let fonts: Array<unifont.FontFaceData>;

		if (family.provider === LOCAL_PROVIDER_NAME) {
			const result = resolveLocalFont({
				family,
				proxyURL: ({ value, data }) => {
					return proxyURL({
						value,
						// We hash based on the filepath and the contents, since the user could replace
						// a given font file with completely different contents.
						hashString: (v) => {
							let content: string;
							try {
								content = readFileSync(value, 'utf-8');
							} catch (e) {
								throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: e });