Bug Tracker

Ticket #6485 (closed feature: fixed)

Opened 5 years ago

Last modified 2 years ago

Solution for HTML5 in IE

Reported by: jonathantneal Owned by: rwaldron
Priority: high Milestone: 1.7
Component: core Version: 1.4.4
Keywords: html5,innershiv,innershim,needsreview,1.7-discuss Cc: paul.irish, SlexAxton
Blocking: Blocked by:

Description (last modified by rwaldron) (diff)

I wanted to propose some solutions to be used for some major HTML5 issues in IE6, IE7, and IE8, especially in regards to javascript and jQuery.

Issues / Solutions:

  1. HTML5 is not supported on a document, html5 elements will not properly contain contents
    • document.createElement('X') triggers support for 'X' element (you know this one, it's the "shiv I mean shim" method)
  2. HTML5 is not supported with innerHTML
    • HTML5 added with innerHTML is supported when the element being innerHTML'd is already appended to a shim'd document (or document fragment!)
  3. <HTML5_elements> become <:HTML5_elements> when element is cloneNode'd
    • use an alternate cloneNode function, the default is broken and should not be used in IE anyway (for example: it should not clone events)

Example of solutions, in action, with comments:

 http://pastie.org/935834


EDIT by paulirish.. the scope of this ticket it only to fix #2 and #3. the markup in the document will still require the basic html5shiv/modernizr to adjust.

this fix will correct the assumption that "jquery is broken" because it cannot handle ajax'd in html5 content and the like.

Change History

comment:1 Changed 4 years ago by rwaldron

  • Keywords needsreview added
  • Priority set to undecided

comment:2 Changed 4 years ago by rwaldron

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

comment:3 Changed 4 years ago by dmethvin

  • Keywords needsreview removed

Take a look at modernizr for this, it's kind of heavy to put into jQuery core because everyone would pay the price for it.

comment:4 Changed 4 years ago by SlexAxton

  • Status changed from closed to reopened
  • Cc paul.irish, SlexAxton added
  • Priority changed from undecided to high
  • Version changed from 1.4.2 to 1.4.4
  • Milestone changed from 1.4.3 to 1.5
  • Keywords html5, innershiv, innershim, needsreview added
  • Resolution invalid deleted

We've talked about different ways to handle this in the 1.5 feature list. I'm going to open this back up as something we are actively considering.

comment:5 Changed 4 years ago by paul.irish

#5327 is a duplicate of this ticket.

comment:6 Changed 4 years ago by paul.irish

  • Description modified (diff)

The major problem is dealing with new elements either ajax'd in or created on the fly... issue #2 of Jon's above.

More detail from the closed dupe #5327 is here: :  http://stackoverflow.com/questions/1191164/jquery-html5-append-appendto-and-ie

Test case:  http://jsfiddle.net/DVnmE/

Remy's test case:  http://jsbin.com/olizu

comment:7 Changed 4 years ago by john

  • Milestone set to 1.next

So right now we're looking for a good patch to this. I'm going to bring it up again for 1.7. If we had had a patch for 1.6, it probably would've landed then.

comment:8 Changed 4 years ago by timmywil

  • Status changed from reopened to open

comment:9 Changed 4 years ago by timmywil

#9049 is a duplicate of this ticket.

comment:10 Changed 4 years ago by john

  • Keywords html5,innershiv,innershim,needsreview,1.7-discuss added; html5, innershiv, innershim, needsreview removed

Nominating ticket for 1.7 discussion.

comment:11 Changed 4 years ago by rwaldron

  • Description modified (diff)

+1, I believe we said we'd try this, but I'm beginning to think we should first try out a plugin.

comment:12 Changed 4 years ago by jaubourg

+1, Gain is obvious but what is the cost in size?

comment:13 Changed 4 years ago by timmywil

+1, I would use this a lot.

comment:14 Changed 4 years ago by ajpiano

  • Description modified (diff)

+1, I'm for this and it would be a boon for many, but the problem isn't size - it's speed. We'd need to see a patch and do a lot of perf analysis..

Last edited 4 years ago by ajpiano (previous) (diff)

comment:15 Changed 4 years ago by paul.irish

+1, major painpoint for developers.

comment:16 Changed 4 years ago by dmethvin

+1, Fan of a team-supported solution, but first as a plugin and not in core for 1.7

comment:17 Changed 4 years ago by rwaldron

See also: #6286

comment:18 Changed 3 years ago by john

  • Description modified (diff)

+1, Only if this can be done in such a way that doesn't cripple performance.

comment:19 Changed 3 years ago by scott.gonzalez

+1, I'd like to see performance impact

comment:20 Changed 3 years ago by paul.irish

  • Description modified (diff)

I was working with jdbarlett on a new version of innerShiv  http://jdbartlett.github.com/innershiv/ that is much faster...

 https://gist.github.com/7e1c3c76db44e5a249ff is the general idea.

We feature test to see if the shiv is necessary, and we also regex against the input to see if we should even bother shiv'ing it. If it is, then we innerHTML it into an on-DOM div and grab the new childNodes which we'll use in a docFragment.

Currently it supports two signatures:

    innerShiv(htmlstring) // documentFragment
    innerShiv(htmlstring, false) // array of nodes

But that clearly could be simplified for its purposes within jQuery.

From a perf standpoints the questions I have are:

  • does the --- 1) add a node to the dom 2) innnerHTML inside of it 3) pull it off --- trick have a significant hit?
  • is the regex against the incoming string worth it?

