diff --git a/goldens/public-api/core/errors.md b/goldens/public-api/core/errors.md index 937ef918ec0..51e832716fc 100644 --- a/goldens/public-api/core/errors.md +++ b/goldens/public-api/core/errors.md @@ -79,8 +79,6 @@ export const enum RuntimeErrorCode { // (undocumented) INVALID_SKIP_HYDRATION_HOST = -504, // (undocumented) - LOOP_TRACK_DUPLICATE_KEYS = 955, - // (undocumented) MISSING_DOCUMENT = 210, // (undocumented) MISSING_GENERATED_DEF = 906, diff --git a/packages/core/src/errors.ts b/packages/core/src/errors.ts index f1b88249f46..c4e170a427e 100644 --- a/packages/core/src/errors.ts +++ b/packages/core/src/errors.ts @@ -124,9 +124,6 @@ export const enum RuntimeErrorCode { // Output() OUTPUT_REF_DESTROYED = 953, - // Repeater errors - LOOP_TRACK_DUPLICATE_KEYS = 955, - // Runtime dependency tracker errors RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 1000, RUNTIME_DEPS_ORPHAN_COMPONENT = 1001, diff --git a/packages/core/src/render3/instructions/control_flow.ts b/packages/core/src/render3/instructions/control_flow.ts index 5b5e1942259..e7d8b842d3c 100644 --- a/packages/core/src/render3/instructions/control_flow.ts +++ b/packages/core/src/render3/instructions/control_flow.ts @@ -9,7 +9,6 @@ import {setActiveConsumer} from '@angular/core/primitives/signals'; import {TrackByFunction} from '../../change_detection'; -import {formatRuntimeError, RuntimeErrorCode} from '../../errors'; import {DehydratedContainerView} from '../../hydration/interfaces'; import {findMatchingDehydratedView} from '../../hydration/views'; import {assertDefined, assertFunction} from '../../util/assert'; @@ -254,35 +253,6 @@ class LiveCollectionLContainerImpl extends } } -function detectDuplicateKeys( - collection: Iterable, trackByFn: TrackByFunction): void { - const keyToIdx = new Map(); - let duplicatedKeysMsg: string[] = []; - - let idx = 0; - for (const item of collection) { - const key = trackByFn(idx, item); - - if (keyToIdx.has(key)) { - const prevIdx = keyToIdx.get(key); - duplicatedKeysMsg.push(`key "${key}" at index "${prevIdx}" and "${idx}"`); - } - - keyToIdx.set(key, idx++); - } - - if (duplicatedKeysMsg.length > 0) { - const message = formatRuntimeError( - RuntimeErrorCode.LOOP_TRACK_DUPLICATE_KEYS, - 'The provided track expression resulted in duplicated keys for a given collection. ' + - 'Adjust the tracking expression such that it uniquely identifies all the items in the collection. ' + - 'Duplicated keys were: \n' + duplicatedKeysMsg.join(', \n') + '.'); - - // tslint:disable-next-line:no-console - console.warn(message); - } -} - /** * The repeater instruction does update-time diffing of a provided collection (against the * collection seen previously) and maps changes in the collection to views structure (by adding, @@ -308,11 +278,6 @@ export function ɵɵrepeater(collection: Iterable|undefined|null): void metadata.liveCollection.reset(); } - // make sure that tracking expression doesn't result in duplicate keys for a given collection - if (ngDevMode && collection != null) { - detectDuplicateKeys(collection, metadata.trackByFn); - } - const liveCollection = metadata.liveCollection; reconcile(liveCollection, collection, metadata.trackByFn); diff --git a/packages/core/test/acceptance/control_flow_for_spec.ts b/packages/core/test/acceptance/control_flow_for_spec.ts index 3302a612f61..9fa35d2c315 100644 --- a/packages/core/test/acceptance/control_flow_for_spec.ts +++ b/packages/core/test/acceptance/control_flow_for_spec.ts @@ -273,32 +273,6 @@ describe('control flow - for', () => { fixture.detectChanges(); expect(context).toBe(fixture.componentInstance); }); - - it('should warn about duplicated keys', () => { - @Component({ - template: `@for (item of items; track item) {{{item}}}`, - }) - class TestComponent { - items = ['a', 'b', 'a', 'c', 'a']; - } - - spyOn(console, 'warn'); - - const fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement.textContent).toBe('abaca'); - expect(console.warn).toHaveBeenCalledTimes(2); - expect(console.warn) - .toHaveBeenCalledWith(jasmine.stringContaining( - `NG0955: The provided track expression resulted in duplicated keys for a given collection.`)); - expect(console.warn) - .toHaveBeenCalledWith(jasmine.stringContaining( - `Adjust the tracking expression such that it uniquely identifies all the items in the collection. `)); - expect(console.warn) - .toHaveBeenCalledWith(jasmine.stringContaining(`key "a" at index "0" and "2"`)); - expect(console.warn) - .toHaveBeenCalledWith(jasmine.stringContaining(`key "a" at index "2" and "4"`)); - }); }); describe('list diffing and view operations', () => {