Fix streams getting stuck on regen
| @@ -2818,7 +2818,7 @@ class StreamingProcessor { | ||
| 2818 | 2818 | } |
| 2819 | 2819 | |
| 2820 | 2820 | #checkDomElements(messageId) { |
| 2821 | 2821 | if (this.messageDom === null || this.messageTextDom === null) { |
| 2822 | 2822 | this.messageDom = document.querySelector(`#chat .mes[mesid="${messageId}"]`); |
| 2823 | 2823 | this.messageTextDom = this.messageDom?.querySelector('.mes_text'); |
| 2824 | 2824 | this.messageTimerDom = this.messageDom?.querySelector('.mes_timer'); |
| @@ -2890,6 +2890,7 @@ class StreamingProcessor { | ||
| 2890 | 2890 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); |
| 2891 | 2891 | } |
| 2892 | 2892 | else { |
| 2893 | + this.#checkDomElements(messageId); | |
| 2893 | 2894 | const currentTime = new Date(); |
| 2894 | 2895 | // Don't waste time calculating token count for streaming |
| 2895 | 2896 | const currentTokenCount = isFinal && power_user.message_token_count_enabled ? getTokenCount(processedText, 0) : 0; |
| @@ -2921,7 +2922,6 @@ class StreamingProcessor { | ||
| 2921 | 2922 | chat[messageId].is_user, |
| 2922 | 2923 | messageId, |
| 2923 | 2924 | ); |
| 2924 | - this.#checkDomElements(messageId); | |
| 2925 | 2925 | if (this.messageTextDom instanceof HTMLElement) { |
| 2926 | 2926 | this.messageTextDom.innerHTML = formattedText; |
| 2927 | 2927 | } |
| @@ -3215,6 +3215,23 @@ function restoreResponseLength(api, responseLength) { | ||
| 3215 | 3215 | } |
| 3216 | 3216 | |
| 3217 | 3217 | /** |
| 3218 | + * Removes last message from the chat DOM. | |
| 3219 | + * @returns {Promise<void>} Resolves when the message is removed. | |
| 3220 | + */ | |
| 3221 | +function removeLastMessage() { | |
| 3222 | + return new Promise((resolve) => { | |
| 3223 | + const lastMes = $('#chat').children('.mes').last(); | |
| 3224 | + if (lastMes.length === 0) { | |
| 3225 | + return resolve(); | |
| 3226 | + } | |
| 3227 | + lastMes.hide(animation_duration, function () { | |
| 3228 | + $(this).remove(); | |
| 3229 | + resolve(); | |
| 3230 | + }); | |
| 3231 | + }); | |
| 3232 | +} | |
| 3233 | + | |
| 3234 | +/** | |
| 3218 | 3235 | * Runs a generation using the current chat context. |
| 3219 | 3236 | * @param {string} type Generation type |
| 3220 | 3237 | * @param {GenerateOptions} options Generation options |
| @@ -3346,9 +3363,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 3346 | 3363 | } |
| 3347 | 3364 | else if (type !== 'quiet' && type !== 'swipe' && !isImpersonate && !dryRun && chat.length) { |
| 3348 | 3365 | chat.length = chat.length - 1; |
| 3349 | - $('#chat').children().last().hide(250, function () { | |
| 3366 | + await removeLastMessage(); | |
| 3350 | - $(this).remove(); | |
| 3351 | - }); | |
| 3352 | 3367 | await eventSource.emit(event_types.MESSAGE_DELETED, chat.length); |
| 3353 | 3368 | } |
| 3354 | 3369 | } |