Bug Tracker

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#12904 closed bug (fixed)

.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:
Blocked by: Blocking:


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 (10)

comment:1 Changed 5 years ago by maranomynet

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

comment:2 Changed 5 years 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 5 years ago by dmethvin

Owner: set to maranomynet
Status: newpending

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 5 years ago by maranomynet

Status: pendingnew
  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 5 years 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 5 years ago by Rick Waldron

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

comment:8 Changed 5 years ago by Rick Waldron

Status: newpending

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 4 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

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 4 years ago by Richard Gibson

Resolution: invalidfixed

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

Changeset: d343e6b9ed501052f1676694d5e53649c92e65a0

Note: See TracTickets for help on using tickets.