🐞 Describe the Bug
The delete() method in all four tracked collections (trackedMap, trackedSet, trackedWeakMap, trackedWeakSet) returns true when the key/value does not exist in the collection. Per the ECMAScript specification, delete() must return false if the element was not present.
The bug is an inverted early-return in each implementation:
delete(key: K): boolean {
if (!this.#vals.has(key)) return true; // should be `return false`
...
}
Affected files:
packages/@glimmer/validator/lib/collections/map.ts
packages/@glimmer/validator/lib/collections/set.ts
packages/@glimmer/validator/lib/collections/weak-map.ts
packages/@glimmer/validator/lib/collections/weak-set.ts
🔬 Minimal Reproduction
import { trackedMap } from '@ember/reactive/collections';
const map = trackedMap();
console.log(map.delete('nonexistent')); // true (should be false)
map.set('key', 'value');
console.log(map.delete('key')); // true (correct)
Same pattern applies to trackedSet, trackedWeakMap, and trackedWeakSet.
😕 Actual Behavior
delete() returns true when the key/value is not in the collection.
🤔 Expected Behavior
delete() returns false when the key/value is not in the collection, per:
🌍 Environment
- Ember: 6.10.1
- Ember-CLI: -
- Node.js/npm: -
- OS: -
- Browser: -
➕ Additional Context
Existing tests for delete() don't assert the return value, which is how this slipped through. Found at commit 02c62b0d7cbec49271949fcf608e66f1ccb5b3a6.
🐞 Describe the Bug
The
delete()method in all four tracked collections (trackedMap,trackedSet,trackedWeakMap,trackedWeakSet) returnstruewhen the key/value does not exist in the collection. Per the ECMAScript specification,delete()must returnfalseif the element was not present.The bug is an inverted early-return in each implementation:
Affected files:
packages/@glimmer/validator/lib/collections/map.tspackages/@glimmer/validator/lib/collections/set.tspackages/@glimmer/validator/lib/collections/weak-map.tspackages/@glimmer/validator/lib/collections/weak-set.ts🔬 Minimal Reproduction
Same pattern applies to
trackedSet,trackedWeakMap, andtrackedWeakSet.😕 Actual Behavior
delete()returnstruewhen the key/value is not in the collection.🤔 Expected Behavior
delete()returnsfalsewhen the key/value is not in the collection, per:🌍 Environment
➕ Additional Context
Existing tests for
delete()don't assert the return value, which is how this slipped through. Found at commit02c62b0d7cbec49271949fcf608e66f1ccb5b3a6.