Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-dancers-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a case where some font families would not be downloaded when using the same font provider several times, using the experimental fonts API
10 changes: 5 additions & 5 deletions packages/astro/src/assets/fonts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ export function familiesToUnifontProviders({
}),
),
);
if (hashes.has(hash)) {
continue;
}
Comment on lines -336 to -338
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here. Isn't the logic here unchanged? If the hash isn't in the hashes set, add the hash to the set and push the provider into the list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes is that provider.name is always updated now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't get that it was mutating the providers you were passing in

// Makes sure every font uses the right instance of a given provider
// if this provider is provided several times with different options
// We have to mutate the unifont provider name because unifont deduplicates
Expand All @@ -344,8 +341,11 @@ export function familiesToUnifontProviders({
// We set the provider name so we can tell unifont what provider to use when
// resolving font faces
provider.name = unifontProvider._name;
hashes.add(hash);
providers.push(unifontProvider);

if (!hashes.has(hash)) {
hashes.add(hash);
providers.push(unifontProvider);
}
}

return { families, providers };
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/units/assets/fonts/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe('fonts utils', () => {
assert.equal(result.providers.length, length);
},
/**
* @param {Array<string | undefined>} names
* @param {Array<string>} names
*/
assertProvidersNames: (names) => {
assert.deepStrictEqual(
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('fonts utils', () => {
},
]);
fixture.assertProvidersLength(1);
fixture.assertProvidersNames(['test-{"name":"test"}', undefined]);
fixture.assertProvidersNames(['test-{"name":"test"}', 'test-{"name":"test"}']);
});

it('deduplicates providers with the same config', () => {
Expand All @@ -504,7 +504,7 @@ describe('fonts utils', () => {
},
]);
fixture.assertProvidersLength(1);
fixture.assertProvidersNames(['test-{"name":"test","x":"y"}', undefined]);
fixture.assertProvidersNames(['test-{"name":"test","x":"y"}', 'test-{"name":"test","x":"y"}']);
});

it('does not deduplicate providers with different configs', () => {
Expand Down