Skip to content

Commit

Permalink
fix: experimental svg types (#12625)
Browse files Browse the repository at this point in the history
* fix: experimental svg types

* apply suggestion
  • Loading branch information
ematipico authored Dec 4, 2024
1 parent 348c71e commit 74bfad0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-cooks-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where the `experimental.svg` had incorrect type, resulting in some errors in the editors.
29 changes: 19 additions & 10 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 } };

Expand Down Expand Up @@ -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;
}),
Expand Down
46 changes: 24 additions & 22 deletions packages/astro/src/types/public/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}

Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

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

0 comments on commit 74bfad0

Please sign in to comment.