Bug 172224 - Incorrect dimensions of images with srcset when adopted from document without browsing context
Summary: Incorrect dimensions of images with srcset when adopted from document without...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: Safari 10
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-05-17 09:13 PDT by Memmie Lenglet
Modified: 2022-11-25 01:31 PST (History)
11 users (show)

See Also:


Attachments
Test cases: nodes from documents with and without browsing context (6.37 KB, text/html)
2017-05-17 09:13 PDT, Memmie Lenglet
no flags Details
Test cases: nodes from documents with and without browsing context (use HTTPS) (5.39 KB, text/html)
2017-05-17 09:16 PDT, Memmie Lenglet
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Memmie Lenglet 2017-05-17 09:13:01 PDT
Created attachment 310397 [details]
Test cases: nodes from documents with and without browsing context

Overview:

Images created from document without browsing context have incorrect dimension (width=0 and height=0) if not forced (defined with CSS). These images are loaded but not visible.
NaturalHeight and naturalWidth are correctly provided (the images are loaded).
This issue doesn't happend if the node is imported (Document#importNode) instead of adopted (Document#adoptNode).

Steps to Reproduce, with JavaScript:

1. Create a document without browsing context (createHTMLDocument, DOMParser, removed iframe)
2. create image with srcset nodes with innerHTML or write() or createElement(), etc.
3. adopt the image node to the current document
4. append the image node

Actual Results:

Images are loaded (see web dev tools, load event) but the width and the height are equals 0.
If with CSS, dimensions are defined (forced), the image is visible

Expected Results:

If dimensions are not forced, the image should have dimension match its natural width and height.
Comment 1 Memmie Lenglet 2017-05-17 09:16:32 PDT
Created attachment 310398 [details]
Test cases: nodes from documents with and without browsing context (use HTTPS)
Comment 2 Radar WebKit Bug Importer 2017-05-18 11:49:54 PDT
<rdar://problem/32277554>
Comment 3 pnparam 2018-03-22 22:54:03 PDT
Check my bug report: https://bugs.webkit.org/show_bug.cgi?id=183910

It is closed based on the suggestions here: https://bugzilla.mozilla.org/show_bug.cgi?id=1448110
Comment 4 mic.gallego 2022-08-08 21:09:17 PDT
Hi,

We are facing this issue as well, and I could not find any fix in the link you have provided pnparam. Is there any way to make sure that srcset is properly honored when a node is added through a fragment or DOMParser ?
Comment 5 Dominik Dröscher 2022-11-25 01:31:07 PST
I also stumbled upon this issue. Dynamically adding DOM nodes containing images with srcset will set their dimensions to 0, 0. For my case I was able to work around this by forcing a predefined aspect-ratio, but that is clearly not ideal and not applicable to most contexts.