Skip to content

perf(web): scope detail-page render cost during viewport changes - #812

Merged
Quick104 merged 3 commits into
mainfrom
perf/scope-detail-render-cost
Aug 28, 2026
Merged

Quick104 merged 3 commits into
mainfrom
perf/scope-detail-render-cost

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A — extracted from #805, which has the original profiling.

Browser UI that animates the content viewport — Brave's hover sidebar is the
reproducible case — made detail pages drop frames during resize, scroll and pointer
movement, while Home stayed smooth. @blurbery profiled this with Chrome DevTools
traces on a signed-in deployment; the numbers in #805 show paint down 16.6% and the
max graphics-pipeline slice down 75.1% on the original branch.

Approach

The cost was concentrated in three places. Everything here stays scoped to detail
pages rather than changing shared primitives — that scoping is the main difference
from #805, which applied several of these fixes app-wide.

Containment. The hero becomes one layout/paint boundary, so resizing it cannot
invalidate every rail below it, and its artwork sits behind contain: strict on the
browser's cheap image path. Five full-hero gradient elements — a tint, two side fades,
two bottom fades and a vignette — were each independently invalidated per frame; they
collapse into two contained scrim surfaces around the ambient glow, preserving the
original layer order exactly.

The hero backdrop's brightness()/saturate() filter is replaced by a flat
background wash: a filter on a full-hero element re-rasterizes on every frame of a
resize, a flat tint composites. The wash is exposed as --hero-backdrop-scrim so
themes keep the knob --hero-backdrop-brightness gave them — including the light
theme, which sets a heavier wash to match its brighter, more desaturated treatment.

Deferral. Detail pages stack several image-heavy rails below the fold, so
supporting sections get the same content-visibility treatment the home carousels
already use, and each clipped Embla viewport is isolated so one rail cannot invalidate
its neighbours.

MangaContent is deliberately excluded. Its only child is a single <ul> holding
every chapter, so a 24rem intrinsic placeholder would collapse the whole list and make
"Jump to chapter" smooth-scroll to an offset that is stale the moment the subtree lays
out. #805 applied it there.

Coalescing. Embla rebuilt its measurements on every frame of an animated resize;
container resizes now settle into one reInit while a standalone slide resize keeps
Embla's immediate path. The virtualized grid measures on the leading edge of a resize
and reconciles once at the end, so row geometry never lags the reflowed grid — a
trailing-only debounce left virtual rows overlapping the already-reflowed grid for the
whole settle window. Ambient colour cleanup is deferred by a microtask so an outgoing
detail surface cannot clear the property before the incoming one publishes, which was
repainting the full-page gradient between routes.

Interaction. Hover prefetch waits for a dwell, so a pointer sweeping a rail no
longer starts cache work for every card it crosses; keyboard focus and touch intent
still fire immediately. The card hover dim fades a fixed overlay instead of repainting
a full-card background colour.

Validation

Confirmed the containment and deferral actually apply in a live signed-in session
rather than only in the stylesheet: .item-detail-hero computes contain: content,
.hero-backdrop-artwork computes contain: strict with filter: none, the hero
renders two scrim layers around a contained ambient glow, --hero-backdrop-scrim
resolves to 25%, and supporting-section children compute
content-visibility: auto.

  • pnpm run build — passed
  • pnpm exec vitest run — 2619 passed
  • pnpm run lint — 0 errors (165 pre-existing warnings, unchanged baseline)
  • pnpm run format:check — passed

Risks

content-visibility: auto is the sharp edge here: it makes off-screen content
non-laid-out, which breaks anything that measures or scrolls into that subtree. The
MangaContent exclusion above is one instance found by inspection, and it is worth
checking whether any other detail section measures its own children.

The hero treatment is a visual change, not just a perf one — the scrim reproduces the
old gradient stack, but the artwork tint moves from a filter to a background wash.
Worth eyeballing in both light and dark themes; the light-theme scrim value is my
estimate of the equivalent of brightness(1.15) saturate(0.6), not a measurement.

Provenance

