Skip to content

fix(library): render album/artist + popover through a portal#77

Merged
InstaZDLL merged 1 commit into
mainfrom
fix/album-artist-popover-portal
May 20, 2026
Merged

fix(library): render album/artist + popover through a portal#77
InstaZDLL merged 1 commit into
mainfrom
fix/album-artist-popover-portal

Conversation

@InstaZDLL
Copy link
Copy Markdown
Owner

@InstaZDLL InstaZDLL commented May 20, 2026

Summary

  • Follow-up to fix(library): hoist album/artist grid row above siblings while + popover is open #75. The pure z-index fix wasn't enough in practice — visually the popover still painted under the row below, and it was anchored to the bottom of the entire tile (below the title + metadata) instead of being snapped to the + button.
  • Two distinct symptoms, one root cause: the popover's absolute top-full right-0 was resolved relative to the card root (which spans avatar + name + metadata), and the virtualizer's transform: translateY() rows created stacking contexts that boxed the popover's z-50 inside its row.

Fix

  • The popover is now optionally rendered through createPortal(..., document.body) when an anchorEl is supplied.
  • Each + button registers its DOM node in a Map<id, HTMLButtonElement> ref; the popover consumes that ref's element as anchor, computes top / left from getBoundingClientRect, and keeps it in sync via a ResizeObserver + capture-phase scroll + resize listeners.
  • Result: the popover lives at the document root (no ancestor stacking context can clip it) and is anchored directly under the + button, not under the whole tile.
  • TrackTable keeps its in-flow popover: its row is a single flex line, its z-index fix from fix(library): hoist track row above siblings while + popover is open #74 works.

Test plan

  • Library → Albums tab → hover a card → click +: popover appears just below the + button (not at the bottom of the title block), is fully opaque, no cover of any other row bleeding through.
  • Same on the last row of the viewport: popover stays on screen (positioned below the button — clipping is fine here, it's a small grid item).
  • Same on artists tab.
  • Scroll while popover open: position updates with the trigger.
  • Resize window while popover open: same.
  • Songs tab (TrackTable): unchanged, regression check.

Follow-up to #75. The z-index fix wasn't enough in practice: the
virtualizer rows use `transform: translateY()`, which creates a
stacking context, and the popover's `top-full right-0` resolved to
"below the entire tile" rather than "below the + button". Some
ancestor (likely the page scroller's own transform / will-change set
by tanstack-virtual) was clipping or restacking the popover so the
following row's avatar/cover still bled through.

Switch the popover to a `createPortal(..., document.body)` render
path. Each `+` button registers its DOM node in a `Map<id, HTMLButtonElement>`
ref; the popover takes that node as `anchorEl` and positions itself
via `getBoundingClientRect` + scroll/resize listeners. Now anchored
right under the trigger button (not below the full tile), and lives
at the document root so stacking contexts no longer apply.

TrackTable keeps its current in-flow popover — its z-index fix from
#74 works because the row layout is a single flex line, not a CSS
grid of multiple cards.
@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented May 20, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0)

Grey Divider


Action required

1. Popover clicks trigger tile 🐞 Bug ≡ Correctness
Description
AddToPlaylistPopover only stops double-click propagation; in portal mode, React synthetic events
still bubble to the originating component tree, so clicking a playlist row can also fire the
album/artist tile onClick. This can navigate/open the album/artist while the user is trying to add
to a playlist.
Code

src/components/views/LibraryView.tsx[R1385-1411]

Evidence
The popover container only stops onDoubleClick, but its menu-item buttons use plain onClick
without stopping propagation; album/artist tiles have onClick handlers, so those clicks can bubble
and trigger tile actions even when the popover is portaled to document.body.

src/components/views/LibraryView.tsx[1384-1454]
src/components/views/LibraryView.tsx[1607-1619]
src/components/views/LibraryView.tsx[1902-1907]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
When the popover is rendered with `createPortal`, React’s event system still bubbles events through the original React tree. Since the popover only stops `onDoubleClick`, normal `click` events from menu items can bubble to the album/artist tile `onClick` handlers and trigger navigation/selection unintentionally.

### Issue Context
- Popover root currently has `onDoubleClick={(e) => e.stopPropagation()}` only.
- Album and artist tiles are clickable (`onClick={() => onAlbumClick(...)}` / `onArtistClick(...)}`).

### Fix Focus Areas
- src/components/views/LibraryView.tsx[1385-1445]

### Implementation notes
- Add `onClick={(e) => e.stopPropagation()}` (and optionally `onMouseDown={(e) => e.stopPropagation()}`) to the popover container (`data-add-to-playlist-popover`).
- Alternatively (or additionally), stop propagation in each playlist row button’s `onClick` before calling `onPick`/`onCreate`.
- Keep the existing outside-click handling working (your `closest([...])` checks will still behave correctly).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Popover can go offscreen 🐞 Bug ≡ Correctness
Description
The portal positioning always uses top = rect.bottom + 4 and left = rect.right - 224 without
clamping/flipping, so triggers near the bottom of the viewport (or within 224px of the left edge)
can produce a partially/fully off-screen menu. This makes playlist actions inaccessible in common
edge placements (e.g., first column or near window bottom).
Code

