Problems with <Image /> component
See original GitHub issueFirst off, thank you for an awesome library. I hope this is one the community can support š. Iām running into several problems with the <Image />
component which Iāll outline below.
Problem 1 - <img />
width / height
props
HTML <img />
accepts width / height
attributes which helps the browser paint the screen without ājankā. Currently, <Box>
/ styled-system / ?, takes these props as css width/height. I understand that this is intentional and desirable for most situations. Perhaps we could add htmlWidth
and htmlHeight
(similar to htmlFor
from react-dom) and pass those props as to the underlying <img />
element.
Proposed prop names:
htmlWidth
/htmlHeight
widthAttribute
/heightAttribute
domWidth
/domHeight
Whatever you decide here, keep in mind that there will likely be other prop names that should pass through to the underlying element in the future.
Problem 2 - useImageHasLoaded
hook causing multiple network requests
The useHasImageLoaded
causes (I think) multiple network requests for the same image. I have not tested with the optional fallbackSrc
, but this should not be required for proper image loading.
Problem 3 - <Box />
and BoxProps
TypeScript
I attempted to workaround Problem 1 & 2 in my user code by reimplementing <Image>
. I, too, would like to do so using <Box as="img" ... />
similarly to how this lib handles it. The problem I encountered immediately is BoxProps
. The TypeScript types are defined as such that <Box as="img" />
doesnāt accept a src
prop. This is likely going to be a problem for many TypeScript users that would like use the <Box as="something" />
paradigm. Iām not sure if this can be solved generically by the lib. Also, Iām not sure how to solve this in my own code yet. It may be unfortunate to have to resort to allowing every possible prop such as src
on <Box />
just because it may be used as an <img />
, <video />
, or <SomeRandomComponent />
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:17 (9 by maintainers)
Top GitHub Comments
@paynecodes, yep. Itās live already, check here: https://chakra-ui.com/image#props
Currently working on the Typescript issue.
hereās a sample of the code (missing a couple functions but you can fill in the blanks). Like I mentioned, we basically rewrote the Avatar so it wouldnāt have the flashing behavior at all, because there is no way around it when using the Chakra Avatar.