Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14736 closed bug (fixed)

window.getDefaultComputedStyle(elem) may return null

Reported by: rr.rosas@… Owned by: rr.rosas@…
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

Change History (13)

comment:1 Changed 6 years ago by dmethvin

Owner: set to rr.rosas@…
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.

comment:2 Changed 6 years ago by rr.rosas@…

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?

comment:3 Changed 6 years ago by rr.rosas@…

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

comment:4 Changed 6 years ago by dmethvin

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.

comment:5 Changed 6 years ago by anonymous

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.

comment:6 Changed 6 years ago by dmethvin

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.

comment:7 Changed 6 years ago by rr.rosas@…

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.

comment:8 Changed 6 years ago by rr.rosas@…

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

comment:9 Changed 6 years ago by dmethvin

Component: unfiledcss
Priority: undecidedlow
Status: newopen

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

comment:10 Changed 6 years ago by anonymous

Ok, thank you.

comment:13 Changed 6 years ago by Rodrigo Rosenfeld Rosas <rr.rosas@…>

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")};
  };
}

})();

comment:14 Changed 6 years ago by dmethvin

Milestone: None1.12/2.2

comment:13 Changed 6 years ago by Rodrigo Rosenfeld Rosas

Resolution: fixed
Status: openclosed

CSS: window.getDefaultComputedStyle may return null

Fixes #14736 Closes gh-1501 (cherry picked from commit 51910ba8a5aff4cd1a811f1fdb76a6c62a09a666)

Changeset: e547a2775fc79e4b2eb807da9d30719afc570458

Note: See TracTickets for help on using tickets.