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/chatty-taxes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug where empty fallbacks could not be provided when using the experimental fonts API
2 changes: 1 addition & 1 deletion packages/astro/src/assets/fonts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const fallbacksSchema = z.object({
* If the last font in the `fallbacks` array is a [generic family name](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name), an [optimized fallback](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
*/
fallbacks: z.array(z.string()).nonempty().optional(),
fallbacks: z.array(z.string()).optional(),
/**
* @default `true`
*
Expand Down
38 changes: 37 additions & 1 deletion packages/astro/test/types/define-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it } from 'node:test';
import { expectTypeOf } from 'expect-type';
import type { AstroFontProvider, FontFamily } from '../../dist/assets/fonts/types.js';
import { defineAstroFontProvider } from '../../dist/config/entrypoint.js';
import { defineAstroFontProvider, fontProviders } from '../../dist/config/entrypoint.js';
import { defineConfig } from '../../dist/config/index.js';
import type { AstroUserConfig } from '../../dist/types/public/index.js';

Expand Down Expand Up @@ -138,4 +138,40 @@ describe('defineConfig()', () => {
},
);
});

it('Allows disabling font fallbacks', () => {
assertType(
defineConfig({
experimental: {
fonts: [
{
provider: fontProviders.google(),
name: 'Roboto',
fallbacks: [],
cssVariable: '--font-roboto',
},
],
},
}),
(config) => {
expectTypeOf(config).toEqualTypeOf<
AstroUserConfig<
never,
never,
[
{
readonly provider: {
entrypoint: string | URL;
config?: Record<string, any> | undefined;
};
readonly name: 'Roboto';
readonly fallbacks: [];
readonly cssVariable: '--font-roboto';
},
]
>
>();
},
);
});
});
18 changes: 18 additions & 0 deletions packages/astro/test/units/config/config-validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it } from 'node:test';
import { stripVTControlCharacters } from 'node:util';
import { z } from 'zod';
import { validateConfig as _validateConfig } from '../../../dist/core/config/validate.js';
import { fontProviders } from '../../../dist/assets/fonts/providers/index.js';
import { formatConfigErrorMessage } from '../../../dist/core/messages.js';
import { envField } from '../../../dist/env/config.js';

Expand Down Expand Up @@ -460,5 +461,22 @@ describe('Config Validation', () => {
}),
);
});

it('Should allow empty font fallbacks', () => {
assert.doesNotThrow(() =>
validateConfig({
experimental: {
fonts: [
{
provider: fontProviders.google(),
name: 'Roboto',
fallbacks: [],
cssVariable: '--font-roboto',
},
],
},
}),
);
});
});
});
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.