fix(common): prevent repeated application of HttpParams mutations (#29045)
Previously, an instance of HttpParams would retain its list of mutations after they have been materialized as a result of a read operation. Not only does this unnecessarily hold onto memory, more importantly does it introduce a bug where branching of off a materialized instance would reconsider the set of mutations that had already been applied, resulting in repeated application of mutations. This commit fixes the bug by clearing the list of pending mutations after they have been materialized, such that they will not be considered once again for branched off instances. Fixes #20430 PR Close #29045
This commit is contained in:
parent
f84c4b066a
commit
8e8e89a119
|
@ -227,7 +227,7 @@ export class HttpParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.cloneFrom = null;
|
this.cloneFrom = this.updates = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,15 @@ import {HttpParams} from '@angular/common/http/src/params';
|
||||||
const mutated = body.delete('a', '2').delete('a', '4');
|
const mutated = body.delete('a', '2').delete('a', '4');
|
||||||
expect(mutated.getAll('a')).toEqual(['1', '3', '5']);
|
expect(mutated.getAll('a')).toEqual(['1', '3', '5']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not repeat mutations that have already been materialized', () => {
|
||||||
|
const body = new HttpParams({fromString: 'a=b'});
|
||||||
|
const mutated = body.append('a', 'c');
|
||||||
|
expect(mutated.toString()).toEqual('a=b&a=c');
|
||||||
|
const mutated2 = mutated.append('c', 'd');
|
||||||
|
expect(mutated.toString()).toEqual('a=b&a=c');
|
||||||
|
expect(mutated2.toString()).toEqual('a=b&a=c&c=d');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('read operations', () => {
|
describe('read operations', () => {
|
||||||
|
|
Loading…
Reference in New Issue