mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3068] [Issue]: Spotify floating mini-player can be stranded off-screen and untappable after rotating/resizing because its clamp style is memoized and never recomputed on viewport change #1635
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#1635
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 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3068
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
On a phone, the floating Spotify mini-player clamps its on-screen position against
window.innerWidth/window.innerHeightso it stays inside the visible viewport. But that clamp is computed inside auseMemokeyed only on[collapsed, mobilePosition], neither of which changes on a plain orientation/resize event. So when the viewport shrinks (rotate landscape → portrait, or the mobile browser address bar expanding/collapsing), the clamp never re-runs, and the widget keeps rendering at its old, now-out-of-bounds position. Because dragging the widget back requires apointerdownon the widget itself, an off-screen widget is effectively unrecoverable — it stays stranded until some unrelated state change happens to flipcollapsedormobilePosition, at which point the clamp self-heals. The component re-renders every ~5s on the playback poll, but the memo just returns its cached, stale style on every one of those renders.How to reproduce (try it yourself)
You'll see: the bubble sits past the right edge (partially or fully off-screen) and you cannot tap or drag it back, because the touch target is now outside the screen. It only reappears if you trigger an unrelated re-render path that flips
collapsedormobilePosition.Expected: the widget should re-clamp into the visible viewport immediately on orientation/resize and remain tappable and draggable.
Where it is
packages/client/src/components/spotify/SpotifyMiniPlayer.tsx:792The dependency array contains no viewport dimension. The next line has the identical gap for the expanded panel:
SpotifyMiniPlayer.tsx:793getMobileWidgetStyle(lines 230-250) is what reads the viewport and bakes the clampedleft/topinto the memoized output:The memoized style is consumed verbatim on the
fixed-positioned container at lines 1031-1032:Sibling that does it right:
useMediaQuery(lines 1120-1133) does attach amatchMedia('change')listener — but it only drives the SpotifyMobileWidget mount/unmount decision; nothing in the file listens forresize/orientationchangeto re-run the position clamp. (A grep forresize/orientationchangeacross the file returns zero listeners.)What's happening
useMemocachesgetMobileWidgetStyle's output keyed on[collapsed, mobilePosition].window.innerWidth/window.innerHeightare read once, at memo-compute time, and the resulting clampedleft/topis frozen into the cached object. A pure orientation/resize event changes neither dependency, so even though React re-renders the widget every 5s via the playback poll (refetchInterval: 5_000, line 329), the memo returns its stale value. Thefixed-position element therefore keeps its oldleft/top, which now lies outside the shrunken viewport.Concretely: at landscape width 800, the drag-time clamp can store
xup to 744. On rotating to portrait width 360,getMobileWidgetStylewould re-clamplefttoMath.max(8, Math.min(304, 744)) = 304(on-screen) — but the memo never re-runs, so the staleleft: 744renders the 48px collapsed bubble entirely off the 360px-wide screen. The horizontal axis is the load-bearing one here; the collapsedtopis intentionally left unclamped (lines 243-244), which only widens the affected range. With the touch target off-screen,startDrag(pointerdown) can never fire, so the bubble is stuck until an unrelated state change re-runs the clamp.Suggested fix
Make the display clamp reactive to viewport size without mutating the persisted store position:
SpotifyMiniPlayer:useEffect, subscribe to windowresizeandorientationchange(throttled viarequestAnimationFrame, with a leading call and properremoveEventListenercleanup) andsetViewport({ w: innerWidth, h: innerHeight }). Guard withtypeof window !== "undefined"to match the SSR guards already ingetMobileWidgetStyle.viewport.w/viewport.hto the dependency arrays of both memos:useMemo(..., [collapsed, mobilePosition, viewport.w, viewport.h])useMemo(..., [mobilePosition, viewport.w, viewport.h])This re-runs
getMobileWidgetStyle/getMobileExpandedPanelStyleon resize, so the clamp (Math.min(innerWidth - 48 - 8, x)) pulls the bubble back into view and makes it tappable/draggable again.Do not call
setMobilePositionon resize. The position is persisted across sessions (ui.store.ts:2539) and its setter only lower-bounds (ui.store.ts:1766-1767,Math.max(8, ...)) — never upper-bounds against the viewport. Writing the shrunk-viewport clamp back would permanently overwrite the user's chosen spot (so rotating back to landscape would not restore it) and risks a resize→setState→persist feedback loop. Optionally harden the store setter to also upper-bound against the viewport, but keep that out of the resize path.Regression avoided:
mobileWidgetStyle/mobileExpandedPanelStyleare consumed only by the floating branch (lines 1031-1032, 1056), never by the desktop non-floating branch (line 1087), so recomputing them cannot reflow desktop, other chat modes, or any flex container. Positioning is purely inline JS clamp math with no CSS/theme/z-index/media-class involvement, so light/dark/sillytavern themes are untouched. The globally-attachedresizelistener still fires on desktop, but it only bumps internal state the desktop branch never renders (a harmless extra throttled render); and for aforceFloatingbubble that renders at >=768px, re-clamping on resize correctly keeps that bubble on-screen too — desired behavior. The persistence regression is sidestepped entirely by clamping for display only and never writing back.AI-investigated against v2.0.6 (packages/client); cited lines read and confirmed. Mobile layout verified by reading the computed Tailwind classes + globals.css, not on a device — please confirm on a phone before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Addressed in PR #3072 by commit
4146a380. Validated locally with pnpm check and pnpm smoke:ui.