You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inlining SVGs, preprocess-inline-svg does not decode the HTML entity & into &, which .svelte files support. Svelte files do not decode & into &, so it must be done by this inlining process. This is especially apparent when using a URL in an SVG that needs an ampersand as a query parameter. When inlining, the ampersand is not decoded, so the query is ruined because the URL is resolved including &. Here is a demo SVG:
When used in combination with preprocess-inline-svg, you can look in the Network tab of your browser's dev tools to see that the queried URL does not properly have &display=swap, meaning the queried URL & returned data is incorrect.
Here is a simple workaround I found in the time being to circumvent this issue (placed in svelte.config.js):
import*aspreprocess_svgfrom'@svelte-put/preprocess-inline-svg'functioncustomInlineSvg(sources,inlineConfig){constrSources=preprocess_svg.resolveSources(sources)constrConfig=preprocess_svg.resolveInlineSvgConfig(inlineConfig)return{markup({ content, filename }){consttransformed=preprocess_svg.transform(content,filename,rSources,rConfig)// Replace & with & because .svelte files will not decode it for ustransformed.code=transformed.code.replace(/&/g,'&')returntransformed}}}
Then, use customInlineSvg in place of inlineSvg in the config, like so:
/** @type {import('@sveltejs/kit').Config} */constconfig={// Consult https://kit.svelte.dev/docs/integrations#preprocessors// for more information about preprocessorspreprocess: [customInlineSvg([{directories: 'static'}]),// ...],// ...
The text was updated successfully, but these errors were encountered:
When inlining SVGs, preprocess-inline-svg does not decode the HTML entity
&
into&
, which.svelte
files support. Svelte files do not decode&
into&
, so it must be done by this inlining process. This is especially apparent when using a URL in an SVG that needs an ampersand as a query parameter. When inlining, the ampersand is not decoded, so the query is ruined because the URL is resolved including&
. Here is a demo SVG:When used in combination with
preprocess-inline-svg
, you can look in the Network tab of your browser's dev tools to see that the queried URL does not properly have&display=swap
, meaning the queried URL & returned data is incorrect.Here is a simple workaround I found in the time being to circumvent this issue (placed in
svelte.config.js
):Then, use
customInlineSvg
in place ofinlineSvg
in the config, like so:The text was updated successfully, but these errors were encountered: