Knockout.js 3.4.1 throws multiple bindings error - javascript

I'm working on a rather large project where I use KnockoutJS (large as in it would be impossible to post all related code here), and today I upgraded from Knockout 3.4.0 to 3.4.1. After doing this, I am suddenly getting a multiple bindings-error on every pageload ("You cannot apply bindings multiple times to the same element").
I have been using Knockout for a while, and I am very confident that I am in no way applying bindings multiple times to the same element. I only call applybindings once, and I have confirmed that this statement also only ever runs once by debugging that code (and also searching for any other instances of this function).
After debugging this problem for I while, I decided to downgrade again, to Knockout 3.4.0. And as it turns out, the error is only showing up on the latest build, version 3.4.1.
Anyone else noticed this behaviour? What did they change to cause this?
Even when I run the debug-version of KO, the error can not tell me what element it is referring to, which makes it hopeless to figure out where the error actually comes from.
I am also not using the second optional parameter when calling applybindings (no specific element target), as I am only doing this once anyway.

5 months after your question someone raised an issue with the same problem on their Github page. It was fixed here.
Brian M Hunt's (one of the owners) comment:
The issue was that the valueAccessor() needed to be called (if it's a function) to create the dependency. I believe I have the right fix for it in TKO (basically if (typeof valueAccessor() === 'function') {valueAccessor()()} in the render loop), but the TKO fix doesn't back-port/translate directly since it's using the new binding class style.

Related

Browser.ExecScript() stopped working after updating windows

I've set up a simple testbed for WatiN (ver 2.1) which reads:
var browser = new IE();
browser.GoTo("http://www.google.co.il"); // webpage doesn't matter really
browser.RunScript("alert(123)");
This works only if KB3025390 is not installed. Installing it breaks the above test with an UnAuthorizedAccessException which has HRESULT set to E_ACCESSDENIED. What gives? Is there any workaround?
Update: Using IWebBrowser2.Navigate2 along with "javascript:console.log(123)" type of scripts works however
it makes me feel uneasy using such a backchannel
the scripts run through this back-channel of .Navigate2() may only have a max length of about 2070 chars (give or take) otherwise they get forcibly truncated to this length leading to javascript errors upon attempting to run them
using .Navigate2(), even with the most trivial script, will clog the ready state of Internet Explorer for good in the sense that it will be set to READYSTATE_LOADING without any hope of getting rid of it. In simple terms this means that once you use this hack, you either have to perform every single subsequent operation in WatiN in a "dont-wait-for-webpage-to-load" fashion (GoToNoWait, ClickNoWait etc) lest your code freezes upon waiting for the browser to turn back to READYSTATE_COMPLETE (which will never come about ofcourse as already mentioned).
there appears to be a much broader issue here in the sense that I can't even access the properties of an IHtmlWindow2 object p.e. window.document throws an unauthorized exception again making it virtually impossible to transfer over to the C# world the return-values of the scripts I'm running (using Expando etc) for documents other than window.top.document (for the window.top.document window there is IWebBrowser2.Document which does the trick)
Update#2: The folks over at the selenium project have also noticed this issue:
https://code.google.com/p/selenium/issues/detail?id=8302
A bug report has been created as well:
https://connect.microsoft.com/IE/feedback/details/1062093/installation-of-kb3025390-breaks-out-of-process-javascript-execution-in-ie11
Update#3: IHTMLWindow2.setInterval and IHTMLWindow2.setTimeout also throw UnauthorizedAccess exceptions. These methods are not marked as deprecated in:
http://msdn.microsoft.com/ko-kr/library/windows/desktop/aa741505%28v=vs.85%29.aspx
yet they have wounded up suffering from the same cutbacks all the same.
Update#4: I gave the approach recommended in this post a shot:
https://stackoverflow.com/a/18546866/863651
In order to dynamically invoke the "eval" method of the IHTMLWindow2 object (or any other method really). Got the same "System.UnauthorizedAccessException" as above. So no joy here either.
Microsoft recommends using "eval" over "execscript" however after the above experiment I suspect that they are refering to accessing "eval" only from within the browser.
As far as I can tell thus far, when it comes to the full-fledged IE11+ using "eval" out-of-process (via COM) appears to have been completely prohibited along with any other function-invocation of the window object, the only exception being the back-channel of the .Navigate2() mentioned above.
It turns out Microsoft eventually backpedaled on its decision to kill off .execScript at COM-level. Just install the latest updates for Windows including kb3025390: One of the updates for IE that came after kb3025390 brings back .execScript functionality at COM-level
Note, however, that .execScript is not accessible through IE's javascript anymore. In that context it's gone for good.
fyi: this one is also not working
ieInstance.Document.Script.<methodNameString>(<commaSeperatedParameterString>)
try this worked for me at some places but not all places
ieObject.Navigate "javascript:<methodNameString>(<commaSeperatedParameterString>)", Null, "_parent"
or
ieObject.Navigate2 "javascript:"<methodNameString>(<commaSeperatedParameterString>)", Null, "_parent"
now trying to find out solution using eval
I have found a way around the problem of an update installing automatically. You can just create a simple batch file with following content.
{code}
#echo off
wusa /uninstall /kb:3025390/quiet /norestart
END
{code}
Then go to task scheduler, create a new task for this batch file to run every one hour or day as per your requirements. Add it as a system task so it runs in the background and does not affect the running automations.

BreezeJS RequireJS support unstable (knockout example)

As I'm trying to compile my project with breeze and requirejs for production, I'm running into multiple issues. Unrolling this, I tried starting fresh with the Knockout RequireJS example.
After I installed MVS2013Pro I was able to run the project, but not without issues:
window.breeze is defined so it has been leaked to global scope (this
should not happen with RequireJS)
Hitting F5 Refresh will crash with
Uncaught Error: Can't find breeze and/or Q (breeze savequeuing)
Uncaught TypeError: undefined is not a function (breeze dataservice)
With these errors I'm not even trying to establish my grunt requirejs (r optimizer) task. As these are the root of my problems.
Note: I'm not searching for a knockout solution, my stack actually is: MongoDataService+Breeze+SaveQueueing+RequireJS+AngularJS+Socket.IO+Cordova
window.breeze
You're right that breeze sneaks back into the browser way down at the bottom of breeze.debug.js:
if (global.window) {
global.window.breeze = breeze;
}
We don't know why we put that in the code base. No one remembers. Coming at the end as it does, it clearly isn't needed by Breeze itself.
I commented it out in preliminary testing and that seems to do the trick. The window.breeze becomes undefined in the Todo-KO-Require sample; it remains defined (properly) in samples that do not use require.js.
We don't think this would be a breaking change for anyone ... and the remedy is simple enough: define it yourself at the top of your app.
We'll probably remove these lines for the next release unless we discover a reason to do otherwise.
F5 fail?
I can't repro this at all. I suspect your are conflating your discovery that breeze is inadvertently in the global namespace with your efforts to write an Angular app that uses breeze.savequeuing.js.
Why do I think this? Because the error you describe arises when trying to use breeze.savequeuing.js in an Angular app which is explicitly disallowed in the comments (line #14) of v.1.0.4:
Depends on Breeze (which it patches) and Q.js (not for use in Angular ... yet)
You no doubt omitted Q.js from your required libraries and it all goes to custard from there.
I'm personally allergic to the "save-when-user-changes-anything" user experience that made save queuing necessary. I'm almost sorry I wrote it. But there it is.
The apparently dependence on Q.js is the reason it isn't available for Angular apps as written. It's actually pretty easy to make it Angular-ready now because we recently (quietly) made accessible the component that Breeze is using for promises
breeze.Q // returns the promises component currently used by Breeze
Therefore, you could change the one reference to Q on line #104 to
var deferredSave = breeze.Q.defer();
This should work when using breeze v.1.4.14 and later. I haven't fully tested it yet.
This change (or something like it) likely will find its way into breeze.savequeuing.js v.1.1.0 (as I just pushed a non-release version of that).

dart's latest js-interop library causes some issues lately

I have seen some strange changes in the latest js-interop library and I wonder if anybody can give some clarification about it.
After upgrading to the latest version I noticed dart2js doesn't work anymore. After some investigation I concluded the cause was an #proxy annotation inside the js-interop library ( also mentioned here).
Because of this I switched between a couple of versions and I noticed some functions like scoped have been deprecated in a timespan of only a couple of days after which it has been completely removed! If you missed the in between version in which this function is marked as deprecated you miss the hint which give's some info about it. Also note that the main tutorials about the js library on dartlang.org don't even give a hint about the fact that large parts of it have become outdated.
I decided to go back to version 0.0.26 and although it seemed to work as before... I noticed in one instance when retrieving a variable from the javascript context in dart I received a dart DateTime object and not a js.Proxy object.
Going back a version earlier (v0.0.25) I got back my js.Proxy when using a variable from the js context, as expected.
The weird thing is that on github the versions go until 0.0.25 (which work as expected) and the one on pub has 3 versions more, which all break backwards compatibility a lot (which sometimes is needed) without clear instructions about what is going on (which I find lightly frustrating).
Can somebody give some clarifications about what is going on and what I can expect for the coming times?
http://pub.dartlang.org/packages/js
All this breaking changes have been announced in Future breaking changes in package:js and BREAKING CHANGE: package:js deprecated features removed.
Basically, starting from 0.0.26, package:js is now baked with dart:js. This change comes with several things :
scopes/retain/release are no longer needed
several types are now transfered directly between Dart and Js and not proxied
null, bool, num, String, DateTime
Blob
KeyRange
ImageData
TypedData, including its subclasses like Int32List, but not ByteBuffer
Node
Element from shadow dom can now be transfered as well
Callback are now longer needed.
a really big performance improvement
Here's a quick migration guide :
scopes : remove js.retain, js.release and js.scoped.
replace new Callback.xxxx(f) with f and remove callback.dispose().
replace Proxy with transferable type based on the above list.

rails3-jquery-autocomplete: Javascript TypeError

Rails 3.2.11
I followed the instructions for this gem: https://github.com/crowdint/rails3-jquery-autocomplete. When I load the page that I want to have the autocompleted field, Jquery, jquery-ui, autocomplete-rails.js, etc are all being loaded. However, upon loading the page, I get this in the error console:
TypeError: 'undefined' is not a function (evaluating 'this.live')
The I uncompress the js file, and this is the function being referred to:
(function(jQuery)
{
var self = null;
jQuery.fn.railsAutocomplete = function() {
return this.live('focus',function() {
if (!this.railsAutoCompleter) {
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
}
});
};
Anyone have any idea what's going on? Since I'm not using '$' anywhere, the noConflict option doesn't seem to matter, and either way doesn't fix the issue. I didn't make any changes to autocomplete-rails.js
What's weird is that I swear this was working at some point, but I can't for the life of me figure out what changed to break it.
Yup, turns out I had an errant javascript_include_tag that loaded another copy of jquery. That was the issue
I believe the original poster's own answer was part of the solution for me as well. Using rails 3.2.13, jquery 1.9.0 and jquery-ui 1.9.2. More completely I also:
upgraded rails3-jquery-autocomplete to latest (from 1.0.9 to 1.0.11, when I saw: "When possible, use jQuery .on() rather than .live()" in the Changelog in rails3-jquery-autocomplete at github
removed possibly redundant or conflicting jquery includes
reordered includes, specifically placing underscore.js after autocomplete-rails
full stop and clearing of caches and compiled assets
After the first 3 steps, the broken behavior was still there (after each step I restarted server only). The last step was out of laziness, but thankfully showed that the combination of the above worked.

Knockout cyclic error - need advice on finding the cause

I'm working on a large project with many developers. We have 2 pages using knockout that have been working for a while now. Some new, unrelated code was introduced and come to find out the 2 pages with Knockout no longer work properly. When the pages load, there's an error thrown like below. A little investigating lead me to think there's some kind parsing issue going on in the data-bind attributes. I've tried many things to get it working, but I keep getting the entire view model object returned whenever I try to access an observable property. I think this is what's causing the error I'm seeing below after the page loads.
It's very difficult for me to put examples in here so what I'm looking for is any advice on finding errors JavaScript and/or HTML mark-up that might be causing Knockout to fail.
<error>
(anonymous function)
r.Oa.v
r.i.q
r.a.n
e
h
f
r.R.fn.notifySubscribers
r.a.n
r.R.fn.notifySubscribers
r.w.b.G
b
Array.indexOf
r.a.k
r.T.Ha
b
PriceFormatted.ko.dependentObservable.read
h
f
r.R.fn.notifySubscribers
r.a.n
r.R.fn.notifySubscribers
r.w.b.G
b
Array.indexOf
r.a.k
r.T.Ha
b
// it keeps going from here...
Just wanted to update the answer for this. Unfortunately I didn't track down exactly what the issue was, but it had to do with rearranging the order of referenced script files in the Master page of the app. I reverted back to the original order and the issue went away so it's in fact related to a bigger issue of poorly written custom JavaScript throughout the app.

Categories

Resources