Skip to content

Images with width=100% don't client side render correctly #3887

@jpnelson

Description

@jpnelson
  • Check if updating to the latest Preact version resolves the issue

Describe the bug
When client side rendering an image with width: 100%, the resulting image has a width of zero.

I think the issue is here specifically:

dom[name] = value == null ? '' : value;

It seems as though Preact tries to set img.width = '100%' and only tries to do img.setAttribute('width', '100%') if that fails. The issue is that img.width = '100%' does not cause an exception, but it does coerce the string to an integer and ultimately sets the image width to zero. img.width when accessed as as property is meant to be only an integer: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-width

To Reproduce
https://codesandbox.io/s/preact-images-csr-only-lrpkbp?file=/src/App.js

Load the page. Expected: the sandbox has an image with width=100%. Actual: the image is not visible since it has width=0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions