Skip to content

Commit a7bcddf

Browse files
committed
fix issue where thumbnail would sometimes keep loading indefinitely
1 parent 54ed550 commit a7bcddf

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/app/thumbnail/thumbnail.component.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ export class ThumbnailComponent implements OnChanges {
9797
*/
9898
ngOnChanges(changes: SimpleChanges): void {
9999
if (isPlatformBrowser(this.platformID)) {
100-
// every time the inputs change we need to start the loading animation again, as it's possible
101-
// that thumbnail is first set to null when the parent component initializes and then set to
102-
// the actual value
103-
if (this.isLoading$.getValue() === false) {
104-
this.isLoading$.next(true);
105-
}
106-
107100
if (hasNoValue(this.thumbnail)) {
108101
this.setSrc(this.defaultImage);
109102
return;
@@ -196,9 +189,22 @@ export class ThumbnailComponent implements OnChanges {
196189
* @param src
197190
*/
198191
setSrc(src: string): void {
199-
this.src$.next(src);
200-
if (src === null) {
201-
this.isLoading$.next(false);
192+
// only update the src if it has changed (the parent component may fire the same one multiple times
193+
if (this.src$.getValue() !== src) {
194+
// every time the src changes we need to start the loading animation again, as it's possible
195+
// that it is first set to null when the parent component initializes and then set to
196+
// the actual value
197+
//
198+
// isLoading$ will be set to false by the error or success handler afterwards, except in the
199+
// case where src is null, then we have to set it manually here (because those handlers won't
200+
// trigger)
201+
if (this.isLoading$.getValue() === false) {
202+
this.isLoading$.next(true);
203+
}
204+
this.src$.next(src);
205+
if (src === null) {
206+
this.isLoading$.next(false);
207+
}
202208
}
203209
}
204210

0 commit comments

Comments
 (0)