From 952b6bbe516a27c00264390f9c2739d6697d5917 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 02:30:23 +0000 Subject: [PATCH] Fix: Prevent emoji display race condition Previously, the `_showEmoji` function determined the total number of emojis by inspecting the DOM (`emojiWrapper.children.length`). This could lead to a race condition if an incoming message containing an emoji was processed before the `_initialEmoji` function had fully populated the emojiWrapper. In such cases, `totalEmojiNum` would be 0 (or an incorrect intermediate value), causing valid emojis to be displayed as '[X]'. This commit fixes the issue by setting `totalEmojiNum` to a constant value of 69, which is the actual number of emojis (1.gif to 69.gif) supported by the application. This makes the emoji display logic robust and independent of the DOM state of the emoji panel during message processing. This likely addresses the underlying problem referred to as 'issue #19', where specific emojis might have been reported as not working due to this timing-sensitive bug. --- www/scripts/hichat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/scripts/hichat.js b/www/scripts/hichat.js index 7be8ed7..ded669e 100644 --- a/www/scripts/hichat.js +++ b/www/scripts/hichat.js @@ -162,7 +162,7 @@ HiChat.prototype = { var match, result = msg, reg = /\[emoji:\d+\]/g, emojiIndex, - totalEmojiNum = document.getElementById('emojiWrapper').children.length; + totalEmojiNum = 69; while (match = reg.exec(msg)) { emojiIndex = match[0].slice(7, -1); if (emojiIndex > totalEmojiNum) {