-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Svg thumbnail failed rendering #32936
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
Svg thumbnail failed rendering #32936
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the implementation should be changed, since I don't understand why JavaScript is needed to get the fill-rule. We're supposed to have that already from elsewhere.
Also this fixes for the svg thumbnail but not for svg preview. What about Peek? Does it have the same issue?
src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the solution, it doesn't seem like a safe solution. According to the sample in the documentation linked in this PR ( https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule ) , fill-rule might be present in internal polygons and not even the svg tag. So this change might actually apply an internal fill rule to the whole SVG, since it's applying it to the svg tag.
This is likely to create errors in trying to show others files.
If what we're trying to do is restore the "fill-rule" we seem to be removing from the style of the svg, perhaps the correct solution is edit or add just the width and height instead of completely overwriting the style of the svg tag like we were doing before.
Thoughts?
…iciently - Add retry logic and error handling for WebView2 initialization
Is this ready for review again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request addresses an SVG thumbnail rendering bug by reapplying the fill-rule (and other style attributes) extracted from the SVG’s style attribute. The changes include removing an unused using directive, parsing the SVG content to capture style information, and adding a retry mechanism during WebView2 initialization.
Comments suppressed due to low confidence (1)
src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs:123
- [nitpick] The variable name 'a' is ambiguous; consider renaming it to something more descriptive like 'svgViewBoxResult' for clarity.
var a = await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].viewBox;");
…GThumbnail-Failed-Rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some code changes, and the local test passed successfully.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, and works fine in my environment
* [SVGThumbnail] Check fill-rule in SVG file and apply it. * [SVGThumbnail] Comment added * [SVGThumbnail] SvgContents is used instead of all html content. * [SVGThumbnail] - Use SvgContents to extract and modify SVG styles efficiently - Add retry logic and error handling for WebView2 initialization * use Linq --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
…d a regression (microsoft#38058) Revert "Svg thumbnail failed rendering (microsoft#32936)" This reverts commit 1d358af.
* [SVGThumbnail] Check fill-rule in SVG file and apply it. * [SVGThumbnail] Comment added * [SVGThumbnail] SvgContents is used instead of all html content. * [SVGThumbnail] - Use SvgContents to extract and modify SVG styles efficiently - Add retry logic and error handling for WebView2 initialization * use Linq --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
…d a regression (microsoft#38058) Revert "Svg thumbnail failed rendering (microsoft#32936)" This reverts commit 1d358af.
Summary of the Pull Request
Default value of fill-rule in style is "nonzero". There is a possibility that rendering bugs may occur due to this reason. Therefore, to eliminate these errors, it is checked whether there is a fill-rule in style and if so, it is re-applied.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
PR Checklist
Detailed Description of the Pull Request / Additional comments
I created some SVG files for testing. The first one is the "fill-rule" attribute is under style. In others it's under "polygon" and "path". When I tested it with version 0.84.1, only the one under style was broken. Therefore, I was able to solve the problem by parsing the svg style of the file and re-applying the "fill-rule" and other attributes there. The reason why I re-applied all the attributes in the style was that if there was such an error in the "fill-rule", I suspected that there might be other attributes as well. When I changed the "stroke color", "clip-rule", "stroke-width", "opacity" attributes, I did not encounter this error. However, I preserved the code this way as similar errors may occur in other attributes in the future.
0.84.1

PR

Validation Steps Performed
Check with these svg files
Test files.zip