-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Render the contents of the <svg>
tag using {@html}
in the component mode
#39
Comments
<svg>
tag using {@html}
as string in the component mode<svg>
tag using {@html}
in the component mode
Sorry for the delayed response. Vacation time and stuff so I've been out and about. This sounds like an improvement to me, so I would gladly accept a PR 😍 |
Thanks a bunch. I got another PR which is conflicting with this PR, but as soon as I have resolved both PR:s I will make a release. I'm on vacation right now so it might take a few days. |
@poppa Got ya, no problem, enjoy the vacation! |
@aradalvand Thank you for your contribution. I have now released version 4.0.1 with your code changes 👍 |
@poppa Thanks! |
Importing an SVG file as a Svelte component with this plugin currently causes it to generate a Svelte component on the fly which will have the entire SVG directly as its content — it just adds
{...$$props}
on the<svg>
tag:sveltekit-svg/src/index.ts
Lines 72 to 81 in be9e121
However, the problem with this is that when the Svelte compiler then looks at the generated component, it will parse all the elements inside the root
<svg>
tag, and will yield lots of compiler output with lots of function calls to create each element in the DOM. This is totally unnecessary. A better approach would be to render the contents of the<svg>
tag using{@html}
.See this REPL, which demonstrates exactly this; take a look at
AtHtmlSvg.svelte
andRegularSvg.svelte
and theJS output
tab of each, and notice the difference.Even some plugins have been created to address this, like svelte-preprocess-svg, for cases where you have inlined SVG elements in your Svelte components. But sveltekit-svg can make this improvement very easily.
Let me know if you're on board, and I will make a pull request.
The text was updated successfully, but these errors were encountered: