From 13405dd207689f63795ea2e04268593fbd91868b Mon Sep 17 00:00:00 2001 From: CaYatur <152031095+CaYatur@users.noreply.github.com> Date: Sat, 26 Sep 2026 13:10:27 +0300 Subject: [PATCH] fix(admin): preserve #sections scroll after panel rebuild (#615) Sync scrollTop right after innerHTML was clamped before layout settled when mode/layer/type changes rebuilt the panel. Restore after layout (double rAF + clamp), and ignore stale restores from rapid re-renders. --- src/admin/admin.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/admin/admin.js b/src/admin/admin.js index bb8eee5..c330ab5 100644 --- a/src/admin/admin.js +++ b/src/admin/admin.js @@ -3136,6 +3136,9 @@ // -------------------------------------------------------------------------- // Render — yalnızca seçili kategorinin kartları // -------------------------------------------------------------------------- + /* #615: hızlı ardışık render'larda eski rAF restore'ları yeni scroll'u ezmesin */ + let sectionsScrollRestoreGen = 0; + function render() { const root = $('sections'); const prevScroll = root.scrollTop; @@ -3158,7 +3161,19 @@ }); renderNav(); - root.scrollTop = prevScroll; + /* #615: innerHTML sonrası sync scrollTop layout oturmadan clamp olur (mode/katman/tür). + MilkDrop listesindeki deferred restore ile aynı fikir; çift rAF + clamp. */ + const gen = ++sectionsScrollRestoreGen; + const restoreSectionsScroll = () => { + if (gen !== sectionsScrollRestoreGen || !root.isConnected) return; + const max = Math.max(0, root.scrollHeight - root.clientHeight); + root.scrollTop = Math.min(prevScroll, max); + }; + restoreSectionsScroll(); + requestAnimationFrame(() => { + restoreSectionsScroll(); + requestAnimationFrame(restoreSectionsScroll); + }); if (window.SVPreview) window.SVPreview.setConfig(cfg); }