-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing jQuery HTML parsing by default is breaking #1880
Conversation
I don't disagree with either approach (reverting to The actual wrapping is not too complex, really just wrapMap and buildFragment. Comparing from ko's parser to the list of "hoistable tags" in jQuery 1.9.1, which is:
... only a few are missing. It doesn't look tremendously difficult (at first glance, at least) to patch KO to do the missing elements correctly. That said, if jQuery already does it, that certainly keeps KO cleaner. To get 3.4 out sooner, I'd say Perhaps we might note in the documentation the problems with Glad you were checking this out, @SteveSanderson. |
So .... I've experimented with this a little, and may have devised something useful for browsers that support the > d = document.createElement('div')
<div></div>
> d.innerHTML = '<tr></tr>'
"<tr></tr>"
> d.innerHTML
""
// ^^ Uh oh. This is why we need all those workarounds.
> t = document.createElement('template')
<template>…</template>
> t.innerHTML = '<tr></tr>'
"<tr></tr>"
> t.innerHTML
"<tr></tr>"
// ^^ Happy dance? ... meaning on browsers that support the If this is a viable option, for "legacy" browsers I think we ought to keep the current and jQuery parsing, but document the caveats (the dash-checking-workaround @mbest suggested is IMO probably also worthwhile). In other words, I'm proposing that we not change parsing too much now, because we might want to test the template tag option in future, because it may solve the problem more elegantly. To know for sure we'll have to wait for the ongoing IE-Edge support of the template tag to wrap up. Thoughts? |
Just ran the small patch above through, expanding the tests slightly and adding a Travis-CI test results – only issue is IE 7 and Also, I've not yet added comments-before-tags parsing |
So the strategy for parsing in the branch I've created (#1881) is:
Parsing HTML via a To support the The regular expression might really slow things down, but will be 110% accurate (the extra 10% is for the false-positives like Newer browsers using This feels like the most correct option and the most forward-looking, but comes at the expense of speed for legacy support. Thoughts? |
If the regular expression causes a huge performance issue with detecting the |
I found that the |
Here's what I think we should do:
|
Thanks @mbest. I'm okay with that. Unless there's a pressing desire to get the template-tag parsing in, I am fine with it going into 3.5.0 (or whenever it makes sense). Template-tag parsing will invariably be faster and simpler, but there's probably a bit of risk to it (particularly with IE Edge 13 being untested, though I did review the W3C spec and compliance with the spec should mean it'll work as we expect it to). |
@mbest - I think the plan that you outlined sounds very reasonable |
…versions fail with certain tags.
@@ -40,7 +40,7 @@ | |||
if (url) { | |||
var shouldInclude = getParam(name); | |||
if ((dependency.include || shouldInclude) && shouldInclude !== "0" && shouldInclude !== "false") { | |||
if (shouldInclude && /^[0-9]+\.[0-9.]+$/.test(shouldInclude)) { | |||
if (shouldInclude && shouldInclude !== "1" && shouldInclude !== "true") { | |||
url = url.replace(dependency.versionString || 'latest', shouldInclude); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change allows the use of jquery=git
to test with the 3.0.0-pre version.
So this should be ready to merge. Hopefully this is the last code change for 3.4.0. |
Removing jQuery HTML parsing by default is breaking
…current versions fail with certain tags." This reverts commit b85e327. re. knockout/knockout#1880 # Conflicts: # spec/lib/loadDependencies.js
I was originally hopeful that we could stop piggybacking on jQuery's HTML parser, at least for modern browsers. But after attempting to upgrade my current project to KO 3.4.0, I can see it's a bit more complicated than that!
Some things that the
$.parseHTML
handles that KO's built-in parser doesn't (even on modern browsers):<col>
and<colgroup>
elements and probably others like<legend>
<thead>
prefixed by comments or whitespace, e.g.,<!-- ko something --><thead>...</thead>
For KO 3.4.0 to ship without pretty bad breaking changes here, I think we need to:
$.parseHTML
when available by default (possibly with someko.options
flag to disable that, but it shouldn't be the default)Looking at jQuery's source for
$.parseHTML
, I don't feel too enthusiastic about putting that much stuff into KO, so am leaning towards "go back to using jQuery's parser again". I know that jQuery's parser doesn't handle certain bizarrely-named custom elements (e.g.,<th-mything>
) but that's much more of an edge case than standard elements like<col>
that jQuery does support.Thoughts?