-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix: experimental svg types #12625
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } }; | ||
|
||
|
@@ -541,17 +540,19 @@ export const AstroConfigSchema = z.object({ | |
.union([ | ||
z.boolean(), | ||
z.object({ | ||
mode: z | ||
.union([z.literal('inline'), z.literal('sprite')]) | ||
.optional() | ||
.default(ASTRO_CONFIG_DEFAULTS.experimental.svg.mode), | ||
mode: z.union([z.literal('inline'), z.literal('sprite')]), | ||
}), | ||
]) | ||
.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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cast make TS happy |
||
} | ||
: undefined; | ||
} | ||
return svgConfig; | ||
}), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ import { defineConfig } from 'astro/config'; | |
export default defineConfig({ | ||
integrations: [mdx()], | ||
experimental: { | ||
svg: {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way of passing the option shouldn't be valid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do everything, but what does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I applied the change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't mean a lot currently, but it's futureproofing if we add more options to it in the future, so I think it's an ok tradeoff for now as long as we don't recommend people to enable with |
||
svg: true | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having an optional
mode
should be a bug. Users should either provide a boolean, or provide an object with explicitmode