mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(core): avoid slow stringification when checking for duplicates in dev mode (#58521)
When we check for duplicates in dev mode, we end up stringifying an `LView` even if we don't report an error. This can be expensive in large views. These changes work around the issue by only generating the string when we have an error to throw. Fixes #58509. PR Close #58521
This commit is contained in:
parent
b0711d74c4
commit
8ae84be3df
1 changed files with 6 additions and 3 deletions
|
|
@ -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';
|
||||
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue