Knockout-Contrib / Knockout-Contrib/Knockout-Validation
deferUpdates, 'with' binding, and a validation extender
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
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:
```
```
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
Contributor guide
Research direction
Start by reproducing the CodePen case with ko.options.deferUpdates enabled, the with: binding, and the required validation extender, then trace the repeated EditableRepVM calls. Done means the extender no longer causes infinite recursion and the view model factory is invoked once, while the existing behavior without the extender remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100