Skip to main content

Bug Tracker

Side navigation

#14736 closed bug (fixed)

Opened January 28, 2014 06:29PM UTC

Closed March 20, 2014 06:43PM UTC

window.getDefaultComputedStyle(elem) may return null

Reported by: rr.rosas@gmail.com Owned by: rr.rosas@gmail.com
Priority: low Milestone: 1.12/2.2
Component: css Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:
Description

In Iceweasel 24.2.0 it happens here when I call layout from jQuery layout plugin in an iframe from an invisible tab (from jQuery UI tabs).

I've created this ticket after the PR:

https://github.com/rosenfeld/jquery/commit/ab632f868e620246edbc11564f4bb83b68042ed0

Attachments (0)
Change History (13)

Changed January 28, 2014 06:33PM UTC by dmethvin comment:1

owner: → rr.rosas@gmail.com
status: newpending

The description sounds rather complicated. Can you post a simplified test case that only uses jQuery core? If it's only happening in one browser it could be a browser bug, but we'd need a test case to be sure. We'll also need one anyway to include in our unit tests.

Changed January 28, 2014 06:39PM UTC by rr.rosas@gmail.com comment:2

status: pendingnew

Sorry, but I don't think I'll have time to work on a project and try to replicate the issue using jQuery core only. It only seems to happen in Firefox. Please believe on me when I say that window.getDefaultComputedStyle may return null (or undefined, don't remember) for this browser.

Also, unfortunately the application I maintain is not open-source so I can't point it to you either (it's available in the web, but require user/password).

Is that really mandatory?

Changed January 28, 2014 06:42PM UTC by rr.rosas@gmail.com comment:3

It returns null actually (not undefined), I just checked.

Changed January 28, 2014 06:45PM UTC by dmethvin comment:4

status: newpending

I understand, we all have work to do. Yes, we need a test case to understand what is happening. We can't just add a bunch of tests for bad return values and then wonder a year later why they are there, with no way to know whether the problem is resolved. We don't need (or want!) to see the whole application or code that involves jQuery UI and third-party plugins, just a test case that shows a valid call to a jQuery core method that causes the problem.

Changed January 28, 2014 06:45PM UTC by anonymous comment:5

In Firefox console I could get it to return null this way:

$('iframe:first')[0].contentWindow.getDefaultComputedStyle($('body')[0])

It doesn't matter if the element is on the parent window or in the iframe itself.

Not sure if this is a required condition, but $('iframe:first').is(':visible') returns false.

Changed January 28, 2014 06:48PM UTC by dmethvin comment:6

You're using the getDefaultComputedStyle of the iframe's window but passing it the <body> element from the parent. I wouldn't expect that to work.

Changed January 28, 2014 06:51PM UTC by rr.rosas@gmail.com comment:7

status: pendingnew

How about this? http://jsfiddle.net/b6Kv5/1/

$(function(){

var iframe = $('iframe:first')[0];

$('body').text(iframe.contentWindow.getDefaultComputedStyle(iframe.contentDocument.body));

});

It still output nulls, as I said before. It doesn't matter if the element belongs to the iframe or master, getDefaultComputedStyle from an iframe doesn't seem to work in Firefox.

Changed January 28, 2014 06:53PM UTC by rr.rosas@gmail.com comment:8

And yes, the iframe being hidden is a required condition for that function to return null.

Changed January 28, 2014 07:05PM UTC by dmethvin comment:9

component: unfiledcss
priority: undecidedlow
status: newopen

Ok, that's enough info for us to look into it.

Changed January 28, 2014 07:20PM UTC by anonymous comment:10

Ok, thank you.

Changed January 28, 2014 10:07PM UTC by Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com> comment:11

Oops, I posted it too soon. The return value was wrong in the previous examples. Fixed version of workaround:

(function(){

if (window.getDefaultComputedStyle) {
  var old = getDefaultComputedStyle;
  window.getDefaultComputedStyle = function(elem) {
    if (var style = old(elem)) return style.display;
    return {display: $.css(elem, "display")};
  };
}

})();

Changed February 07, 2014 02:15AM UTC by dmethvin comment:12

milestone: None1.12/2.2

Changed March 20, 2014 06:43PM UTC by Rodrigo Rosenfeld Rosas comment:13

resolution: → fixed
status: openclosed

CSS: window.getDefaultComputedStyle may return null

Fixes #14736

Closes gh-1501

(cherry picked from commit 51910ba8a5aff4cd1a811f1fdb76a6c62a09a666)

Changeset: e547a2775fc79e4b2eb807da9d30719afc570458