From 85004ada3fea045258479aa5011064103ec44ba7 Mon Sep 17 00:00:00 2001 From: arne Date: Fri, 21 Nov 2025 17:03:50 +0100 Subject: [PATCH] Provide stable keys for components in lists See https://preactjs.com/tutorial/08-keys/ --- src/computersandblues/lodestone/app.cljs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/computersandblues/lodestone/app.cljs b/src/computersandblues/lodestone/app.cljs index 3561957..c181fce 100644 --- a/src/computersandblues/lodestone/app.cljs +++ b/src/computersandblues/lodestone/app.cljs @@ -415,10 +415,11 @@ [:time.date {:datetime (:created_at post)} (first (str/split (:created_at post) "T"))]]] [:section.content {:dangerouslySetInnerHTML (r/unsafe-html (:content post))}] (when (seq (:media_attachments post)) - [:section.attachments - (map-indexed (fn [idx item] - ^{:key idx} [attachment {:attachment item}]) - (:media_attachments post))]) + (into [:section.attachments] + (map (fn [item] + (let [key (str "post-" (:id post) "-attachment-" (:id item))] + ^{:key key} [attachment {:attachment item}]))) + (:media_attachments post))) [:nav [:ul.controls [:li.control-element.url @@ -519,8 +520,11 @@ [:section.buttons [:button.control-button {:on-click fetch-more-posts! :disabled (boolean (seq loading))} "⇓ Fetch more"] [:button.control-button {:on-click disconnect-account!} "▤ Disconnect account"]]] - [:ul.results (map-indexed (fn [idx p] - ^{:key idx} [:li.result [post {:post p}]]) displayed-posts)]])) + (into [:ul.results] + (map (fn [p] + (let [key (str "post-" (:id p))] + ^{:key key} [:li.result [post {:post p}]]))) + displayed-posts)])) ;; help section