I'm gonna be quite busy, but I'll try to take a stab at this within jQuery and get some perf numbers, sometime, if no one else beats me to it. Help requested :)

comment:21 Changed 3 years ago by addyosmani

  • Description modified (diff)

+1

comment:22 Changed 3 years ago by ajpiano

  • Description modified (diff)

+1, especially if we're able to limit its impact in the ways paul describes above

comment:23 Changed 3 years ago by jzaefferer

  • Description modified (diff)

+1

comment:24 Changed 3 years ago by paul.irish

  • Description modified (diff)

Started looking at the code around this and I'm gonna leave my notes, in case they can help someone else...

Talked with jdbarlett about this at TXJS and we agreed the shiv'ing approach within Shimprove  http://www.iecss.com/shimprove/ is probably a better choice here. Well, actually  the pastie jon linked in this issue's description has that code in a more readable format.

Essentially, that approach is this:

var frag = document.createDocumentFragment();
frag.createElement('abbr');
frag.createElement('aside');
// etc, ...

// fragment can now accept unknown element nodes

It looks like we'll want test coverage for:

  • html() when using the innerHTML shortcut fast path
  • clone()
  • append/prepend/before/after/replaceWith and appendto/prependto/insertbefore/insertafter/replaceAll and wrap/wrapInner/wrapAll ... all use domManip so really only a single code path there should be sufficient.

Implementation notes:

  • Appears as though everything is within manipulation.js
  • buildFragment() is used by domManip and looks to be the right place to improve things
  • a docFrag is made before sending it off to jQuery.clean() along with the html string. We could shiv it before clean or maybe within clean
  • We'll probably want a test in $.support to know if a browser collapses unknown elems.  The test used in Modernizr would work well.

Open questions:

  • regex to test against incoming html? (or some indexOf magic?)
  • There is an innerHTML set action inside of clean(). Does that collapse unknown elements, or no, since it's still off-dom?
Last edited 3 years ago by paul.irish (previous) (diff)

comment:25 Changed 3 years ago by paul.irish

WIP here:  https://github.com/paulirish/jquery/commits/ticket6485

  • unit test coverage and $.support.unknownElems added.

so far, the .innerHTML use from within clean() is looking like trouble that'll have to be worked around

comment:26 Changed 3 years ago by aspilicious

Drupal is working on his drupal8 release. We are planning to include shiv (inner shiv) stuff because we are going to go html5 all the way. BUT apparantly jquery is going to integrate those things for us in their next release.

Correct? When will this happen? 3 months? 6 months? a year? I would like to get this info so we can make a roadmap for drupal8.

Thnx!

comment:27 Changed 3 years ago by jon_neal

I tracked the bugs down to manipulation.js, within the clean function, specifically where html strings are converted into DOM nodes; the line that reads.

div = context.createElement("div")

This element is used to append the strings, and it's not part of a shimmed document. I successfully experimented by adding the following.

html5elementsArr = 'abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|subline|summary|time|video'.split('|'),
html5elementsArrLen = html5elementsArr.length,
html5elementsArrCar = -1,						
html5safeFrag = context.createDocumentFragment();
if (html5safeFrag.createElement) while (++html5elementsArrCar < html5elementsArrLen) html5safeFrag.createElement(html5elementsArr[html5elementsArrCar]);
html5safeFrag.appendChild(div);

Of course, this html5safe fragment could have been previously generated, but for experimental purposes it worked, completely. I ran the unit tests that Paul Irish shared, and loaded up old IE7 and IE8. They passed: 100%.

comment:28 Changed 3 years ago by paul.irish

