Skip to content

feat(types): add SvgComponent type and update SVG module declaration #13651

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ADTC
Copy link
Contributor

@ADTC ADTC commented Apr 18, 2025

Changes

Testing

No tests needed, I think?

Docs

Docs will need to mention that the SvgComponent component is available for use, similar to the mentions of other types like ImageMetadata.

/cc @withastro/maintainers-docs for feedback!

Copy link

changeset-bot bot commented Apr 18, 2025

🦋 Changeset detected

Latest commit: bddf04c

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 semver: minor Change triggers a `minor` release labels Apr 18, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@ADTC
Copy link
Contributor Author

ADTC commented Apr 18, 2025

Should this be minor or patch? @florian-lefebvre I was going by the semver definitions ("add [new] functionality") when I chose minor:

MAJOR version when you make incompatible API changes
MINOR version when you add functionality in a backward compatible manner
PATCH version when you make backward compatible bug fixes

But we can change it to patch if desired.

@@ -1,3 +1,4 @@
import type * as astroHTML from 'astro/jsx-runtime';
Copy link
Member

Choose a reason for hiding this comment

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

@Princesseuh do you think this import could have weird TS implications? IIRC its always a bit tricky to import this one (at least in userland)

Copy link
Member

Choose a reason for hiding this comment

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

Can we import the type from the actual file @florian-lefebvre ?

Copy link
Member

Choose a reason for hiding this comment

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

That's what I'm looking at atm but it's tricky because it's only in a namespace inside a dts

Copy link
Member

Choose a reason for hiding this comment

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

So one way is to do import '../../astro-jsx.d.ts'; (or using a triple slash reference) but then it overrides other type definitions, eg.

error TS5055: Cannot write file '/home/florian/Documents/github/withastro/astro/packages/astro/dist/transitions/events.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/home/florian/Documents/github/withastro/astro/packages/astro/dist/transitions/types.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/home/florian/Documents/github/withastro/astro/packages/astro/dist/type-utils.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/home/florian/Documents/github/withastro/astro/packages/astro/dist/types/public/elements.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/home/florian/Documents/github/withastro/astro/packages/astro/dist/types/public/view-transitions.d.ts' because it would overwrite input file.

Copy link
Member

Choose a reason for hiding this comment

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

instead of exporting the type from here, personally I'd export it directly in client.d.ts, where it's trivial to import from astro-jsx without bundling issues

Copy link
Member

Choose a reason for hiding this comment

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

We want the type to be used in *.svg but also to be exported from "astro". Would that be doable in client.d.ts without making the type global?

Copy link
Member

Choose a reason for hiding this comment

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

ah in which case I think maybe it's fine that way

Copy link
Contributor Author

@ADTC ADTC Apr 19, 2025

Choose a reason for hiding this comment

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

@Princesseuh the way I did it here won't work, as it causes build errors. (I confirmed that main branch builds successfully.)

I have tried a few different things including "export it directly in client.d.ts" but nothing is working.

What exactly did you mean by "it's trivial to import from astro-jsx without bundling issues"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possible to fix this?

@florian-lefebvre
Copy link
Member

I think this is good as a minor thanks!

@ADTC
Copy link
Contributor Author

ADTC commented Apr 18, 2025

Changes done. @florian-lefebvre

Note: I didn't use GitHub UI to accept your suggestions, but rather just replicated them in my local and made a commit to ensure there are no syntax errors and it has proper formatting. :)

@ADTC ADTC requested a review from florian-lefebvre April 18, 2025 12:34
@ascorbic
Copy link
Contributor

This is an expermental feature, so it can be a patch

@ADTC
Copy link
Contributor Author

ADTC commented Apr 19, 2025

@ascorbic As per v5.7.0 release notes, the SVG feature is no longer experimental.

Can you clarify again whether this change should be minor or patch?

@ascorbic
Copy link
Contributor

🤦‍♂️ You're right of course. In my defence is been a long week with lots of features

@ADTC ADTC requested a review from Princesseuh April 21, 2025 15:10
@ematipico ematipico added this to the v5.8.0 milestone May 19, 2025
@ematipico
Copy link
Member

@ADTC maintainers are responsible for documenting the features they implement. This means that you will have send a PR to withastro/docs.

Also, the Build is falling, so we can't merge it until this is fixed.

@ADTC
Copy link
Contributor Author

ADTC commented May 19, 2025

Yes I know the build is failing but I don't know how to fix it. 😢 I was hoping @Princesseuh might have some insight.

@Princesseuh
Copy link
Member

I'm not sure, sorry. It has been too much time since I've set up client.d.ts and all of that to remember the exact rules that make TypeScript happy. In retrospect, maybe astro-jsx.d.ts shouldn't have lived "outside" of the package, it's wonky, but I set that up 3 years ago now 😅

@ematipico ematipico removed this from the v5.8.0 milestone May 20, 2025
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) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants