fix: experimental svg types (#12625)

* fix: experimental svg types

* apply suggestion
This commit is contained in:
Emanuele Stoppa 2024-12-04 15:38:50 +00:00 committed by GitHub
parent 348c71ecdc
commit 74bfad07af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 38 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue where the `experimental.svg` had incorrect type, resulting in some errors in the editors.

View file

@ -11,6 +11,7 @@ import type { OutgoingHttpHeaders } from 'node:http';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { z } from 'zod';
import type { SvgRenderMode } from '../../assets/utils/svg.js';
import { EnvSchema } from '../../env/schema.js';
import type { AstroUserConfig, ViteUserConfig } from '../../types/public/config.js';
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js';
@ -96,9 +97,7 @@ export const ASTRO_CONFIG_DEFAULTS = {
clientPrerender: false,
contentIntellisense: false,
responsiveImages: false,
svg: {
mode: 'inline',
},
svg: false,
},
} satisfies AstroUserConfig & { server: { open: boolean } };
@ -540,18 +539,28 @@ export const AstroConfigSchema = z.object({
svg: z
.union([
z.boolean(),
z.object({
mode: z
.union([z.literal('inline'), z.literal('sprite')])
.optional()
.default(ASTRO_CONFIG_DEFAULTS.experimental.svg.mode),
}),
z
.object({
mode: z.union([z.literal('inline'), z.literal('sprite')]).optional(),
})
.optional(),
])
.optional()
.default(ASTRO_CONFIG_DEFAULTS.experimental.svg)
.transform((svgConfig) => {
// Handle normalization of `experimental.svg` config boolean values
if (typeof svgConfig === 'boolean') {
return svgConfig ? ASTRO_CONFIG_DEFAULTS.experimental.svg : undefined;
return svgConfig
? {
mode: 'inline' as SvgRenderMode,
}
: undefined;
} else {
if (!svgConfig.mode) {
return {
mode: 'inline' as SvgRenderMode,
};
}
}
return svgConfig;
}),

View file

@ -1940,7 +1940,9 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
* For a complete overview, and to give feedback on this experimental API,
* see the [Feature RFC](https://github.com/withastro/roadmap/pull/1035).
*/
svg?: {
svg?:
| boolean
| {
/**
*
* @name experimental.svg.mode
@ -1960,7 +1962,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
* <Logo size={24} mode="sprite" />
* ```
*/
mode?: SvgRenderMode;
mode: SvgRenderMode;
};
};
}

View file

@ -968,12 +968,6 @@ importers:
specifier: ^18.3.1
version: 18.3.1(react@18.3.1)
packages/astro/e2e/fixtures/custom-renderer:
dependencies:
astro:
specifier: workspace:*
version: link:../../..
packages/astro/e2e/fixtures/dev-toolbar:
dependencies:
'@astrojs/preact':