compose: Fix preview not being updated when compose textarea is updated.

In preview mode, background updates to the compose box don’t refresh
the preview. For example, canceling an ongoing file upload after
activating preview mode still displays "uploading."

This commit extracts the preview rendering logic from the
show_preview_area function into a new function, `render_preview_area`,
and calls it on the compose textarea’s change event to ensure the
preview updates whenever the textarea is modified.

However, this introduces a race condition where the latest request is
not always reflected in the preview. To resolve this, we introduce a
state variable, `preview_render_count`, which is used to ensure only
the latest preview update is applied.

Fixes #33589.
This commit is contained in:
ubaidrmn
2025-02-28 03:24:47 +05:00
committed by Tim Abbott
parent ddd14a3dc1
commit 1a97fecdb8
4 changed files with 28 additions and 3 deletions

View File

@@ -80,6 +80,9 @@ export function initialize() {
});
$("textarea#compose-textarea").on("input propertychange", () => {
if ($("#compose").hasClass("preview_mode")) {
compose.render_preview_area();
}
compose_validate.warn_if_topic_resolved(false);
const compose_text_length = compose_validate.check_overflow_text($("#send_message_form"));
if (compose_text_length !== 0 && $("textarea#compose-textarea").hasClass("invalid")) {