From b2c4b58b27599b016a66ff0420e8622bbe732cc0 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Fri, 13 Nov 2026 14:11:30 +0100 Subject: [PATCH] :bug: Keep the pages panel scroll when switching pages (#13004) Switching pages swaps the workspace content for a loader until the new page is ready, so the whole left sidebar mounts again. The pages list started at the top and the selected page scrolled into view at the bottom of the panel, even when it was already visible. The sidebar scroll store now lives in workspace-inner*, which stays mounted across page switches. The pages panel saves its scroll there and restores it before the selected page scrolls into view. The layers, assets and tokens panels keep their positions across page switches too. Closes #13002 AI-assisted-by: claude-opus-5-5 --- frontend/src/app/main/ui/workspace.cljs | 17 +++++++++----- .../src/app/main/ui/workspace/sidebar.cljs | 13 ++++++----- .../app/main/ui/workspace/sidebar/scroll.cljs | 10 ++++----- .../main/ui/workspace/sidebar/sitemap.cljs | 22 +++++++++++++++++-- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/main/ui/workspace.cljs b/frontend/src/app/main/ui/workspace.cljs index 4b37d284a9..b9958a3230 100644 --- a/frontend/src/app/main/ui/workspace.cljs +++ b/frontend/src/app/main/ui/workspace.cljs @@ -54,7 +54,7 @@ (mf/defc workspace-content* {::mf/private true} - [{:keys [file layout page wglobal]}] + [{:keys [file layout page wglobal scroll-store]}] (let [palete-size (mf/use-state nil) selected (mf/deref refs/selected-shapes) @@ -123,6 +123,7 @@ :file-id (get file :id) :page-id page-id :file file + :scroll-store scroll-store :selected selected :section options-mode :drawing-tool (get drawing :tool)}])])) @@ -173,9 +174,14 @@ (mf/defc workspace-inner* {::mf/private true} [{:keys [page-id file-id file layout wglobal]}] - (let [page-ref (mf/with-memo [file-id page-id] - (make-page-ref file-id page-id)) - page (mf/deref page-ref)] + (let [page-ref (mf/with-memo [file-id page-id] + (make-page-ref file-id page-id)) + page (mf/deref page-ref) + + ;; NOTE: lives here because the sidebar unmounts on every page + ;; switch (the loader replaces `workspace-content*` until the + ;; new page is ready), so the scroll positions must outlive it + scroll-store* (mf/use-var {})] (mf/with-effect [] (let [focus-out #(st/emit! (dw/workspace-focus-lost)) @@ -191,7 +197,8 @@ [:> workspace-content* {:file file :page page :wglobal wglobal - :layout layout}] + :layout layout + :scroll-store scroll-store*}] [:> workspace-loader*]))) (mf/defc workspace* diff --git a/frontend/src/app/main/ui/workspace/sidebar.cljs b/frontend/src/app/main/ui/workspace/sidebar.cljs index c8a0ece18e..aed6882aea 100644 --- a/frontend/src/app/main/ui/workspace/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar.cljs @@ -101,6 +101,7 @@ [:article {:class (stl/css :layers-tab)} [:> sitemap* {:layout layout :height sitemap-height + :scroll-store scroll-store :collapsed sitemap-collapsed? :on-toggle-collapsed on-toggle-sitemap-collapsed}] @@ -118,11 +119,10 @@ (mf/defc left-sidebar* {::mf/memo true} - [{:keys [layout file tokens-lib tokens-status active-tokens resolved-active-tokens]}] + [{:keys [layout file tokens-lib tokens-status active-tokens resolved-active-tokens scroll-store]}] (let [options-mode (mf/deref refs/options-mode-global) project (mf/deref refs/project) file-id (get file :id) - scroll-store* (mf/use-var {}) design-tokens? (features/use-feature "design-tokens/v1") mode-inspect? (= options-mode :inspect) @@ -216,7 +216,7 @@ :assets [:> assets-toolbox* {:size (- width 58) :file-id file-id - :scroll-store scroll-store*}] + :scroll-store scroll-store}] :tokens [:> tokens-sidebar-tab* @@ -224,12 +224,12 @@ :tokens-status tokens-status :active-tokens active-tokens :resolved-active-tokens resolved-active-tokens - :scroll-store scroll-store*}] + :scroll-store scroll-store}] :layers [:> layers-content* {:layout layout :width width - :scroll-store scroll-store*}])]])]])) + :scroll-store scroll-store}])]])]])) ;; --- Right Sidebar (Component) @@ -362,7 +362,7 @@ [:> options-toolbox* props]))]]]])) (mf/defc sidebar* - [{:keys [layout file file-id page-id section drawing-tool selected]}] + [{:keys [layout file file-id page-id section drawing-tool selected scroll-store]}] (let [tokens-lib (mf/deref refs/tokens-lib) @@ -407,6 +407,7 @@ [:> left-sidebar* {:layout layout :file file :page-id page-id + :scroll-store scroll-store :tokens-lib tokens-lib :tokens-status tokens-status :active-tokens active-tokens-force-set diff --git a/frontend/src/app/main/ui/workspace/sidebar/scroll.cljs b/frontend/src/app/main/ui/workspace/sidebar/scroll.cljs index 1902c9798f..386ed63b73 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/scroll.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/scroll.cljs @@ -7,11 +7,11 @@ (ns app.main.ui.workspace.sidebar.scroll "Scroll position save/restore for sidebar panels. - Panels unmount on every tab switch, so positions that must survive it - cannot live in component state. The store is created once in - `left-sidebar*` (which stays mounted while tabs swap, unlike - `layers-content*` and the toolboxes) with `mf/use-var` and threaded to - the panels as a prop. Shape: {[panel id] scroll-top}." + Panels unmount on every tab switch, and the whole sidebar unmounts on + every page switch, so positions that must survive it cannot live in + component state. The store is created once in `workspace-inner*` (which + stays mounted while pages and tabs swap) with `mf/use-var` and threaded + to the panels as a prop. Shape: {[panel id] scroll-top}." (:require [app.util.dom :as dom] [app.util.timers :as tm] diff --git a/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs b/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs index 3f1ec3ab8d..818d002dd8 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs @@ -23,6 +23,7 @@ [app.main.ui.ds.foundations.assets.icon :as i :refer [icon*]] [app.main.ui.hooks :as hooks] [app.main.ui.notifications.badge :refer [badge-notification]] + [app.main.ui.workspace.sidebar.scroll :as sc] [app.render-wasm.api :as wasm.api] [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] @@ -291,10 +292,16 @@ ;; --- Sitemap Toolbox (mf/defc sitemap* - [{:keys [height collapsed on-toggle-collapsed]}] + [{:keys [height collapsed on-toggle-collapsed scroll-store]}] (let [file (mf/deref ref:file-with-pages) file-id (get file :id) project-id (get file :project-id) + content-ref (mf/use-ref nil) + + on-scroll (mf/use-fn + (mf/deps scroll-store file-id) + (fn [event] + (sc/save-scroll! scroll-store [:sitemap file-id] event))) on-create (mf/use-fn (mf/deps file-id project-id) @@ -306,6 +313,15 @@ read-only? (mf/use-ctx ctx/workspace-read-only?) permissions (mf/use-ctx ctx/permissions)] + ;; NOTE: a layout effect, so the saved position is back before the + ;; selected page item runs its `scroll-into-view-if-needed!` effect. + ;; With nothing saved the list is left alone, so the selected page + ;; still scrolls into view when the file opens. + (mf/with-layout-effect [file-id collapsed] + (when-not ^boolean collapsed + (when-some [saved (get @scroll-store [:sitemap file-id])] + (sc/restore-scroll! (mf/ref-val content-ref) saved)))) + [:div {:class (stl/css :sitemap) :style {:--height (dm/str height "px")}} @@ -326,6 +342,8 @@ :icon i/add}])] (when-not ^boolean collapsed - [:div {:class (stl/css :sitemap-content)} + [:div {:class (stl/css :sitemap-content) + :ref content-ref + :on-scroll on-scroll} [:> pages-list* {:key (dm/str (:id file)) :file file}]])]))