Knockout-Validation
Knockout-Validation copied to clipboard
deferUpdates, 'with' binding, and a validation extender
When using the latest version of knockout, v3.4 with knockout-validation v2.0.3, I get some crashes due to infinite recursion. I have narrowed it down to the following case, where a with: binding instantiates a new VM object containing an observable with a validation extender. The problem does not happen when the validation extender is removed.
HTML:
<div data-bind="with: EditableRepVM($data)">
<p data-bind="text: Name"></p>
</div>
JS:
ko.options.deferUpdates = true;
class ViewModel {
constructor(){
}
EditableRepVM(nonEditableData) {
console.debug('EditableRepVM called');
var newItem = {
};
newItem.Name = ko.observable('default name').extend({required: true});
return newItem;
}
}
ko.applyBindings(new ViewModel());
With the above, console output is:
EditableRepVM called
EditableRepVM called
EditableRepVM called
...
Uncaught Error: 'Too much recursion' after processing 5000 task groups.
@ processTasks @ knockout-debug.js:1081
When removing the validation extender, 'EditableRepVM called' is only logged once, as expected and the page does not crash.
Here is a codepen demonstrating this case. Remove the commented code to experience the issue: http://codepen.io/petemill/pen/GpaPOO?editors=101
See knockout/knockout#1934