I think we got success here. :)

I can take point to integrate that code in jquery style, commit that and PR it.

The test suite index.html will also need the basic html5 shiv run on it for some of these new tests to pass in IE. I hope that's okay.

comment:29 Changed 3 years ago by paul.irish

Committed Jon's raw patch to my branch..  https://github.com/paulirish/jquery/commits/ticket6485

snover indicates we'll probably need a test similar to  https://github.com/jquery/jquery/commit/0a0cf/#diff-1

for this patch.

comment:30 Changed 3 years ago by rwaldron

Is there anyway that we can handle creation of elements without maintaining an internal hard-coded list? I seem to recall seeing something somewhere...

comment:31 Changed 3 years ago by ajpiano

  • Milestone changed from 1.next to 1.7

comment:32 Changed 3 years ago by john

#9496 is a duplicate of this ticket.

comment:33 Changed 3 years ago by paul.irish

snover gave some feedback to Jonathan the day we were working on this that was useful so I tracked it back down and it's cleaned up and available here  http://oksoclap.com/fNZvdYRdAU

comment:34 Changed 3 years ago by dmethvin

  • Owner set to rwaldron
  • Status changed from open to assigned

comment:35 Changed 3 years ago by rwaldron

Worked on this today, but ultimately, I'm hitting walls. Here are screen shots of one of the tests when I pull the branch as-is (resolving a minor conflict is required)

IE8  http://gyazo.com/950889903bb10ad7e947ef221b9b2a16.png

IE7  http://gyazo.com/127aca2933a2f3905bdcc80ba07ae23f.png

IE6  http://gyazo.com/4a16f40faf1fe6c4da40b83949d359c8.png

When I change the test to use:

article.width()

The result changes in IE8

 http://gyazo.com/f524046a6b4b7aa51ab83f2adb54c804.png

Last edited 3 years ago by rwaldron (previous) (diff)

comment:36 follow-up: ↓ 37 Changed 3 years ago by rwaldron

More research stuff...

Running this fiddle:  http://jsfiddle.net/rwaldron/t6hqK/show

Produces the following results:

 http://gyazo.com/4f54690fa9126ea78285b71518d97c76.png

Version 0, edited 3 years ago by rwaldron (next)

comment:37 in reply to: ↑ 36 Changed 3 years ago by jonathantneal@…

rwaldon, unless specified by the browser or the CSS, elements are display: inline by default, so IE is handling them the way it would normally handle inline elements

Running this fiddle:  http://jsfiddle.net/t6hqK/5/show/

Produces the following results in IE6:  http://s4.postimage.org/5hrhkupqg/ie6_html5.png

comment:38 Changed 3 years ago by paul.irish

  • Description modified (diff)

comment:39 Changed 3 years ago by rwaldron

comment:40 Changed 3 years ago by rwaldron

#10283 is a duplicate of this ticket.

comment:41 Changed 3 years ago by Haprog

+1, I just spent a whole day at work figuring out why my code breaks on IE8 and older. It would really help if there was a good solution to this issue.

comment:42 Changed 3 years ago by rwaldron

@Haprog This is coming in 1.7, barring any disastrous findings :)

comment:43 Changed 3 years ago by Rick Waldron

  • Status changed from assigned to closed
  • Resolution set to fixed

Landing pull request 490. 1.7 HTML5 Support for innerHTML, clone & style. Fixes #6485.

More Details:

comment:44 Changed 3 years ago by ajpiano

#10427 is a duplicate of this ticket.

comment:45 Changed 3 years ago by bmustiata

If I may, I think this issue should be extended to really support unknown elements for IE7/8. The problem is that the current implementation has a list of unknown elements.

This causes in my view (at least) two problems:

  1. If tomorrow html5 decide to add a new element, old versions of the applications that use the current jQuery version will suddenly stop working until they upgrade their jQuery, and for any new element this list must be upgraded.
  2. This approach also doesn't allow custom elements to be created that are not (and will never be) part of HTML5. We are actually using this in an application, where we create custom rendered metadata nodes on the fly (we receive them via AJAX). Elements are things like <loop>, <metatarget>, etc.

I am currently working on a fork where I try to allow creation of completely unknown elements, because currently (in the 1.7 beta):

jQuery('<customelement>some content</customelement>');

has a different outcome in IE8 than in IE9 (or any other decent browser).

I hope you find these requirements acceptable for reopening this, or even better in my opinion reopening the duplicate issue 10427. (since HTML5 support is implemented, and only custom elements are not working).

comment:46 Changed 3 years ago by jdbartlett

