Bug Tracker


Ticket #12904 (closed bug: fixed)

Opened 17 months ago

Last modified 17 months ago

.show()ing CSS hidden elements fails permanently if iframes are hidden during first try

Reported by: maranomynet Owned by: maranomynet
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.3
Keywords: Cc:
Blocking: Blocked by:


Affects all versions of jQuery 1.8 in Firefox 16 (at least)

This is kind of an obscure bug and it's kind of hard to explain, but real easy to fix.

Here's a reduced, annotated demo:  http://jsfiddle.net/qT4Tg/ with a proposed fix (patch) attached in a comment.

Change History

comment:1 Changed 17 months ago by maranomynet

I reduced the demo a bit more:  http://jsfiddle.net/qT4Tg/1/

comment:2 Changed 17 months ago by maranomynet

It occurred to me that the same happens if body or html are set to display:none; ... so that might require a second check before css_defaultDisplay caches the result.

Here's a quick patch for jQuery 1.8.3 showing how this can be accomplished:

< 		iframe = document.body.appendChild(
< 			iframe || jQuery.extend( document.createElement("iframe"), {
< 				frameBorder: 0,
< 				width: 0,
< 				height: 0
< 			})
< 		);
> 		if ( !iframe )
> 		{
> 			iframe = document.createElement("iframe");
> 			iframe.frameBorder = 0;
> 			iframe.width = 0;
> 			iframe.height = 0;
> 			// Hidden iframes always rport display as 'none' in Firefox 17
> 			// Note: Hidden body might still result in a hidden iframe
> 			iframe.style.cssText += "display: block !important;";
> 		}
> 		document.body.appendChild( iframe );
< 	// Store the correct default display
< 	elemdisplay[ nodeName ] = display;
> 	if ( display === "none"  &&  curCSS( document.body, "display" ) === "none" )
> 	{
> 		// document.body won't hide forever,
> 		// so let's go for "block" for now, and not cache the result.
> 		display = "block";
> 	}
> 	else
> 	{
> 		// Store the correct default display
> 		elemdisplay[ nodeName ] = display;
> 	}

comment:3 Changed 17 months ago by dmethvin

  • Owner set to maranomynet
  • Status changed from new to pending

How does this differ from the parent-hidden case, which we also do not handle? These are relatively expensive operations so it is better to have the user write code that doesn't expect us to do these things under the covers.

comment:4 Changed 17 months ago by maranomynet

  • Status changed from pending to new
  1. This is a clear regression in 1.8
  2. It works perfectly in all browsers except Firefox.
  3. Simply setting iframe to display:none; triggers this - even though the iframe is not the affected element's parent.
  4. And even for the body hidden case - which is strictly speaking "parent-hidden" case - it still differs because it causes all future attempts to .show() the affected elements to fail - even after the body/html have been made visible.


Regarding the added operational expense, is not as great as you may think:

In iframe-hidden case we need to add a single operation iframe.style.cssText += "display: block !important;"; which is probably offset by changing from jQuery.extend() to direct property assignments.

In the body hidden case there's one extra curCSS(document.body,"display") invocation - that only happens in the highly unusual case when display==='none'. Someone more clever than me might even come up with an even faster method for that...

comment:5 Changed 17 months ago by dmethvin

Good points on the bug and impact, broken-forever is not good. Can you put together a pull request?

comment:7 Changed 17 months ago by rwaldron

I'm curious about what lead to this "regression".

comment:8 Changed 17 months ago by rwaldron

  • Status changed from new to pending

This behaviour exists as far back as 1.6.4 (what happened to all of our older versions on jsfiddle?)

1.6.4  http://jsfiddle.net/rwaldron/7htPw/ 1.7.2  http://jsfiddle.net/rwaldron/K69P7/

The reason we use an iframe with height: 0, width: 0 and frameborder: 0 is because Firefox doesn't have "presentation" for an iframe with display: none.

I've adapted your solution to a more suitable patch that includes tests. The only change that's necessary to fix this issue is the addition of iframe.style.cssText = "display: block !important"; after the iframe is created. You can either update your patch or I can merge mine.


comment:9 Changed 17 months ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:10 Changed 17 months ago by Richard Gibson

  • Resolution changed from invalid to fixed

Fix #12904: Firefox defaultDisplay with body/iframe display:none. Report and solution by @maranomynet; test by @rwldrn.

Changeset: d343e6b9ed501052f1676694d5e53649c92e65a0

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Add a comment

Modify Ticket

as closed

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.