diff --git a/packages/compiler-cli/src/ngtsc/resource_loader.ts b/packages/compiler-cli/src/ngtsc/resource_loader.ts index ea54032e3c..3ab9118f7a 100644 --- a/packages/compiler-cli/src/ngtsc/resource_loader.ts +++ b/packages/compiler-cli/src/ngtsc/resource_loader.ts @@ -15,13 +15,15 @@ import {ResourceLoader} from './annotations'; */ export class HostResourceLoader implements ResourceLoader { private cache = new Map(); - private fetching = new Set(); + private fetching = new Map>(); constructor(private host: (url: string) => string | Promise) {} preload(url: string): Promise|undefined { - if (this.cache.has(url) || this.fetching.has(url)) { + if (this.cache.has(url)) { return undefined; + } else if (this.fetching.has(url)) { + return this.fetching.get(url); } const result = this.host(url); @@ -29,11 +31,12 @@ export class HostResourceLoader implements ResourceLoader { this.cache.set(url, result); return undefined; } else { - this.fetching.add(url); - return result.then(str => { + const fetchCompletion = result.then(str => { this.fetching.delete(url); this.cache.set(url, str); }); + this.fetching.set(url, fetchCompletion); + return fetchCompletion; } }