Perhaps it'd be more appropriate to open a new bug for this (please yell if so), but it looks like this has been marked "fixed" prematurely; I tried innerShiv's test page with jQ1.7b2 and Test 2 (which checks for innerShiv support built into jQuery) fails in IE8 :o :( :_(

 http://jsbin.com/igerig

Looking at the DOM tree, IE seems to be recognizing the elements properly, and I can style them if I use class names, but it's not styling based on tag names alone.

comment:47 Changed 3 years ago by rwaldron

  • Description modified (diff)

I'm not at a machine that I can test from, but the first thing that comes to mind is that you'll still need to shiv/shim (whatever) the elements themselves - jQuery has no intention of providing that.

comment:48 Changed 3 years ago by rwaldron

  • Description modified (diff)

Sorry, my mobile browser seems to like to remove urls from the original description text

comment:49 Changed 3 years ago by anonymous

Yeah, innerShiv's test page includes Rem's HTML5shim (otherwise none of the tests would pass at all) -- it's actually the test set I used when developing the original innerShiv. jQuery 1.7's HTML5 support is substantially the same technique as innerShiv, which is why it's so odd that this isn't working. Either I've done something really stupid in the test page, or something's going on between the HTML being cleaned and appended that's causing the breakage.

comment:50 Changed 3 years ago by jdbartlett

(That last "anonymous" was me again, BTW!)

comment:51 Changed 3 years ago by rwaldron

Would be nice if all of those tests appeared on screen without the need for scrolling. I screen capped this:  http://gyazo.com/d02e3887ccc6c561915421e43cad02b8.png running in IE7 via BrowserStack - not sure if that's even useful or meaningful

comment:52 Changed 3 years ago by jdbartlett

It's just the 2nd test that's affected (the other tests use innerShiv). Here's another version with the other tests removed:

 http://jsbin.com/igerig/3

Expected result (seen in IE9 and good browsers):  http://d.pr/MKFP Actual result (seen in IE6, IE7, IE8):  http://d.pr/SSZk

HTML5shim is included (line 27 of the source). Line 51 of the source shows the test that's being used.

comment:53 Changed 3 years ago by rwaldron

Maybe I'm missing something... I see the same thing in both screenshots.

comment:54 Changed 3 years ago by jdbartlett

Ah. The section element's background color in the IE<=8 screenshot is red, whereas it's red in the IE9 screenshot.

But never mind that! Here's an even simpler demonstration:

 http://jsbin.com/obomec

In this demonstration, jQuery appends a section to an article. The CSS uses the "section" tag as a selector to style the section's background pink. Works in all good browsers, but not in IE <= 8. :(

Here's exactly the same code, but using a class name ("pink") instead of an HTML5 tag name as a selector:

 http://jsbin.com/obomec/2/

When using a class name as a selector instead of a tag name, the page is styled successfully.

innerShiv uses _exactly_ the same technique as the jQuery 1.7 fix, but I've never before encountered this problem with being able to style based of class selectors but not tags, which is why I suspect something's happening between the innerShiv fix and the append.

Hope that helps clarify the problem.

comment:55 Changed 3 years ago by jdbartlett

"The section element's background color in the IE<=8 screenshot is red, whereas it's red in the IE9 screenshot."

Ugh. Obviously, I meant to say:

"The section element's background color in the IE<=8 screenshot is red, whereas it's GREEN in the IE9 screenshot."

GREEN! GREEN, damn it! There is a difference! Honest! :)

But anyway. The other demonstration is much easier code to read.

comment:56 Changed 3 years ago by rwaldron

comment:57 Changed 3 years ago by heruan@…

Is the cloning issue fixed? I still get <:section></:section> on cloned <section>s in IE8 (with jQuery 1.7 and html5shiv).

comment:58 Changed 3 years ago by rwaldron

Fix is coming in 1.7.1

comment:59 Changed 3 years ago by anonymous

I'm using 1.7.1 and I still get the ":"-bug using clone(). Are there any news regarding this bug?

comment:60 Changed 2 years ago by anonymous

This is still happening as of 1.8, anyone have a fix for this they would like to share?

comment:61 Changed 2 years ago by dmethvin

This is still happening as of 1.8, anyone have a fix for this they would like to share?

I have no idea what "this" you are referring to but I am sure it can be answered better on a forum than on a closed bug tracker ticket.

comment:62 Changed 2 years ago by anonymous

I think 'this' is referring to cloning still not working. I have the same problem using 1.8.2 with Modernizr 2.6.1.

Note: See TracTickets for help on using tickets.