Skip to content

perf(web): smooth sidebar collapse on item details - #504

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/optimize-web-performance
Jul 28, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/optimize-web-performance

Conversation

@Rhainland

@Rhainland Rhainland commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace the desktop sidebar's width animation with a fixed 260px surface and paired compositor transforms
  • commit an item-detail shell immediately, prefetch metadata, and reveal details when sidebar motion settles or reaches a bounded deadline
  • route remaining item links through the shared transition path and keep modifier/middle-click browser behavior intact
  • synchronize main content and the impersonation banner with the sidebar, including responsive and reduced-motion behavior
  • add orchestration, navigation, hook, item-detail, and CSS regression coverage

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

  • manually verified home → seeded movie detail in the local browser with no new console errors
  • focused sidebar suite: 10 files, 78 tests passed
  • full frontend suite: 233/235 files and 1,425/1,431 tests passed
    • the six failures are existing baseline failures in SeasonContent.test.tsx (missing QueryClient provider) and ServerStorageStep.test.tsx (missing ResizeObserver)
  • pnpm run lint: 0 errors, 158 existing warnings
  • pnpm run format:check
  • pnpm run build
  • make verify-local-paths
  • git diff --check

Review

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

  • Tool(s): Claude Code, Codex
  • Model(s): Claude model ID was not exposed to Codex; GPT-5
  • Involvement: AI-assisted
  • Adversarial review: Codex reviewed the complete sidebar change, reported eight findings, and the implementation was revised to address all eight before publication.

Summary by CodeRabbit

  • New Features
    • Added smoother, coordinated sidebar collapse and expansion animations.
    • Improved sidebar logo, labels, navigation rows, and notification badge transitions.
    • Added synchronized navigation transitions when opening item details from search, notifications, requests, and featured content.
    • Item detail pages now display a loading state until navigation transitions are ready.
    • Improved poster placeholder behavior while artwork loads.
  • Accessibility
    • Reduced-motion preferences now produce immediate sidebar and navigation changes.
  • Bug Fixes
    • Prevented horizontal scrolling and visual artifacts during sidebar and banner transitions.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Sidebar collapse and transform coordination

Layer / File(s) Summary
Transform-based sidebar surface
web/src/app.css, web/src/components/AppSidebar.logic.ts, web/src/components/AppSidebar.tsx, web/src/sidebarCollapseCss.test.ts, web/src/components/AppSidebar.test.tsx
Sidebar collapse uses fixed surface dimensions, transform transitions, cross-fading labels and branding, reduced-motion overrides, and synchronized impersonation-banner transforms.
Sidebar navigation and detail gate
web/src/components/Layout.tsx, web/src/components/ViewTransitionLink.tsx, web/src/components/sidebarItemNavigation.ts, web/src/hooks/*, web/src/components/*Navigation*, web/src/components/Layout.test.tsx, web/src/components/*Navigation.test.*
Layout prefetches item details, publishes target and visual sidebar states, intercepts eligible item links, and reveals details after sidebar settling or fallback deadlines.
View-transition link adoption
web/src/components/GlobalSearch.tsx, web/src/components/HeroBanner.tsx, web/src/components/NowListeningHero.tsx, web/src/components/RequestPosterCard.tsx, web/src/pages/Notifications.tsx, web/src/pages/RequestDetail.tsx, web/src/components/NowListeningHero.test.tsx
Item navigation from search, hero, listening, request, and notification surfaces uses the sidebar-aware link flow.
Item detail readiness and poster placeholder
web/src/pages/ItemDetail/index.tsx, web/src/pages/ItemDetail/DetailHero.tsx, web/src/pages/ItemDetail/*.test.tsx
Item detail rendering waits for sidebar readiness, query library IDs are validated centrally, and poster thumbnails render as separate fading placeholders.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • Silo-Server/silo-server#26: Updates catalog item metadata and item-card rendering, which may intersect with item-detail navigation and rendering paths.

Suggested labels: v1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: smoother sidebar collapse tied to item-detail navigation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Rhainland
Rhainland marked this pull request as ready for review July 27, 2026 22:23
@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
web/src/components/AppSidebar.tsx (1)

800-810: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Admin row is the only nav item still on plain Link.

Every other row now uses ViewTransitionLink, so /admin navigates without the shared viewTransition treatment. 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

196px collapse travel is duplicated instead of derived. The distance is SIDEBAR_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 from SIDEBAR_SURFACE_WIDTH - SIDEBAR_RAIL_WIDTH as 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 win

Duplicate 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 win

Subscribe to the breakpoint instead of sampling it per render.

This value also feeds useSidebarItemDetailsGate (Line 88), so crossing the lg breakpoint while already on an item route flips gatesItemDetails false→true on the next unrelated render and re-hides details that were already revealed. A subscription also avoids calling matchMedia on 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a784a1 and c43543d.

📒 Files selected for processing (28)
  • web/src/app.css
  • web/src/components/AppSidebar.logic.ts
  • web/src/components/AppSidebar.test.tsx
  • web/src/components/AppSidebar.tsx
  • web/src/components/GlobalSearch.tsx
  • web/src/components/HeroBanner.tsx
  • web/src/components/Layout.test.tsx
  • web/src/components/Layout.tsx
  • web/src/components/NowListeningHero.test.tsx
  • web/src/components/NowListeningHero.tsx
  • web/src/components/RequestPosterCard.tsx
  • web/src/components/SidebarItemNavigationProvider.tsx
  • web/src/components/ViewTransitionLink.test.tsx
  • web/src/components/ViewTransitionLink.tsx
  • web/src/components/sidebarItemNavigation.test.ts
  • web/src/components/sidebarItemNavigation.ts
  • web/src/components/sidebarItemNavigationContext.ts
  • web/src/hooks/useImmediateSidebarCollapse.test.tsx
  • web/src/hooks/useImmediateSidebarCollapse.ts
  • web/src/hooks/useSidebarItemDetailsGate.test.tsx
  • web/src/hooks/useSidebarItemDetailsGate.ts
  • web/src/pages/ItemDetail/DetailHero.test.tsx
  • web/src/pages/ItemDetail/DetailHero.tsx
  • web/src/pages/ItemDetail/index.test.tsx
  • web/src/pages/ItemDetail/index.tsx
  • web/src/pages/Notifications.tsx
  • web/src/pages/RequestDetail.tsx
  • web/src/sidebarCollapseCss.test.ts

Comment thread web/src/app.css
Comment on lines +1970 to +1972
#root {
overflow-x: clip;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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.

Suggested change
#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.

@Quick104
Quick104 merged commit 5d6f632 into Silo-Server:main Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants