Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: experimental svg types #12625

Merged
merged 2 commits into from
Dec 4, 2024
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/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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast make TS happy

}
: 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.

Loading