<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>14563</bug_id>
          
          <creation_ts>2007-07-08 14:11:31 -0700</creation_ts>
          <short_desc>getComputedStyle() returns an empty style declaration for detached elements</short_desc>
          <delta_ts>2020-01-20 21:01:20 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>GoogleBug, InRadar, NeedsReduction</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>110007</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>mitz</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>allan.jardine</cc>
    
    <cc>bdakin</cc>
    
    <cc>ddkilzer</cc>
    
    <cc>fremycompany_pub</cc>
    
    <cc>hyatt</cc>
    
    <cc>ian</cc>
    
    <cc>jan.fiegert</cc>
    
    <cc>m.goleb+bugzilla</cc>
    
    <cc>mike.sherov</cc>
    
    <cc>paulirish</cc>
    
    <cc>tabatkins</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>webkit</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>5167</commentid>
    <comment_count>0</comment_count>
    <who name="">mitz</who>
    <bug_when>2007-07-08 14:11:31 -0700</bug_when>
    <thetext>getComputedStyle() returns an empty style declaration for detached elements. Firefox returns a full style declaration including inherited properties (starting from the root of the detached element&apos;s tree).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88046</commentid>
    <comment_count>1</comment_count>
    <who name="Jon Emerson">jon</who>
    <bug_when>2008-08-07 10:21:46 -0700</bug_when>
    <thetext>I&apos;m also running into this bug.  It affects Windows Safari, both on the latest Safari release and the WebKit nightly.

I have a 20-line HTML file that exercises the bug if you&apos;d like me to send you it.

Thanks!

Jon Emerson
Google</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88047</commentid>
    <comment_count>2</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2008-08-07 10:33:28 -0700</bug_when>
    <thetext>Jon, please attach your test case reduction.  Thanks!
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88048</commentid>
    <comment_count>3</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2008-08-07 10:33:58 -0700</bug_when>
    <thetext>&lt;rdar://problem/6132967&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88049</commentid>
    <comment_count>4</comment_count>
      <attachid>22698</attachid>
    <who name="Jon Emerson">jon</who>
    <bug_when>2008-08-07 10:43:20 -0700</bug_when>
    <thetext>Created attachment 22698
Example of the getComputedStyle bug

The attached HTML file exercises the bug.  In Firefox, you correctly get an alert of &apos;10px&apos;.  In Safari, you get &apos;&apos;.  You can uncomment the appendChild call to see that getComputedStyle acts as intended in both Firefox and Safari if the element is appended to the document body.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88054</commentid>
    <comment_count>5</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-08-07 12:31:37 -0700</bug_when>
    <thetext>Isn&apos;t this &quot;expected&quot; based on our implementation?  We use the resolved style for computing this.  So we&apos;d have to do a manual style-resolve in this case, since a detached element is going to have no renderer.

SVG had to do some manual style resolution.  I guess for a detached element it&apos;s relatively easy, since you&apos;re resolving w/o a parent, so only #id selectors and * selectors apply.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88063</commentid>
    <comment_count>6</comment_count>
    <who name="Dave Hyatt">hyatt</who>
    <bug_when>2008-08-07 14:01:06 -0700</bug_when>
    <thetext>We could fix this I suppose, but it&apos;s kind of odd that someone is depending on this.  It&apos;s not like any style changes you make will have any meaningful effect while detached, so what are you checking for anyway? :)

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88095</commentid>
    <comment_count>7</comment_count>
    <who name="Jonathan del Strother">jon</who>
    <bug_when>2008-08-08 02:29:47 -0700</bug_when>
    <thetext>I don&apos;t have the original code any more, but if I remember correctly, this was my use case : 

I was creating a bunch of elements dynamically, throughout the lifetime of the page (as opposed to once on page load).   Whenever I inserted them, I needed to find their dimensions (using getComputedStyle) in order to position them correctly.

Which would be fine, except it turns out that getComputedStyle is pretty slow.  So I created some prototype elements on startup that I could run getComputedStyle on, cached the results, and used the precalculated values every time after that.  Which was fine in Firefox, but obviously broken in Safari given the prototype elements were never inserted into the page.

I guess I ended up inserting them into a hidden div to get the style, then deleting them again.
I&apos;m sure there was some reason why I couldn&apos;t just do it on the first time I added an element, but nothing&apos;s coming to mind...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88131</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2008-08-08 15:17:04 -0700</bug_when>
    <thetext>Per spec, getComputedStyle() returns the computed style, and a node that isn&apos;t a document by definition doesn&apos;t have a computed style. Whether that&apos;s desireable or not is another story; maybe we should redefine getComputedStyle()... that&apos;s Anne&apos;s spec, I believe.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88805</commentid>
    <comment_count>9</comment_count>
    <who name="Jon Emerson">jon</who>
    <bug_when>2008-08-19 02:47:01 -0700</bug_when>
    <thetext>In our application, we render our pages off-screen before attaching them to the document because in a couple popular browsers the performance of off-screen (detached) DOM creation is an order of magnitude greater than on-screen (attached) DOM creation.  Part of our rendering involves manually setting the width and heights on certain elements to fill the screen.  (We do this manually for cross-browser compatibility.)  If we can&apos;t know the margins of elements, then we can&apos;t size other elements appropriately.

