-
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
Knockout cannot process component template correctly if it is loaded by element identifier (IE 11). #1836
Comments
Interesting problem. I can confirm it happens for me too (IE 11 on Windows 8.1) @brianmhunt - I wonder if this is what's causing grief for the new KO docs site in IE? I recall reading this morning in your blog post that you concatenate all of the templates into a single file. Presumably they're referenced by their id in a manner similar to that described in this issue. |
@IanYates Ahh yes, that may indeed be the issue. @maxim-boligatov Does the problem exhibit in IE when you rewrite the If that does work, then one can do a javascript polyfill for the |
@brianmhunt - just tried script tags. They work a treat - http://jsfiddle.net/qp49uz0v/18/ :) |
Thanks @IanYates ; looks like So it looks like this is not a Knockout issue per se, but an IE problem. We all have to fall back on a polyfill for IE support. This being an IE issue I'm not sure what we could be doing better in KO here. @maxim-boligatov if you think there's still something KO could be doing better here please let me know. In the mean time I'll close this, but happy to reopen if there's more to discuss or something else to be done here. Thanks and cheers. |
I have posted previous comment too early. So I wrote new one. <template id="common-account">
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
</template>
<common-account></common-account> var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.pureComputed(function() {
return this.firstName() + " " + this.lastName();
}, this);
};
var trick = document.getElementById('common-account');
var template = trick.innerHTML;
trick.parentNode.removeChild(trick);
ko.components.register("common-account", {
template: template,
viewModel: {
createViewModel: function (params, componentInfo) {
var viewModel = new ViewModel("User", "Trick");
return viewModel;
}
},
synchronous: true
});
ko.applyBindings(); |
Thanks @maxim-boligatov & @IanYates – I think I see this now. Sorry, it takes me a minute. 😁 I am guessing that at components/defaultLoader.js#L168-L170 we'd want something like: if (isDocumentFragment(elemInstance.content)) {
return ko.utils.cloneNodes(elemInstance.content.childNodes);
}
// Fallback where <template> tag is not natively supported. See #1836.
return ko.utils.parseHtmlFragment(elemInstance.innerHTML); I really don't know what IE is doing, so I'm only speculating at a patch here. The fallback of @mbest Do you think the potential patch here could be this simple? Any insight into what's going on? |
@brianmhunt, I'll take a look. |
This is already fixed. See issue 1783. |
Thanks @chessels for reminding us. We need to get 3.4.0 out the door! |
The following code works fine in Firefox, Chrome, Opera, but does not work in IE (at least in IE 11):
To explain solution I have created jsfiddle: http://jsfiddle.net/qp49uz0v/16/
It raises exception that firstName is undefined.
IE works fine as well only if template is specified as string (like it is here: http://jsfiddle.net/47e2gpqq/4/).
The text was updated successfully, but these errors were encountered: