preact ignores/rewrites <img> dimensions?
See original GitHub issueI have a React-managed page with some 175+ images, and after switching from react
to preact-compat
(using the webpack alias solution) all my images come out as <img src="..." width="0" height="0">
in the DOM, despite having defined dimensions in the JSX source code (e.g. <img src="..." width="100px" height="50px"/>
etc) - is there any reason why it does this? Because that seems like a pretty crazy bug.
Issue Analytics
- State:
- Created 6 years ago
- Comments:28 (15 by maintainers)
Top Results From Across the Web
preact ignores/rewrites <img> dimensions? #619 - GitHub
I have a React-managed page with some 175+ images, and after switching from react ... What happens there is Preact doing img.width =...
Read more >Setting initial img dimensions in state - REACT - Stack Overflow
The dimensions-state is set correctly when the loading of the img is completed. However there is no inline styling applied. Can someone help...
Read more >preact-lazyimage - npm
Lazy image loading made easy and simple for preact. ... Start using preact-lazyimage in your project by running `npm i preact-lazyimage`.
Read more >HTML img width Attribute - W3Schools
The width attribute specifies the width of an image, in pixels. Tip: Always specify both the height and width attributes for images. If...
Read more ><img>: The Image Embed element - HTML - MDN Web Docs
The HTML element embeds an image into the document. ... Use both width and height to set the intrinsic size of the image,...
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
dimension attrs must not have units [1]. so i’m not sure what all the fuss is about.
[1] https://www.w3.org/TR/html5/embedded-content-0.html#dimension-attributes
@Pomax - It sounds like you’re still not sure what’s going on. I’ll try to see if I can explain:
Internally, what happens when Preact renders the
<img src='invalid' width="400px" height="400px"/>
in your JSX is roughly this:h('img', { src: 'invalid', width: '400px', height: '400px' })
h(...)
function call is a data structure that looks like this:vdomElement
below) and creates an actual DOM element:vdomElement.nodeName
isimg
,node
is anHTMLImageElement
, which does have properties calledwidth
andheight
so what ends up getting executed is:Try the code from step (4) in your browser console and then print out the values of
node.width
andnode.height
.Now on the other hand, try this:
You’ll see different results.
Does this make things clearer?