Please fix this bug!  Thanks.
Jon</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>251161</commentid>
    <comment_count>10</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2010-07-14 06:56:34 -0700</bug_when>
    <thetext>The spec has changed to expect the Firefox behavior: http://dev.w3.org/csswg/cssom/#extensions-to-the-window-interface</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>382072</commentid>
    <comment_count>11</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2011-04-08 01:23:27 -0700</bug_when>
    <thetext>*** Bug 39250 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>531711</commentid>
    <comment_count>12</comment_count>
    <who name="Mike Sherov">mike.sherov</who>
    <bug_when>2012-01-07 21:02:50 -0800</bug_when>
    <thetext>The spec has indeed changed:
http://dev.w3.org/csswg/cssom/#resolved-value
http://www.w3.org/TR/css3-values/#computed-value

This shows that disconnected nodes should still resolve to computed values for disconnected nodes, with the computed value defined as: &quot;the result of resolving the specified value insofar as possible without formatting the document, as defined in the &quot;Computed value&quot; line of the property definition tables.&quot;

Indeed, Firefox resolves this correctly now, but alas IE9 and Opera do this incorrectly according to the spec.

FWIW, It&apos;s also reared its head as a bug reported in jQuery: http://bugs.jquery.com/ticket/9338</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>741135</commentid>
    <comment_count>13</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-10-12 13:11:43 -0700</bug_when>
    <thetext>*** Bug 83867 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>741139</commentid>
    <comment_count>14</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-10-12 13:14:20 -0700</bug_when>
    <thetext>Related CSSWG discussion http://lists.w3.org/Archives/Public/www-style/2012Oct/0362.html.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>915021</commentid>
    <comment_count>15</comment_count>
    <who name="François REMY">fremycompany_pub</who>
    <bug_when>2013-08-06 19:58:56 -0700</bug_when>
    <thetext>Just faced this issue today as I wanted to know the default style applied to a certain kind of element (tagName). For info, my webkit fix is to insert the element into the HEAD hoping it doesn&apos;t trigger any relayout nor too many observable effects.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1235166</commentid>
    <comment_count>16</comment_count>
    <who name="Jan Fiegert">jan.fiegert</who>
    <bug_when>2016-09-30 01:42:06 -0700</bug_when>
    <thetext>Webkit shares the bug with Chrome:

https://bugs.chromium.org/p/chromium/issues/detail?id=558165

Someone created the following example to demonstrate it:

http://jsfiddle.net/3wz4xdgq/3/

Running this with Safari, Chrome and Firefox shows the following result:

Safari:  NOT WORKING
Firefox: OK
Chrome:  NOT WORKING
Edge:    OK</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1607947</commentid>
    <comment_count>17</comment_count>
    <who name="Mike Sherov">mike.sherov</who>
    <bug_when>2020-01-17 04:18:34 -0800</bug_when>
    <thetext>This should be marked as wontfix as it was resolved as correct behavior in 2018 https://lists.w3.org/Archives/Public/www-style/2018May/0031.html</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>22698</attachid>
            <date>2008-08-07 10:43:20 -0700</date>
            <delta_ts>2008-08-07 10:43:20 -0700</delta_ts>
            <desc>Example of the getComputedStyle bug</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>466</size>
            <attacher name="Jon Emerson">jon</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8c3R5bGU+CiAgLnRlbnBpeGVsbWFyZ2luIHsKICAgIG1hcmdpbjogMTBw
eDsKICB9Cjwvc3R5bGU+CjwvaGVhZD4KPGJvZHk+CiAgPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFz
Y3JpcHQiPgogICAgdmFyIG15RGl2ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnZGl2Jyk7CiAg
ICBteURpdi5jbGFzc05hbWUgPSAndGVucGl4ZWxtYXJnaW4nOwogICAgbXlEaXYuaW5uZXJIVE1M
ID0gJ3NvbWUgdGV4dCc7Ci8vICAgIGRvY3VtZW50LmJvZHkuYXBwZW5kQ2hpbGQobXlEaXYpOwoK
ICAgIHZhciBzdHlsZXMgPSBkb2N1bWVudC5kZWZhdWx0Vmlldy5nZXRDb21wdXRlZFN0eWxlKG15
RGl2LCAnJyk7CiAgICBhbGVydCgiQ29tcHV0ZWQgbWFyZ2luIGxlZnQgPSAnIiArIHN0eWxlcy5n
ZXRQcm9wZXJ0eVZhbHVlKCdtYXJnaW4tbGVmdCcpICsgIiciKTsKICA8L3NjcmlwdD4KPC9ib2R5
Pgo8L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>