Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(core): avoid slow stringification when checking for duplicates in dev mode #58521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/core/src/render3/list_reconciliation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import {TrackByFunction} from '../change_detection';
import {formatRuntimeError, RuntimeErrorCode} from '../errors';
import {assertNotSame} from '../util/assert';

import {stringifyForError} from './util/stringify_utils';

Expand Down Expand Up @@ -428,8 +427,12 @@ export class UniqueValueMultiKeyMap<K, V> {
set(key: K, value: V): void {
if (this.kvMap.has(key)) {
let prevValue = this.kvMap.get(key)!;
ngDevMode &&
assertNotSame(prevValue, value, `Detected a duplicated value ${value} for the key ${key}`);

// Note: we don't use `assertNotSame`, because the value needs to be stringified even if
// there is no error which can freeze the browser for large values (see #58509).
if (ngDevMode && prevValue === value) {
throw new Error(`Detected a duplicated value ${value} for the key ${key}`);
}

if (this._vMap === undefined) {
this._vMap = new Map();
Expand Down