WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
14563
getComputedStyle() returns an empty style declaration for detached elements
https://bugs.webkit.org/show_bug.cgi?id=14563
Summary
getComputedStyle() returns an empty style declaration for detached elements
mitz
Reported
2007-07-08 14:11:31 PDT
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's tree).
Attachments
Example of the getComputedStyle bug
(466 bytes, text/html)
2008-08-07 10:43 PDT
,
Jon Emerson
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Jon Emerson
Comment 1
2008-08-07 10:21:46 PDT
I'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'd like me to send you it. Thanks! Jon Emerson Google
David Kilzer (:ddkilzer)
Comment 2
2008-08-07 10:33:28 PDT
Jon, please attach your test case reduction. Thanks!
David Kilzer (:ddkilzer)
Comment 3
2008-08-07 10:33:58 PDT
<
rdar://problem/6132967
>
Jon Emerson
Comment 4
2008-08-07 10:43:20 PDT
Created
attachment 22698
[details]
Example of the getComputedStyle bug The attached HTML file exercises the bug. In Firefox, you correctly get an alert of '10px'. In Safari, you get ''. 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.
Eric Seidel (no email)
Comment 5
2008-08-07 12:31:37 PDT
Isn't this "expected" based on our implementation? We use the resolved style for computing this. So we'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's relatively easy, since you're resolving w/o a parent, so only #id selectors and * selectors apply.
Dave Hyatt
Comment 6
2008-08-07 14:01:06 PDT
We could fix this I suppose, but it's kind of odd that someone is depending on this. It's not like any style changes you make will have any meaningful effect while detached, so what are you checking for anyway? :)
Jonathan del Strother
Comment 7
2008-08-08 02:29:47 PDT
I don'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'm sure there was some reason why I couldn't just do it on the first time I added an element, but nothing's coming to mind...
Ian 'Hixie' Hickson
Comment 8
2008-08-08 15:17:04 PDT
Per spec, getComputedStyle() returns the computed style, and a node that isn't a document by definition doesn't have a computed style. Whether that's desireable or not is another story; maybe we should redefine getComputedStyle()... that's Anne's spec, I believe.
Jon Emerson
Comment 9
2008-08-19 02:47:01 PDT
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't know the margins of elements, then we can't size other elements appropriately. Please fix this bug! Thanks. Jon
Ojan Vafai
Comment 10
2010-07-14 06:56:34 PDT
The spec has changed to expect the Firefox behavior:
http://dev.w3.org/csswg/cssom/#extensions-to-the-window-interface
Ojan Vafai
Comment 11
2011-04-08 01:23:27 PDT
***
Bug 39250
has been marked as a duplicate of this bug. ***
Mike Sherov
Comment 12
2012-01-07 21:02:50 PST
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: "the result of resolving the specified value insofar as possible without formatting the document, as defined in the "Computed value" line of the property definition tables." Indeed, Firefox resolves this correctly now, but alas IE9 and Opera do this incorrectly according to the spec. FWIW, It's also reared its head as a bug reported in jQuery:
http://bugs.jquery.com/ticket/9338
Ojan Vafai
Comment 13
2012-10-12 13:11:43 PDT
***
Bug 83867
has been marked as a duplicate of this bug. ***
Ojan Vafai
Comment 14
2012-10-12 13:14:20 PDT
Related CSSWG discussion
http://lists.w3.org/Archives/Public/www-style/2012Oct/0362.html
.
François REMY
Comment 15
2013-08-06 19:58:56 PDT
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't trigger any relayout nor too many observable effects.
Jan Fiegert
Comment 16
2016-09-30 01:42:06 PDT
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
Mike Sherov
Comment 17
2020-01-17 04:18:34 PST
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
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug