mirror of
https://github.com/withastro/astro.git
synced 2025-01-22 10:31:53 -05:00
fix: experimental svg types (#12625)
* fix: experimental svg types * apply suggestion
This commit is contained in:
parent
348c71ecdc
commit
74bfad07af
4 changed files with 48 additions and 38 deletions
5
.changeset/rare-cooks-battle.md
Normal file
5
.changeset/rare-cooks-battle.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue where the `experimental.svg` had incorrect type, resulting in some errors in the editors.
|
|
@ -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;
|
||||
}),
|
||||
|
|
|
@ -1940,28 +1940,30 @@ 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?: {
|
||||
/**
|
||||
*
|
||||
* @name experimental.svg.mode
|
||||
* @type {string}
|
||||
* @default 'inline'
|
||||
*
|
||||
* The default technique for handling imported SVG files. Astro will inline the SVG content into your HTML output if not specified.
|
||||
*
|
||||
* - `inline`: Astro will inline the SVG content into your HTML output.
|
||||
* - `sprite`: Astro will generate a sprite sheet with all imported SVG files.
|
||||
*
|
||||
* ```astro
|
||||
* ---
|
||||
* import Logo from './path/to/svg/file.svg';
|
||||
* ---
|
||||
*
|
||||
* <Logo size={24} mode="sprite" />
|
||||
* ```
|
||||
*/
|
||||
mode?: SvgRenderMode;
|
||||
};
|
||||
svg?:
|
||||
| boolean
|
||||
| {
|
||||
/**
|
||||
*
|
||||
* @name experimental.svg.mode
|
||||
* @type {string}
|
||||
* @default 'inline'
|
||||
*
|
||||
* The default technique for handling imported SVG files. Astro will inline the SVG content into your HTML output if not specified.
|
||||
*
|
||||
* - `inline`: Astro will inline the SVG content into your HTML output.
|
||||
* - `sprite`: Astro will generate a sprite sheet with all imported SVG files.
|
||||
*
|
||||
* ```astro
|
||||
* ---
|
||||
* import Logo from './path/to/svg/file.svg';
|
||||
* ---
|
||||
*
|
||||
* <Logo size={24} mode="sprite" />
|
||||
* ```
|
||||
*/
|
||||
mode: SvgRenderMode;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in a new issue