Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Subscription leak when using live flag with observableArray
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
Sorry, I misunderstood the code. The inverted flag seems correct.
The question is actually how can I eventually get rid of the observableArray subscriptions made by a ko.validation.group using live: true in config when I'm done with the validation group?
Thinking perhaps add/wrap (depending on observable flag) dispose on the result returned from ko.validation.group to include a cleanUpSubscriptions?
Old post
In traverseGraph there is this piece of code:
if (context.options.live && utils.isObservableArray(obj)) {
context.subscriptions.push(obj.subscribe(function () {
context.graphMonitor.valueHasMutated();
}));
}
That is the only place I can find that subscriptions array is being added to.
But when time comes for disposal the code looks like this:
if (!context.options.live) {
cleanUpSubscriptions(context);
}
Should the check against live flag really be inverted?
It will cause dispose to skip cleaning up subscriptions for the cases where there might actually be some subscriptions according to my test.
Example code
https://github.com/SimmeNilsson/KnockoutValidationDisposeFix
Added console.log for these parts in the code.
knockout.validation.fixed.js has the inverting removed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the leak using the linked KnockoutValidationDisposeFix example, then inspect traverseGraph and the cleanup condition shown in the issue, along with knockout.validation.fixed.js. Confirm that a validation group using live: true can dispose its observableArray subscriptions, and verify the group no longer retains those subscriptions after disposal.
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
- 30/100