preact@10.0.0-rc.3 svg prop strokeWidth is not equal to stroke-width
See original GitHub issueFor our project we use SVG arcs to render a circular chart.
When upgrading from 8.5.2 to the newest rc, we noticed that our circle charts turned into blobs.
Upon further inspection we realized that the issue occurs on all SVG path
elements.
After some hair pulling and debugging and checking code differences we came to the conclusion that the newest version doesn’t correctly pass the strokeWidth
property.
When changing it to stroke-width
it started working properly again.
Code sandbox example of said behaviour.
Check the difference between components Arc and Arc2, they only differ in strokeWidth
vs stroke-width
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
stroke-width - SVG: Scalable Vector Graphics - MDN Web Docs
The stroke-width attribute is a presentation attribute defining the width of the stroke to be applied to the shape.
Read more >SVG stroke-width not working - css - Stack Overflow
How to make the SVG shape outline thicker / thinner. I am trying to implement the stroke-width property, but it is ignored by...
Read more >stroke-width - CSS-Tricks
The stroke-width property in CSS is for setting the width of a border on SVG shapes.
Read more >Painting: Filling, Stroking and Marker Symbols – SVG ... - W3C
Properties 'fill' and 'stroke' take on a value of type <paint>, ... imposes a limit on the ratio of the miter length to...
Read more >4. Basic Shapes - SVG Essentials, 2nd Edition [Book] - O'Reilly
Example 4-2 draws some lines where the stroke width has been set to 10 user ... Setting this property to crispEdges (on an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks everyone for the issue and digging in 😁. I took a look myself and below are some of my thoughts:
Re: the original issue (
strokeWidth
not working inpreact
) -preact
core (notpreact/compat
) does not normalize SVG attributes and properties. SVG is pretty interesting when it comes to the names of its properties and attributes. Some properties (and their attributes) on SVG objects are camelCased (e.g.clipPathUnits
on aclipPath
element), some attributes are kebab-case (e.g.clip-path
on many SVG elements), and other attributes (usu. ones inherited from the DOM, e.g.oninput
are all lowercase - check out in your browser’s console). Normalizing all of these special cases is out of scope forpreact
core as it would be too big for the core renderer 😕 .preact/compat
however tries to mimicreact
which does normalize these attributes so we have a best effort attempt to get this right. So I think the recommendation, like @bojan88 hinted at, is that if this normalization is important to you and worth the bytes, then usepreact/compat
. Else, use the casing that matches what SVG expects which can be found on MDN (e.g. path).As @mattly pointed out,
preact
core does do some normalization (for legacy reasons) specifically for DOM events which are typically always all lowercase, which is whyonInput
andonSubmit
work inpreact
core.However, it appear our TypeScript typings may be wrong. They do indeed state that
strokeWidth
is supported 😬. We probably need to update some things here and differentiate which properties are allowed inpreact
core and which properties are allowed inpreact/compat
. Perhaps we should open a separate issue for that?@KerryMahne from what I understand Preact is not converting camel case to kebab case. That’s being done in
preact/compat
module.You just need to add this to the top of your script
import { createElement as h } from "preact/compat";
. Here’s updated code sandbox.