Skip to content

Commit 33f5edd

Browse files
authored
Fix infinite onerror loop in avatar image loader (#82)
Avatar images have an onerror attribute to set their image to a generic avatar image if they fail to load from discord. However, in situations where the network fails or the discord CDN is unavailable for some reason (adblockers), this will throw an error as well. In browsers other than chrome, this will trigger the on-error handler again, infinitely looping requests as fast as possible. We set the onerror handler to null before making the new request to get around this and ensure if the fallback fails to load we don't make further requests. Signed-off-by: Bast <52266665+bast0006@users.noreply.github.com>
1 parent 9e4dff4 commit 33f5edd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

templates/logbase.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<div class="info__guild-icon-container">
4242
<img class="info__guild-icon hoverable"
4343
src="{{ log_entry.recipient.avatar_url }}"
44-
onerror="this.src='{{ log_entry.recipient.default_avatar_url }}'"
44+
onerror="this.onerror=null;this.src='{{ log_entry.recipient.default_avatar_url }}'"
4545
alt="avatar">
4646
</div>
4747
<div class="info__metadata">
@@ -81,7 +81,7 @@
8181
<div class="chatlog__author-avatar-container">
8282
<img class="chatlog__author-avatar"
8383
src="{{ group.author.avatar_url }}"
84-
onerror="this.src='{{ group.author.default_avatar_url }}'"
84+
onerror="this.onerror=null;this.src='{{ group.author.default_avatar_url }}'"
8585
alt="avatar"/>
8686
</div>
8787

@@ -242,4 +242,4 @@
242242
$('.dropdown-trigger').dropdown({coverTrigger: false});
243243
</script>
244244
</body>
245-
</html>
245+
</html>

0 commit comments

Comments
 (0)