src/components/views/LibraryView.tsx[R1389-1400]

Evidence
The portal-mode style sets a fixed top below the trigger and a fixed left derived from
rect.right - 224 with no bounds checks; given the popover’s potentially large height (scroll area
+ header/footer), it can overflow the viewport bottom, and it can overflow left when `rect.right <
224`.

src/components/views/LibraryView.tsx[1363-1401]
src/components/views/LibraryView.tsx[1410-1468]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The fixed-position portal popover computes `top`/`left` directly from `getBoundingClientRect()` and a constant width, but does not clamp to the viewport or flip above the trigger when there isn’t enough space below. This can render the menu off-screen.

### Issue Context
- Current logic:
 - `top = rect.bottom + 4`
 - `left = rect.right - POPOVER_WIDTH`
- The menu can be tall (header + scrollable list + footer), so bottom overflow is realistic.

### Fix Focus Areas
- src/components/views/LibraryView.tsx[1363-1403]

### Implementation notes
- Clamp horizontally:
 - `left = Math.max(MARGIN, Math.min(left, window.innerWidth - POPOVER_WIDTH - MARGIN))`
 - This specifically fixes the `rect.right < POPOVER_WIDTH` (first-column) case.
- Handle vertical overflow by measuring popover height (e.g., `const popoverRef = useRef<HTMLDivElement>(null)` + `useLayoutEffect` after `rect` updates):
 - Prefer below: `top = rect.bottom + 4`
 - If `top + height > window.innerHeight - MARGIN`, flip above: `top = rect.top - 4 - height`
 - Then clamp: `top = Math.max(MARGIN, Math.min(top, window.innerHeight - height - MARGIN))`
- Keep the existing scroll/resize listeners; the clamp/flip should apply on each `update()`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@InstaZDLL has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 57 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 15422a1c-766f-4178-ac35-6bdb1713a702

📥 Commits

Reviewing files that changed from the base of the PR and between 24d0037 and 8c262f8.

📒 Files selected for processing (1)
  • src/components/views/LibraryView.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/album-artist-popover-portal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added scope: frontend React/Vite frontend (src/) type: fix Bug fix size: m 50-200 lines labels May 20, 2026
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · 0 duplication

Metric Results
Complexity 8
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@InstaZDLL InstaZDLL self-assigned this May 20, 2026
@InstaZDLL InstaZDLL merged commit 929f182 into main May 20, 2026
14 checks passed
@InstaZDLL InstaZDLL deleted the fix/album-artist-popover-portal branch May 20, 2026 20:27
Comment on lines 1385 to 1411
<div
data-add-to-playlist-popover
role="menu"
onDoubleClick={(e) => e.stopPropagation()}
className="absolute top-full right-0 mt-1 z-50 w-56 rounded-xl border border-zinc-200 bg-white shadow-lg dark:border-zinc-700 dark:bg-surface-dark-elevated dark:shadow-black/40 overflow-hidden animate-fade-in"
style={
anchorEl
? rect
? {
position: "fixed",
// Anchor the right edge to the trigger's right edge,
// matching the in-flow `right-0` behaviour. Drop 4 px
// below the trigger to match `mt-1`.
top: rect.bottom + 4,
left: rect.right - POPOVER_WIDTH,
width: POPOVER_WIDTH,
}
: { position: "fixed", visibility: "hidden" }
: undefined
}
className={`${
anchorEl
? "z-100"
: "absolute top-full right-0 mt-1 z-50 w-56"
} rounded-xl border border-zinc-200 bg-white shadow-lg dark:border-zinc-700 dark:bg-surface-dark-elevated dark:shadow-black/40 overflow-hidden animate-fade-in`}
>
<div className="text-[10px] font-bold tracking-widest text-zinc-400 uppercase px-3 pt-3 pb-2">
{t("trackActions.addToPlaylist")}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Popover clicks trigger tile 🐞 Bug ≡ Correctness

AddToPlaylistPopover only stops double-click propagation; in portal mode, React synthetic events
still bubble to the originating component tree, so clicking a playlist row can also fire the
album/artist tile onClick. This can navigate/open the album/artist while the user is trying to add
to a playlist.
Agent Prompt
### Issue description
When the popover is rendered with `createPortal`, React’s event system still bubbles events through the original React tree. Since the popover only stops `onDoubleClick`, normal `click` events from menu items can bubble to the album/artist tile `onClick` handlers and trigger navigation/selection unintentionally.

### Issue Context
- Popover root currently has `onDoubleClick={(e) => e.stopPropagation()}` only.
- Album and artist tiles are clickable (`onClick={() => onAlbumClick(...)}` / `onArtistClick(...)}`).

### Fix Focus Areas
- src/components/views/LibraryView.tsx[1385-1445]

### Implementation notes
- Add `onClick={(e) => e.stopPropagation()}` (and optionally `onMouseDown={(e) => e.stopPropagation()}`) to the popover container (`data-add-to-playlist-popover`).
- Alternatively (or additionally), stop propagation in each playlist row button’s `onClick` before calling `onPick`/`onCreate`.
- Keep the existing outside-click handling working (your `closest([...])` checks will still behave correctly).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: frontend React/Vite frontend (src/) size: m 50-200 lines type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant