Skip to content

TrackedMap, TrackedSet, TrackedWeakMap, and TrackedWeakSet delete() returns true for non-existent entries #21121

@megothss

Description

@megothss

🐞 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions