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

SVGs are not rendering on lates vite 6 #401

Closed
7 tasks done
Prathap-Thunga opened this issue Jan 6, 2025 · 5 comments
Closed
7 tasks done

SVGs are not rendering on lates vite 6 #401

Prathap-Thunga opened this issue Jan 6, 2025 · 5 comments

Comments

@Prathap-Thunga
Copy link

Describe the bug

I am trying render an SVG in Vite + React application. There is only probelm with one SVG that in vite 6. In vite 5 same svg is working did anyone faced this issue ?? Help would be appreciated.

Reproduction

NA

Steps to reproduce

No response

System Info

Chrome, Edge, Safari

Used Package Manager

npm

Logs

No response

Validations

Copy link

github-actions bot commented Jan 6, 2025

Hello @Prathap-Thunga. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@ArnaudBarre
Copy link
Member

How are rendering this SVG? They are multiple ways to do so, it would be simpler for us to fix the issue if you can reproduce it on stackblitz. The default template in the comment above does render two svg correctly (one from public, one relative import)

@Prathap-Thunga
Copy link
Author

Prathap-Thunga commented Jan 7, 2025

How are rendering this SVG? They are multiple ways to do so, it would be simpler for us to fix the issue if you can reproduce it on stackblitz. The default template in the comment above does render two svg correctly (one from public, one relative import)

Hello @ArnaudBarre , Here is the link where you can reproduce. If you hover on the text React Icon its is displaying react icon as a cursor but if we hover on the custom text its not displaying the custom icon and both the SVGs are rendering normally but if we render them as a cursor icon react icon is working but my custom icon is not working. Use the below link to reproduce the issue.

link - https://stackblitz.com/edit/vitejs-vite-afda43gn?file=src%2FApp.jsx

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 8, 2025

Inline svg seems broken for inline style style={{ cursor: `url(${icon}) 16 16, auto` }}, but this was already the case on Vite 5 build. In Vite 6, svg can be inlined both dev and build, so it just got broken in both cases vitejs/vite#18581. This is an intended change for dev/build consistency, and you can now use ?no-inine to enforce file asset vitejs/vite#15454. Here is an updated example:

https://stackblitz.com/edit/vitejs-vite-afda43gn?file=src%2FApp.jsx

import icon from './assets/icon.svg?no-inline';

@hi-ogawa hi-ogawa closed this as completed Jan 8, 2025
@Prathap-Thunga
Copy link
Author

I tried using ?no-inline which didn't worked for me. But wrapping up the URL in double quotes solved my problem. I tried searching everywhere but didn't find correct solution posting it here so it will be useful for others.
style={{ cursor: url("${icon}") 16 16, auto }}

@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants