mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2800] [Issue]: Mobile: Characters panel auto-scrolls on reopen (persisted scroll restoration re-fires on AnimatePresence remount) #1424
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1424
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2800
Summary
A mobile user reported that opening the agent / persona / character (and "other") side panels auto-scrolls the page, attributing it to
autoFocuson the panel search/filter input pulling the focused field into view and popping the soft keyboard on mount.That described cause is not present in v2.0.0. No panel search input has
autoFocus, and no panel runs a focus or scroll effect on mount — so opening Agents, Personas, Connections, Lorebooks, or Presets cannot move the viewport from the code as written.There is one real mount-time scroll, but it is Characters-only and is a different mechanism than reported: the Characters panel restores a persisted scroll offset on mount, and because the mobile right-panel is unmounted/remounted on every open (
AnimatePresence), that restoration re-fires on every reopen. When the saved offset is non-zero, the list visibly jumps away from the top, which reads as an "auto-scroll on open."This issue corrects the reported root cause, pins the real one, and gives a fix that actually removes the perceived jump (the obvious-looking guard does not).
Symptom & UX impact (mobile)
autoFocus.Create*ModalautoFocus name field (see Root cause / alternatives), which needs a recording to confirm.Steps to reproduce
Characters panel jump (real):
characterPanelScrollTopdefaults to0).Reported "search autoFocus" cause (does NOT repro):
autoFocus.Root cause (exact file:line trace)
1. The reported cause is absent. None of the panel search inputs use
autoFocus:packages/client/src/components/panels/AgentsPanel.tsx:847-852("Search agents")packages/client/src/components/panels/PersonasPanel.tsx:514-519("Search personas")packages/client/src/components/panels/CharactersPanel.tsx:689-694('Search characters or -tag:"..."')packages/client/src/components/panels/ConnectionsPanel.tsx:1214-1220("Search connections...")packages/client/src/components/panels/LorebooksPanel.tsx:729-735("Search lorebooks")packages/client/src/components/panels/PresetsPanel.tsx:820-826("Search presets…")The
autoFocusinstances that exist (AgentsPanel.tsx:935,PersonasPanel.tsx:695,CharactersPanel.tsx:871,ConnectionsPanel.tsx:804, etc.) are all inside conditionally-rendered rename inputs gated onisEditing/renaming, whose state initializes tonull/false(e.g.editingGroupIdPersonasPanel.tsx:128,CharactersPanel.tsx:139;editingFolderIdAgentsPanel.tsx:247). They are not in the tree at mount and cannot fire on panel open.2. The open path has no scroll/focus side effect.
TopBar.tsx:334toggleRightPanel(panel)→ui.store.ts:1201sets{ rightPanelOpen, rightPanel }only. On mobile,AppShell.tsx:907-926renders the panel inside<AnimatePresence mode="wait">→<motion.aside key="mobile" initial={{x:"100%"}} animate={{x:0}}>(full-screen fixed overlay; no autoFocus, no focus trap).3. The real mechanism — Characters scroll restoration re-firing on every mobile remount:
RightPanel.tsx:60-61declares a module-levelconst mountedPanels = new Set<string>()with the comment "Module-level set survives component remounts (e.g. mobile AnimatePresence unmount/remount)." Each panel renders inside its ownabsolute inset-0 overflow-y-autocontainer atRightPanel.tsx:113— the only scroll container.AppShell.tsx:908-909gates the whole<motion.aside>onrightPanelOpen &&insideAnimatePresence, the entireRightPanelsection unmounts on close and remounts on reopen on mobile.CharactersPanel's restore effect atCharactersPanel.tsx:435-445runs on every reopen. At:440it setsnode.scrollTop = Math.min(useUIStore.getState().characterPanelScrollTop, maxScrollTop). Its deps (CharactersPanel.tsx:445:isLoading,parsedGroups.length,sortedCharacters.length,visibleRootCharacters.length) also make it re-run after the asyncuseCharactersfetch resolves.characterPanelScrollTopis persisted across sessions: set on scroll atui.store.ts:1223(setCharacterPanelScrollTop), included in the persist partialize atui.store.ts:2249, and rehydrated/normalized on load. A previously saved non-zero offset is therefore reapplied on every open → visible jump. Default is0, so a first/clean open does not jump.4. Agents/Personas cannot exhibit this. Neither panel has any
useLayoutEffect/useEffectsettingscrollTop, norscrollIntoView/.focus()on mount (grep returns no matches). The reported cross-panel symptom is therefore not reproducible for them from the code.Suggested fix (concrete)
Do NOT "remove autoFocus from the panel search inputs" — there is no such autoFocus; that change targets dead code and is a no-op.
Primary fix — stop the Characters panel from restoring scroll on a mobile reopen. The naive guard
if (characterPanelScrollTop <= 0) return;is wrong: it only suppresses restoring-to-0-when-already-0 (a no-op) and lets the actual non-zero jump through. The fix must skip restoration when the panel is opened fresh on the mobile overlay, where users expect the list at the top.In
packages/client/src/components/panels/CharactersPanel.tsx:435-445, gate restoration off the mobile overlay so desktop session restoration is preserved:Alternative to the primary fix (pick one):
characterPanelScrollTopto0incloseRightPanel(ui.store.ts) when the closing panel ischaracters, so reopen always starts at the top on every platform. Simpler, but also drops desktop restoration.AnimatePresenceremount.Secondary hardening (only if a recording shows a focus-driven jump on a
Create*modal or detail editor). TheautoFocusname fields that actually mount over a panel are the create modals —CreateCharacterModal.tsx:113,CreatePersonaModal.tsx:59,CreateConnectionModal.tsx:69,CreateLorebookModal.tsx:74,CreatePresetModal.tsx:79. On iOS the soft keyboard can shift the visual viewport, which the user may perceive as the page scrolling. ReplaceautoFocusthere with a focus that does not scroll and does not pop the keyboard on touch. This pattern is already established in the codebase (ChatMessage.tsx:295,ChatSettingsDrawer.tsx:1386usefocus({ preventScroll: true })):Before closing this issue: attach a fresh mobile screen recording and confirm which surface scrolls — the Characters list (primary fix covers it) or a Create* modal / detail editor (secondary hardening covers it). The static read can only explain the Characters case; the Agents/Personas symptom as reported is not reproducible from the code.
Affected files
packages/client/src/components/panels/CharactersPanel.tsx— primary fix (restore effect:435-445)packages/client/src/stores/ui.store.ts— alternative fix (reset oncloseRightPanel); persistedcharacterPanelScrollTop(:1223,:2249)packages/client/src/components/layout/RightPanel.tsx— context: module-levelmountedPanels(:60-61), scroll container (:113)packages/client/src/components/layout/AppShell.tsx— context: mobileAnimatePresenceremount (:907-926)packages/client/src/components/modals/CreateCharacterModal.tsx,CreatePersonaModal.tsx,CreateConnectionModal.tsx,CreateLorebookModal.tsx,CreatePresetModal.tsx— only if recording implicates a create-modal autoFocusAgentsPanel.tsx,PersonasPanel.tsx,ConnectionsPanel.tsxValidation
pnpm checkpasses (TypeScript + ESLint).AI-investigated against released 2.0.0; verify before fixing.
@SpicyMarinara commented on GitHub (Jun 22, 2026):
Addressed in PR #2790 / commit acab1fba: CharactersPanel scroll restoration is disabled for the mobile overlay sheet so reopening the panel does not replay desktop-style persisted scroll jumps.