Handle data:image/svg+xml URLs without making requests #1467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vite 5 started automatically inlining small SVG files, attempting to request these with AJAX causes CSP issues, after some digging it seemed the most expedient solution was to adjust the request logic so it will avoid making a request if it is given a data URL with the correct MIME type and return the expected structure so it can be used immediately.
I haven't added new tests but I have tested this change and it resolved the issue. This isn't entirely comprehensive, there are additional cases I didn't account for like base64 encoding. If that is needed I can add it as well or this can be used as a starting point.
Relevant commit from Vite: vitejs/vite@5acda5e