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: asset import should skip handling data URIs #18163

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

Justineo
Copy link
Contributor

Description

Vite currently transforms asset URLs inside new URL(..., import.meta.url), but if we are dealing with data URIs it incorrectly produces <some-path>/data:image/png;....

This PR made the assetImportMetaUrlPlugin skip handling data URIs and added corresponding tests.

Copy link

stackblitz bot commented Sep 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! I checked webpack and it looks like they also keep data url properly.

Btw, if you know it's a data url beforehand, you could simply write new URL("data:...") without import.meta.url. What's your use case you cannot do so?

@Justineo
Copy link
Contributor Author

A dependency (built by Vite too) of the current project is producing this and I can see the vite:asset-import-meta-url plugin is transforming it to an invalid one.

@hi-ogawa
Copy link
Collaborator

Hmm, that's interesting. I guess we could also avoid doing that by only emitting new URL('data:...') for inlined assets as that would slightly reduce the build output. Either way, this PR should be fine as is.

@sapphi-red sapphi-red added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Sep 26, 2024
@sapphi-red sapphi-red merged commit 70813c7 into vitejs:main Sep 26, 2024
12 checks passed
@Justineo Justineo deleted the fix-datauri-asset branch September 26, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants