Last modified: 2011-04-20 21:22:34 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T30413, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 28413 - Loading CSS with mw.loader.load crashes IE
Loading CSS with mw.loader.load crashes IE
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
ResourceLoader (Other open bugs)
1.17.x
All Windows XP
: Normal major (vote)
: ---
Assigned To: Krinkle
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-04 10:11 UTC by Michael M.
Modified: 2011-04-20 21:22 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Michael M. 2011-04-04 10:11:47 UTC
Adding a CSS file via mw.loader.load causes Internet Explorer (tested: IE 8.0/Win XP) to reload the page telling you a serious problem occured.

To reproduce enter

javascript:void(mw.loader.load('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css&action=raw&ctype=text/css', 'text/css'))

as adress.
Comment 1 Krinkle 2011-04-04 10:26:45 UTC
Going to javascript:void(mw.loader.load('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css&action=raw&ctype=text/css','text/css')); doens't do anything weird for me in IE7 and IE9 beta. I don't have IE8 here tho.
Comment 2 Michael M. 2011-04-05 07:30:21 UTC
I found this bug in jQuery's bug tracker:
http://bugs.jquery.com/ticket/4230

The solution there seems to work:

$( 'head' )
 .append( $( '<link />' )
           .attr( 'rel', 'stylesheet' )
           .attr( 'type', 'text/css' )
           .attr( 'href', modules ) )
Comment 3 Trevor Parscal 2011-04-05 18:25:31 UTC
Well, mediaWiki.loader.load uses..

$( 'head' ).append( $( '<link rel="stylesheet" type="text/css" />' ).attr( 'href', modules ) );

So, are we saying that using some of the attributes in the initial HTML string is the difference between IE crashing or not?
Comment 4 Krinkle 2011-04-06 16:46:20 UTC
(In reply to comment #3)
> Well, mediaWiki.loader.load uses..
> 
> $( 'head' ).append( $( '<link rel="stylesheet" type="text/css" />' ).attr(
> 'href', modules ) );
> 
> So, are we saying that using some of the attributes in the initial HTML string
> is the difference between IE crashing or not?

Well, not by definition. The difference is that this:

$( '<link />' )

Will cause jQuery's quick regex to pick it up and use document.createElement, whereas anything more complicated makes it append it to a <div> and get the inner child(ren).

http://api.jquery.com/jQuery#jQuery2 states:

* "When the HTML is more complex than a single tag without attributes [..] the actual creation of the elements is handled by the browser's innerHTML mechanism. In most cases, jQuery creates a new <div> element and sets the innerHTML property of the element to the HTML snippet that was passed in. "
* "When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided."
* "To ensure cross-platform compatibility, the snippet must be well-formed."

This was also the cause of a few bugs in the makeCollapsible plugin which used "<span></a></span>" to quickly create a wrapped anchor tag (works fine in WebKit-browsers), but goes bad in (some) IE versions.

I think Internet Explorer wants link-tags to be closed instead of self-closing. Either way, the solution is by using the native createElement function.

In other words (as, in a way, Trevor already said): "[attributes] in the initial HTML string is the difference between IE crashing or not". Yes :-D
Comment 5 Trevor Parscal 2011-04-06 16:49:01 UTC
Thank you for the excellent input! This is an incredibly easy fix, has anyone verified this actually prevents IE from crashing?
Comment 6 Owltom 2011-04-20 20:02:30 UTC
I can confirm (as of r86333):

a) loading CSS with mw.loader.load crashes IE 7 & IE 8 (tested in XP)

b) the solution (comment2) works and does not crash IE 7 oder 8
Comment 7 Krinkle 2011-04-20 21:22:34 UTC
Fixed in r86548.

Used the new method as of jQuery 1.4 to populate attributes instead of chained .attr() calls.

Should fix IE problems and it's slightly faster as well.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links