Ports the detail-page performance work from #805 by @blurbery, rebuilt against current
main and re-scoped. The app-wide backdrop-filter removal and the shared card hover
changes from that branch are deliberately not included; the navigation rewrite is
still open (see #805).

Not ported: the SeasonCarousel dwell-prefetch conversion, which needs a component
extraction for a row that typically holds under ten seasons.

AI Disclosure

  • Tool(s): Claude Code
  • Model(s): claude-opus-5[1m]
  • Involvement: Fully AI-generated, human verified — @Quick104 set the direction,
    decided which of the original branch's changes were in scope, and reviewed the
    result against a live deployment. The underlying profiling and the original fixes
    are @blurbery's.
  • Adversarial review: extracted during a defect-first review of perf(web): smooth detail layout, resizing, and navigation #805. Several changes
    from that branch were deliberately dropped here after review found they were
    app-wide fixes for a detail-page problem, and the MangaContent exclusion is a
    content-visibility defect found by that review rather than by the profiler.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

🤖 Generated with Claude Code

Browser UI that animates the content viewport — Brave's hover sidebar is
the reproducible case — made detail pages drop frames while Home stayed
smooth. The cost was concentrated in three places, all of which stay
scoped to detail pages rather than changing shared primitives.

Containment. The hero is one layout/paint boundary, so resizing it cannot
invalidate every rail below it, and its artwork sits behind `contain:
strict` on the browser's cheap image path. Five full-hero gradient
elements — a tint, two side fades, two bottom fades and a vignette — were
each independently invalidated per frame; they collapse into two contained
scrim surfaces around the ambient glow, preserving the original layer
order exactly.

The hero backdrop's `brightness()`/`saturate()` filter is replaced by a
flat background wash. A filter on a full-hero element re-rasterizes on
every frame of a resize; a flat tint composites. The wash is exposed as
`--hero-backdrop-scrim` so themes keep the knob that
`--hero-backdrop-brightness` gave them, including the light theme's
brighter, more desaturated treatment.

Deferral. Detail pages stack several image-heavy rails below the fold, so
supporting sections get the same `content-visibility` treatment the home
carousels already use, and each clipped Embla viewport is isolated so one
rail cannot invalidate its neighbours. MangaContent is deliberately
excluded: its only child is a single <ul> holding every chapter, and a
24rem intrinsic placeholder would collapse the whole list and make
"Jump to chapter" scroll to an offset that is stale the moment the subtree
lays out.

Coalescing. Embla rebuilt its measurements on every frame of an animated
resize; container resizes now settle into one reInit while a standalone
slide resize keeps Embla's immediate path. The virtualized grid measures
on the leading edge of a resize and reconciles once at the end, so row
geometry never lags the reflowed grid. Ambient colour cleanup is deferred
by a microtask so an outgoing detail surface cannot clear the property
before the incoming one publishes, which was repainting the full-page
gradient between routes.

Interaction. Hover prefetch waits for a dwell, so a pointer sweeping a
rail no longer starts cache work for every card it crosses; keyboard focus
and touch intent still fire immediately. The card hover dim fades a fixed
overlay instead of repainting a full-card background colour.

Ports the detail-page performance work from #805 by @blurbery, rebuilt
against main and re-scoped: the app-wide backdrop-filter removal and card
hover changes from that branch are deliberately not included.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 44 minutes.

View limit details

Limit details: You’ve used the included review currently available. Your 100 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 056bb6b4-fd4a-439a-98a1-e92b3aa533b0

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8f9ae and 5086966.

📒 Files selected for processing (20)
  • web/src/app.css
  • web/src/hooks/useAmbientColor.test.tsx
  • web/src/hooks/useAmbientColor.ts
  • web/src/hooks/useCarouselEmbla.test.tsx
  • web/src/hooks/useCarouselEmbla.ts
  • web/src/hooks/useDwellPrefetch.ts
  • web/src/hooks/useGridLayout.test.tsx
  • web/src/hooks/useGridLayout.ts
  • web/src/lib/carouselEmbla.test.ts
  • web/src/lib/carouselEmbla.ts
  • web/src/pages/ItemDetail/AudiobookContent.tsx
  • web/src/pages/ItemDetail/DetailHero.tsx
  • web/src/pages/ItemDetail/EbookContent.tsx
  • web/src/pages/ItemDetail/EpisodeContent.tsx
  • web/src/pages/ItemDetail/MovieContent.tsx
  • web/src/pages/ItemDetail/SeasonContent.tsx
  • web/src/pages/ItemDetail/SeriesContent.tsx
  • web/src/pages/ItemDetail/components/EpisodeCarousel.test.tsx
  • web/src/pages/ItemDetail/components/EpisodeCarousel.tsx
  • web/src/pages/ItemDetail/components/SeasonEpisodeGrid.tsx

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d12537fc5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/hooks/useGridLayout.ts Outdated
Comment on lines +53 to +54
if (resizeTimerRef.current === null) measure();
else window.clearTimeout(resizeTimerRef.current);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-measure when the grid crosses a responsive breakpoint

During a continuous resize that crosses a grid breakpoint after the first notification, this branch suppresses every subsequent measurement until 120 ms after resizing stops. CSS immediately changes the number of columns, but ItemGrid continues using the stale columnCount to calculate row count, visible ranges, and item indices, so cards can be omitted, duplicated, or laid out beyond the virtualizer's reserved height for the duration of a browser-sidebar animation or window drag. Preserve coalescing for ordinary width changes, but measure when the computed column count changes.

Useful? React with 👍 / 👎.

Quick104 and others added 2 commits August 28, 2026 12:08
…der-cost

# Conflicts:
#	web/src/pages/ItemDetail/components/SeasonEpisodeGrid.tsx
Addresses Codex review feedback on #812.

Coalescing every notification after the first was wrong for one case. CSS
changes the column count the instant a drag crosses a breakpoint, but
`columnCount` also slices the item list — `ItemGrid` derives `rowCount`,
`startIndex` and `cellCount` from it — so holding the stale value until the
resize settled omitted or duplicated cards for the rest of the gesture.

Reading the column count is a style read; the React render is what the
coalescing exists to protect. So the observer now reads the count on every
notification and measures when it changed, while ordinary width changes
within a breakpoint still collapse into one trailing reconcile.

The regression test fails against the previous behaviour: it starts a drag,
reflows the track to three columns mid-gesture, and asserts the layout
follows on that notification rather than 120ms after the drag stops.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Quick104
Quick104 merged commit 3eb93b6 into main Aug 28, 2026
4 checks passed
@Quick104
Quick104 deleted the perf/scope-detail-render-cost branch August 28, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant