Skip to content

Commit 74bfad0

Browse files
authored
fix: experimental svg types (withastro#12625)
* fix: experimental svg types * apply suggestion
1 parent 348c71e commit 74bfad0

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

.changeset/rare-cooks-battle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an issue where the `experimental.svg` had incorrect type, resulting in some errors in the editors.

packages/astro/src/core/config/schema.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { OutgoingHttpHeaders } from 'node:http';
1111
import path from 'node:path';
1212
import { fileURLToPath, pathToFileURL } from 'node:url';
1313
import { z } from 'zod';
14+
import type { SvgRenderMode } from '../../assets/utils/svg.js';
1415
import { EnvSchema } from '../../env/schema.js';
1516
import type { AstroUserConfig, ViteUserConfig } from '../../types/public/config.js';
1617
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js';
@@ -96,9 +97,7 @@ export const ASTRO_CONFIG_DEFAULTS = {
9697
clientPrerender: false,
9798
contentIntellisense: false,
9899
responsiveImages: false,
99-
svg: {
100-
mode: 'inline',
101-
},
100+
svg: false,
102101
},
103102
} satisfies AstroUserConfig & { server: { open: boolean } };
104103

@@ -540,18 +539,28 @@ export const AstroConfigSchema = z.object({
540539
svg: z
541540
.union([
542541
z.boolean(),
543-
z.object({
544-
mode: z
545-
.union([z.literal('inline'), z.literal('sprite')])
546-
.optional()
547-
.default(ASTRO_CONFIG_DEFAULTS.experimental.svg.mode),
548-
}),
542+
z
543+
.object({
544+
mode: z.union([z.literal('inline'), z.literal('sprite')]).optional(),
545+
})
546+
.optional(),
549547
])
550548
.optional()
549+
.default(ASTRO_CONFIG_DEFAULTS.experimental.svg)
551550
.transform((svgConfig) => {
552551
// Handle normalization of `experimental.svg` config boolean values
553552
if (typeof svgConfig === 'boolean') {
554-
return svgConfig ? ASTRO_CONFIG_DEFAULTS.experimental.svg : undefined;
553+
return svgConfig
554+
? {
555+
mode: 'inline' as SvgRenderMode,
556+
}
557+
: undefined;
558+
} else {
559+
if (!svgConfig.mode) {
560+
return {
561+
mode: 'inline' as SvgRenderMode,
562+
};
563+
}
555564
}
556565
return svgConfig;
557566
}),

packages/astro/src/types/public/config.ts

+24-22
Original file line numberDiff line numberDiff line change
@@ -1940,28 +1940,30 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
19401940
* For a complete overview, and to give feedback on this experimental API,
19411941
* see the [Feature RFC](https://github.com/withastro/roadmap/pull/1035).
19421942
*/
1943-
svg?: {
1944-
/**
1945-
*
1946-
* @name experimental.svg.mode
1947-
* @type {string}
1948-
* @default 'inline'
1949-
*
1950-
* The default technique for handling imported SVG files. Astro will inline the SVG content into your HTML output if not specified.
1951-
*
1952-
* - `inline`: Astro will inline the SVG content into your HTML output.
1953-
* - `sprite`: Astro will generate a sprite sheet with all imported SVG files.
1954-
*
1955-
* ```astro
1956-
* ---
1957-
* import Logo from './path/to/svg/file.svg';
1958-
* ---
1959-
*
1960-
* <Logo size={24} mode="sprite" />
1961-
* ```
1962-
*/
1963-
mode?: SvgRenderMode;
1964-
};
1943+
svg?:
1944+
| boolean
1945+
| {
1946+
/**
1947+
*
1948+
* @name experimental.svg.mode
1949+
* @type {string}
1950+
* @default 'inline'
1951+
*
1952+
* The default technique for handling imported SVG files. Astro will inline the SVG content into your HTML output if not specified.
1953+
*
1954+
* - `inline`: Astro will inline the SVG content into your HTML output.
1955+
* - `sprite`: Astro will generate a sprite sheet with all imported SVG files.
1956+
*
1957+
* ```astro
1958+
* ---
1959+
* import Logo from './path/to/svg/file.svg';
1960+
* ---
1961+
*
1962+
* <Logo size={24} mode="sprite" />
1963+
* ```
1964+
*/
1965+
mode: SvgRenderMode;
1966+
};
19651967
};
19661968
}
19671969

pnpm-lock.yaml

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)