From dd7cf27735f5c56fc49a268611d901b300936579 Mon Sep 17 00:00:00 2001 From: ubaidrmn Date: Fri, 28 Feb 2025 14:26:03 +0500 Subject: [PATCH] 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. --- web/src/compose_ui.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts index 9711d8b7b0..97708499ef 100644 --- a/web/src/compose_ui.ts +++ b/web/src/compose_ui.ts @@ -1354,8 +1354,12 @@ export function render_and_show_preview( url: "/json/messages/render", data: {content}, success(response_data) { - if (preview_render_count !== compose_state.get_preview_render_count()) { - // The compose input has already been updated with new raw Markdown + if ( + 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 // there's nothing to do. return;