compose: Fix stale preview rendering after exiting preview mode.

If the user exits preview mode before the render response arrives, the
render is still applied to the hidden preview element, causing a stale
preview to appear when switching back to preview mode.

This commit adds a check to ensure the render is only applied if the
user is still in preview mode when the render response is received.
This commit is contained in:
ubaidrmn
2025-02-28 14:26:03 +05:00
committed by Tim Abbott
parent 1a97fecdb8
commit dd7cf27735

View File

@@ -1354,8 +1354,12 @@ export function render_and_show_preview(
url: "/json/messages/render", url: "/json/messages/render",
data: {content}, data: {content},
success(response_data) { success(response_data) {
if (preview_render_count !== compose_state.get_preview_render_count()) { if (
// The compose input has already been updated with new raw Markdown preview_render_count !== compose_state.get_preview_render_count() ||
!$("#compose").hasClass("preview_mode")
) {
// The user is no longer in preview mode or the compose
// input has already been updated with new raw Markdown
// since this rendering request was sent off to the server, so // since this rendering request was sent off to the server, so
// there's nothing to do. // there's nothing to do.
return; return;