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

fix: experimental svg types #12625

merged 2 commits into from
Dec 4, 2024

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Dec 4, 2024

Changes

Closes #12626

This PR fixes an issue where experimental.svg had incorrect types.

The previous types allowed having an empty object {} but it failed with a boolean value, which how we document it.

This was reported on Discord: https://discord.com/channels/830184174198718474/1313850696126431263

Testing

There was a failing test, which is now fixed

Docs

Copy link

changeset-bot bot commented Dec 4, 2024

🦋 Changeset detected

Latest commit: 7c0a1b4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Dec 4, 2024
@@ -22,7 +22,7 @@ export type SvgRenderMode = 'inline' | 'sprite';
export function makeSvgComponent(
meta: ImageMetadata,
contents: Buffer | string,
options?: { mode?: SvgRenderMode },
options?: { mode: 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.

Having an optional mode should be a bug. Users should either provide a boolean, or provide an object with explicit mode

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

@@ -4,6 +4,6 @@ import { defineConfig } from 'astro/config';
export default defineConfig({
integrations: [mdx()],
experimental: {
svg: {}
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 way of passing the option shouldn't be valid

Copy link
Member

Choose a reason for hiding this comment

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

IIUC passing {} is like passing true. Couldn't we support {} without specifying mode too? It feels to me futureproofing if it ever has more optional options in the object, so you don't have to specify mode always.

Copy link
Member Author

@ematipico ematipico Dec 4, 2024

Choose a reason for hiding this comment

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

We can do everything, but what does svg: {} even mean to the user and to us? I don't want to be pedantic, I'll see what I can do

Copy link
Member Author

Choose a reason for hiding this comment

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

I applied the change in 26c65f2 (#12625) and tested that svg: {} is still a valid configuration

Copy link
Member

Choose a reason for hiding this comment

The 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 {} only.

Copy link

codspeed-hq bot commented Dec 4, 2024

CodSpeed Performance Report

Merging #12625 will degrade performances by 21.79%

Comparing chore/svg-experimental-type (7c0a1b4) with main (b073014)

Summary

❌ 1 regressions
✅ 5 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main chore/svg-experimental-type Change
Rendering: streaming [false], .mdx file 868.9 ms 1,111 ms -21.79%

@ematipico ematipico requested a review from bluwy December 4, 2024 15:18
@ematipico ematipico force-pushed the chore/svg-experimental-type branch from 26c65f2 to 7c0a1b4 Compare December 4, 2024 15:21
@ematipico ematipico merged commit 74bfad0 into main Dec 4, 2024
16 of 17 checks passed
@ematipico ematipico deleted the chore/svg-experimental-type branch December 4, 2024 15:38
@astrobot-houston astrobot-houston mentioned this pull request Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SVG Component Not Working
3 participants