-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
<svelte:element this="svg"> generates proper html but doesn't get rendered properly. #7613
Comments
I believe you have to define the width or height of the SVG using css / inline style. button svg {
height: 16px;
} This is default behaviour. Your usage of svelte:element is fine and not causing issues. |
This didn't help. I have two svg elements : one in plain html, another using svelte. They both are identcal in definition. HTML renders fine. Svelte one doesn't. Attaching the html and the output:
|
@sandeep-gh In the code that you have shared, the first svg element does not contain a height or width values. The second one does contain width, that is the reason why the second one is rendering and the first one isn't. |
As @sami-baadarani said, the first svg element does not contain a height or width values. After adding width or height, they both work well. @sandeep-gh |
I came across something I believe is similar to this issue. I'm doing something like this: App.svelte
DynamicTag.svelte
The html generated and retrieved through the browser developer tools is flawless and will work if used statically, but renders nothing within my svelte app. TLDR |
I got curious and looked into the hint that @nicksulkers left. It looks like there are two relevant functions in
If you use a static name, the compiler is able to figure out that you want to use The generated code for
I was thinking it could be hard for the compiler to figure out that an arbitrary name is supposed to use the svg namespace, but that maybe adding the namespace would help. When you do, the correct function is brought in, but the compiler takes a different path & in the output, the element name ends up being
it seems like we'd want it to output this:
(but I don't know how to do that 🤗) postscript: I don't think it's simply about the presence or absence of a height or width attribute, because adding either to the sag element in App.svelte doesn't fix the problem |
Seeing the same problem here using svelte:element and svelte:self to generate an SVG structure. Once I figured out it was a namespace problem, I was able to add |
This should be supported now as of 3.51.0. |
Closed by #7695. |
I am not able to get this to work. Below is setup: package.json{
...
...
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.11",
...
"tailwindcss": "^3.1.8",
"vite": "^2.3.7"
},
"dependencies": {
"svelte": "^3.51.0"
}
} The html begin generate: <div class="flex justify-center" style=""> <div class="flex flex-col space-y-4" style="">
<button value="myval" class="" style="">Click me
<svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" class="h-6 w-6" style=""> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" style=""> </path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" style=""> </path></svg>
</button>
</div>
</div> However, no svg is getting rendered. Not sure if I am missing something. |
I can see the SVG. Maybe I can easily understand the situation if you create REPL. |
Here is a repl, which shows that the problem persists in v.3.55.0. https://svelte.dev/repl/5e1e989bbccb4d688b571006bc3c0d12?version=3.55.0 I would expect to see both the red and the green circle, since both look identical in html, but the green circle isn't rendered. |
What is the use case of this? |
I have an one use case for this. I am developing a web development framework in Python based on justpy (https://github.com/justpy-org/justpy/). I am using svelte as the frontend library. |
Why just using |
I will try the |
Let me summarize: the problem is that svg elements need to be created with a different namespace. The namespace can't be changed afterwards. In general, the problem can occur on all svg tags (svg, path, circle, etc ). I say 'can', since svelte is smart enough to change the namespace, if the svelte:element is a visual child of an svg tag. Example: <svg>
<svelte:element this={toggle?"circle":"ellipse"} {...props}/>
</svg> This works. If you extract just the svelte:element into a different component, it would fail.
|
We have easy workaround that is using |
@baseballyama workaround works for me now. Thank you. |
Describe the bug
I am using a python library that builds a json describing the html components. This is then fed to a svelte code that uses svelte:element to instantiate the html components. All components (button/iinput) works fine except for svg elements. The html is generated properly as shown below
Severity
annoyance
The text was updated successfully, but these errors were encountered: