Repository navigation
perf(web): smooth sidebar collapse on item details - #504
Conversation
📝 WalkthroughWalkthroughThe PR replaces sidebar width and margin animations with coordinated transform-based collapse, adds sidebar-aware item navigation and detail-readiness gating, adopts view-transition links across item destinations, and separates poster placeholders into fading overlays. ChangesSidebar collapse and transform coordination
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
web/src/components/AppSidebar.tsx (1)
800-810: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdmin row is the only nav item still on plain
Link.Every other row now uses
ViewTransitionLink, so/adminnavigates without the sharedviewTransitiontreatment. If that's intentional, a short comment would help; otherwise switch it for consistency.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/components/AppSidebar.tsx` around lines 800 - 810, Update the Admin navigation item in the showAdminNav block to use ViewTransitionLink instead of Link, preserving its existing destination, click handler, styling, active-state, icon, and label props so it receives the same shared view-transition behavior as the other navigation rows.web/src/app.css (1)
894-931: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
196pxcollapse travel is duplicated instead of derived. The distance isSIDEBAR_SURFACE_WIDTH - SIDEBAR_RAIL_WIDTH, but both the stylesheet and half of its contract test spell it out literally, so changing either width silently desynchronizes them.
web/src/app.css#L894-L931: introduce a single travel custom property (e.g.--sidebar-collapse-travel: 196px) and use it in the surface, inner, and main-stage transforms (and the banner rules).web/src/sidebarCollapseCss.test.ts#L75-L85: compute the expected value fromSIDEBAR_SURFACE_WIDTH - SIDEBAR_RAIL_WIDTHas Lines 60 and 71 already do, including the banner assertions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/app.css` around lines 894 - 931, Define a shared --sidebar-collapse-travel custom property in web/src/app.css from the sidebar width difference and replace every literal 196px collapse translation in .sidebar-surface, .sidebar-inner, .sidebar-main-stage, and banner rules with it. In web/src/sidebarCollapseCss.test.ts lines 75-85, derive expected travel from SIDEBAR_SURFACE_WIDTH - SIDEBAR_RAIL_WIDTH for all related assertions, including banners.web/src/components/Layout.test.tsx (1)
268-284: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate deadline test — this body is identical to the test above.
Both tests exercise the same path (rAF is stubbed to never fire in
beforeEach), so neither actually distinguishes "hover expansion holds the surface open" from "rAF never fires". Drop one or make the setups differ.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/components/Layout.test.tsx` around lines 268 - 284, Remove the duplicate deadline test in the Layout test suite, or alter its setup so it exercises a distinct hover-expansion scenario rather than the existing requestAnimationFrame-never-fires path. Keep only tests with meaningfully different behavior and assertions.web/src/components/Layout.tsx (1)
57-59: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winSubscribe to the breakpoint instead of sampling it per render.
This value also feeds
useSidebarItemDetailsGate(Line 88), so crossing thelgbreakpoint while already on an item route flipsgatesItemDetailsfalse→true on the next unrelated render and re-hides details that were already revealed. A subscription also avoids callingmatchMediaon every render.♻️ Subscribe via `useSyncExternalStore`
- // Breakpoint changes naturally cause other layout renders; navigation only - // needs the viewport value at the moment it is attempted. - const hasDesktopSidebar = window.matchMedia("(min-width: 64rem)").matches; + const hasDesktopSidebar = useSyncExternalStore( + subscribeDesktopSidebar, + getDesktopSidebarSnapshot, + );Outside the component:
const desktopSidebarQuery = () => window.matchMedia("(min-width: 64rem)"); function subscribeDesktopSidebar(onChange: () => void) { const query = desktopSidebarQuery(); query.addEventListener("change", onChange); return () => query.removeEventListener("change", onChange); } function getDesktopSidebarSnapshot() { return desktopSidebarQuery().matches; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/components/Layout.tsx` around lines 57 - 59, Replace the per-render window.matchMedia sampling used for hasDesktopSidebar with a useSyncExternalStore-backed breakpoint subscription. Add stable subscribe and snapshot helpers for the "(min-width: 64rem)" query, then consume that snapshot in the component so crossing the breakpoint updates reactively without re-sampling on unrelated renders.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/app.css`:
- Around line 1970-1972: Scope the `#root` overflow-x: clip rule to the root
sidebar-collapse transition state instead of applying it globally. Preserve
horizontal scrolling for wide tables, code blocks, and narrow or zoomed
viewports once the collapse attribute is absent.
---
Nitpick comments:
In `@web/src/app.css`:
- Around line 894-931: Define a shared --sidebar-collapse-travel custom property
in web/src/app.css from the sidebar width difference and replace every literal
196px collapse translation in .sidebar-surface, .sidebar-inner,
.sidebar-main-stage, and banner rules with it. In
web/src/sidebarCollapseCss.test.ts lines 75-85, derive expected travel from
SIDEBAR_SURFACE_WIDTH - SIDEBAR_RAIL_WIDTH for all related assertions, including
banners.
In `@web/src/components/AppSidebar.tsx`:
- Around line 800-810: Update the Admin navigation item in the showAdminNav
block to use ViewTransitionLink instead of Link, preserving its existing
destination, click handler, styling, active-state, icon, and label props so it
receives the same shared view-transition behavior as the other navigation rows.
In `@web/src/components/Layout.test.tsx`:
- Around line 268-284: Remove the duplicate deadline test in the Layout test
suite, or alter its setup so it exercises a distinct hover-expansion scenario
rather than the existing requestAnimationFrame-never-fires path. Keep only tests
with meaningfully different behavior and assertions.
In `@web/src/components/Layout.tsx`:
- Around line 57-59: Replace the per-render window.matchMedia sampling used for
hasDesktopSidebar with a useSyncExternalStore-backed breakpoint subscription.
Add stable subscribe and snapshot helpers for the "(min-width: 64rem)" query,
then consume that snapshot in the component so crossing the breakpoint updates
reactively without re-sampling on unrelated renders.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6a24dc95-870d-4cf2-b7c9-0481d0e2f2fe
📒 Files selected for processing (28)
web/src/app.cssweb/src/components/AppSidebar.logic.tsweb/src/components/AppSidebar.test.tsxweb/src/components/AppSidebar.tsxweb/src/components/GlobalSearch.tsxweb/src/components/HeroBanner.tsxweb/src/components/Layout.test.tsxweb/src/components/Layout.tsxweb/src/components/NowListeningHero.test.tsxweb/src/components/NowListeningHero.tsxweb/src/components/RequestPosterCard.tsxweb/src/components/SidebarItemNavigationProvider.tsxweb/src/components/ViewTransitionLink.test.tsxweb/src/components/ViewTransitionLink.tsxweb/src/components/sidebarItemNavigation.test.tsweb/src/components/sidebarItemNavigation.tsweb/src/components/sidebarItemNavigationContext.tsweb/src/hooks/useImmediateSidebarCollapse.test.tsxweb/src/hooks/useImmediateSidebarCollapse.tsweb/src/hooks/useSidebarItemDetailsGate.test.tsxweb/src/hooks/useSidebarItemDetailsGate.tsweb/src/pages/ItemDetail/DetailHero.test.tsxweb/src/pages/ItemDetail/DetailHero.tsxweb/src/pages/ItemDetail/index.test.tsxweb/src/pages/ItemDetail/index.tsxweb/src/pages/Notifications.tsxweb/src/pages/RequestDetail.tsxweb/src/sidebarCollapseCss.test.ts
| #root { | ||
| overflow-x: clip; | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
#root { overflow-x: clip } is app-wide, not transition-scoped.
The overhang it guards against only exists for the length of the collapse, but the rule permanently clips any horizontally overflowing content in the app (wide tables, code blocks, zoomed/narrow viewports), where the browser would otherwise offer a horizontal scrollbar — content becomes unreachable rather than scrollable. Consider scoping it to the transition, e.g. only while a root sidebar-collapse attribute is present.
♻️ Scoped alternative
- `#root` {
- overflow-x: clip;
- }
+ :root[data-sidebar-collapsed="true"] `#root`,
+ :root[data-sidebar-visual-collapsed="true"] `#root` {
+ overflow-x: clip;
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #root { | |
| overflow-x: clip; | |
| } | |
| :root[data-sidebar-collapsed="true"] `#root`, | |
| :root[data-sidebar-visual-collapsed="true"] `#root` { | |
| overflow-x: clip; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/app.css` around lines 1970 - 1972, Scope the `#root` overflow-x: clip
rule to the root sidebar-collapse transition state instead of applying it
globally. Preserve horizontal scrolling for wide tables, code blocks, and narrow
or zoomed viewports once the collapse attribute is absent.
Summary
Why
Entering an item detail page animated sidebar width and main-content margin while a blurred surface and movie artwork were being rasterized. That repeatedly triggered layout and made the collapse appear laggy or step through frozen frames. The new path keeps layout geometry stable during motion and uses compositor-friendly transforms, while detail loading happens behind a lightweight route shell.
Validation
SeasonContent.test.tsx(missing QueryClient provider) andServerStorageStep.test.tsx(missing ResizeObserver)pnpm run lint: 0 errors, 158 existing warningspnpm run format:checkpnpm run buildmake verify-local-pathsgit diff --checkReview
An adversarial code review identified eight material edge cases: hover-expanded reveal stalls, unrelated animation detection, missed Now Listening interception, hidden-tab requestAnimationFrame suspension, untested modified clicks, missing Layout orchestration coverage, brittle CSS assertions, and impersonation-banner desynchronization. All were addressed and covered where applicable.
AI Disclosure
Summary by CodeRabbit