From d66af6ec6f8a91cb48980da4e92485e77a64a319 Mon Sep 17 00:00:00 2001 From: scheinriese Date: Thu, 23 Apr 2026 14:49:43 +0200 Subject: [PATCH] fix: guard stale web-image responses and avoid layout jump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two related bugs around the web-images section: 1. Fast typing produced overlapping fetches where a late 'do' response could overwrite results for 'donald trump'. Stamp each request with a generation id in a component-local atom and drop responses whose id no longer matches. 2. The section unmounted during transition states — while the parent's debounced query hadn't caught up yet, or after the user typed but before loading? flipped to true — so the layout below jumped up, then back down when skeletons appeared. Compute a pending? flag from both conditions, keep the section mounted whenever loading? or pending?, and mirror avatar-mode on skeletons so circle-mode loads land in the exact spot the circular skeletons occupied. CSS mirror the same geometry (transparent 2px border + avatar-mode 50% radius) on .web-image-placeholder. --- src/main/frontend/components/icon.cljs | 77 ++++++++++++++++++-------- src/main/frontend/components/icon.css | 9 +++ 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/main/frontend/components/icon.cljs b/src/main/frontend/components/icon.cljs index 3a7e44a677..441859c25b 100644 --- a/src/main/frontend/components/icon.cljs +++ b/src/main/frontend/components/icon.cljs @@ -1865,61 +1865,87 @@ (rum/local nil ::images) (rum/local true ::loading?) (rum/local nil ::current-query) + ;; Generation counter — responses whose id no longer matches are stale + ;; (e.g. a "do" prefix response arriving after "donald trump" was issued) + ;; and must not overwrite the current images. + (rum/local 0 ::request-id) {:did-mount (fn [state] (let [[{:keys [query]}] (:rum/args state) *images (::images state) *loading? (::loading? state) - *current-query (::current-query state)] + *current-query (::current-query state) + *request-id (::request-id state)] (when-not (string/blank? query) (reset! *current-query query) (reset! *loading? true) - (-> ( ( ( ( * { + border-radius: 50%; + } } /* Bordered tooltip arrow - CSS-positioned (Base UI technique) */