Skip to content

SVG not rendering properly with Blazor #5613

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

Closed
mdegroot71 opened this issue Oct 16, 2018 · 19 comments
Closed

SVG not rendering properly with Blazor #5613

mdegroot71 opened this issue Oct 16, 2018 · 19 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue help wanted Up for grabs. We would accept a PR to help resolve this issue Status: Resolved
Milestone

Comments

@mdegroot71
Copy link

Originally posted by @mdegroot71 in https://github.com/aspnet/Blazor/issue_comments#issuecomment-430270522

I am having the same issues. I've taken all of the same CSS, Javascript and produced HTML from Blazor, popped it into a static HTML page and ran it. The SVG scales as it should without any workarounds. I'm using Chrome. When I run it with Blazor, the SVG behaves in a weird way. This isn't a CSS issue. This is definitely a rendering issue b/c no matter how I inject the SVG, it still does not behave as if Blazor was not present.

@Lupusa87
Copy link
Contributor

Link is not working. Can you provide related issue number?

@mdegroot71
Copy link
Author

mdegroot71 commented Oct 23, 2018

Here is the link...https://github.com/aspnet/Blazor/issues/888. The original issue was about SVGs not resizing to size of parent. Thank you. Let me know if you need anything else.

@Lupusa87
Copy link
Contributor

Maybe it is related to this #1317
Did you check generated svg in chrome's inspector? Is this exact as expected?

@mdegroot71
Copy link
Author

Maybe it is related to this #1317
Did you check generated svg in chrome's inspector? Is this exact as expected?

I am not binding variables into the inline SVG. The SVG is within an If block - if that matters. Is there a work-around?

@mdegroot71
Copy link
Author

mdegroot71 commented Oct 23, 2018 via email

@Lupusa87
Copy link
Contributor

I don't know how you can avoid this case changing. Hope @SteveSandersonMS will comment.

@Lupusa87
Copy link
Contributor

You can ask here too https://gitter.im/aspnet/Blazor

@SQL-MisterMagoo
Copy link
Contributor

Take a look here : it's working fine for me - maybe you are doing something different?

I found that as long as blazor is rendering the entire svg it is fine even with @fields present in the markup, but if you try to update any property on the SVG from Blazor, it will then lowercase the viewBox.

If you do need to update the SVG, try to find a way to do it with CSS and then modify the CSS on the fly rather than changing the SVG.

https://github.com/SQL-MisterMagoo/BlazorTest/blob/master/Bletris/BletrisPiece.cshtml
https://github.com/SQL-MisterMagoo/BlazorTest/blob/master/BlazorClock/Clock.cshtml

@mdegroot71
Copy link
Author

mdegroot71 commented Oct 24, 2018 via email

@SteveSandersonMS
Copy link
Member

@mdegroot71 Yes, it is a 0.5.1 vs 0.6.0 thing. The SVG case handling bug isn't fixed in 0.6.0, but for an unrelated reason (the introduction of static markup blocks), the bug doesn't affect the initial render in 0.6.0 as long as your SVG is purely static (i.e., doesn't contains C# expressions in the Razor source).

So to clarify, I recognise the bug is still there in 0.6.0, but there is a case where it affects 0.5.1 worse than 0.6.0.

@StevenTCramer
Copy link
Contributor

@SteveSandersonMS Can you give us a hint on where the code is for this and maybe I can take a stab at a PR?

@BlazorDashboard
Copy link

I am having the same issues with a for loop in a svg tag.

<svg height="200px" viewBox="-1 -1 2 2" style="transform: rotate(-90deg)">
<path.....
@for (var i = 0; i < 1; i++)
{
}
</svg>

@Suchiman
Copy link
Contributor

Suchiman commented Nov 2, 2018

@PaulOst
Copy link

PaulOst commented Nov 8, 2018

@StevenTCramer have you been able to resolve this bug?

@mdegroot71
Copy link
Author

mdegroot71 commented Nov 8, 2018 via email

@StevenTCramer
Copy link
Contributor

StevenTCramer commented Nov 9, 2018

@PaulOst Not resolved yet... Planing to review the code next week if someone has not gotten to it before me. I will make note here before I start working on a PR. (So no one wastes there time. including me )

@StevenTCramer
Copy link
Contributor

@Suchiman
Update on this. I am investigating to see where the original PascalCase variable gets converted to all lowercase.

In the entire callstack below the value is already lower case.

export function renderBatch(browserRendererId: number, batch: RenderBatch) {
...

The batch in the above is just a memory stream in the HEAP. So far from easy to debug. I am guessing what ever passes this thing has already converted it to all lowercase. If anyone can give me hints on where the original Razor is parsed before sending it to mono I can test and see if it is lowercase on that side.

To debug I added a "viewBox" attribute to the current SVG component in the test app.

toJavaScriptString (MonoPlatform.ts:87)
readHeapObject (MonoPlatform.ts:131)
attributeName (SharedMemoryRenderBatch.ts:85)
./src/Rendering/BrowserRenderer.ts.BrowserRenderer.applyAttribute (BrowserRenderer.ts:233)
./src/Rendering/BrowserRenderer.ts.BrowserRenderer.applyEdits (BrowserRenderer.ts:84)
./src/Rendering/BrowserRenderer.ts.BrowserRenderer.updateComponent (BrowserRenderer.ts:35)
renderBatch (Renderer.ts:41)
window.Blazor._internal.renderBatch (Boot.WebAssembly.ts:17)
_mono_wasm_invoke_js_unmarshalled (mono.js:1)
(anonymous) (mono.js:1)
callMethod (MonoPlatform.ts:68)
beginInvokeDotNetFromJS (MonoPlatform.ts:299)
invokePossibleInstanceMethodAsync (Microsoft.JSInterop.ts:77)
invokeMethodAsync (Microsoft.JSInterop.ts:55)
raiseEvent (BrowserRenderer.ts:370)
(anonymous) (BrowserRenderer.ts:21)
./src/Rendering/EventDelegator.ts.EventDelegator.onGlobalEvent (EventDelegator.ts:83)

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added this to the Backlog milestone Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. area-blazor Includes: Blazor, Razor Components help wanted Up for grabs. We would accept a PR to help resolve this issue labels Dec 17, 2018
@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, 5.0.0-preview2 Jan 23, 2020
@ElderJames
Copy link
Contributor

In my project, I can render the svg icon in components.
I use HttpClient to download the file and render it by converting to MarkupString.
https://github.com/ElderJames/ant-design-blazor/blob/master/components/icon/AntIcon.razor
https://ant-design-blazor.gitee.io/

@mkArtakMSFT
Copy link
Member

Closing as we will be tackling this as part of #18271

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label May 14, 2020
@ghost ghost added the Status: Resolved label May 14, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue help wanted Up for grabs. We would accept a PR to help resolve this issue Status: Resolved
Projects
None yet
Development

No branches or pull requests