Skip to content

Pause animations in collapsed height transitions - #768

Merged
SawyerHood merged 1 commit into
mainfrom
fix/collapsed-preview-overflow-loop
Jul 17, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
fix/collapsed-preview-overflow-loop

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

  • pause descendant CSS animations while HeightTransition content is collapsed
  • preserve mounted child state and resume animations automatically when visible
  • add regression coverage for the collapsed and restored states

Root cause

After refreshing the affected workspace, the page was back at 60 FPS with no mutation loop, but two Working... shimmer animations continued running inside height: 0, opacity: 0, overflow-clipped wrappers. The indicators were not visible or hit-testable, but Chromium continued advancing and painting their background-position animations.

Browser profiling measured about 0.73 seconds of renderer task time per five seconds with the hidden shimmers running versus 0.027 seconds with them paused. The production build now emits the descendant animation-play-state: paused selector for collapsed transitions.

Validation

  • browser bounding-rect, clipping, and hit-test inspection of the hidden indicators
  • reversible runtime pause profiling on the live page
  • pnpm exec turbo run test --filter=@bb/app -- --run src/components/ui/height-transition.test.tsx src/components/thread/timeline/GeneratedConversationMessage.test.tsx
  • pnpm exec turbo run typecheck build --filter=@bb/app
  • pnpm exec turbo run test --filter=@bb/app --force (242 files, 1,602 tests)

@SawyerHood
SawyerHood merged commit 497bf7b into main Jul 17, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the fix/collapsed-preview-overflow-loop branch July 17, 2026 02:52
SawyerHood added a commit that referenced this pull request Sep 18, 2026
…me (#3906)

## Human comments

## What was wrong

With an agent working and the user doing nothing, the app kept roughly
one CPU core busy. The cause is the working shimmer: `.animate-shine`
animates `background-position` and `.animate-shine-icon` animates
`mask-position`. The compositor cannot run either, so every frame at 60
fps is a full main-thread style, paint, layerize, and commit pass, and
the cost of that pass grows with the weight of the page around the
label.

A DevTools trace of an idle app with one working thread showed 804
main-thread frames in 13.6 s with about 1% of the time in JavaScript.
Every frame repainted the same four nodes (two title spans, two status
icons). By OS thread: renderer main 47% of a core, GPU 28%, browser 13%,
compositor 8.5%, Viz 7%.

There is no single regressing commit. The text sweep dates from the
initial commit, the icon mask from #86, and `will-change: transform`
from #1880 measured neutral (52.6% vs 50.7%). What grew is the page: on
a synthetic timeline the same animation costs 41%, 52%, and 76% of a
core at 300, 2,500, and 8,000 rows. The sweep also kept costing CPU
while hidden, which is what #768 worked around with
`animation-play-state`.

## What changed

The sweep is now an animated image used as a mask, with the same look.

- `apps/app/src/components/ui/shine-sweep.png`: a 2.6 KB, 128x2 APNG
whose alpha band (50% to 100% to 50%) travels left to right once a
second. `theme.css` stretches it over the element with `mask-size: 100%
100%`. The mask carries alpha only, so one file serves every theme,
label, and icon; the text stays real DOM text.
- Chromium advances animated images on the compositor, so the page's
main thread does no work for the shimmer, and a hidden mask is not drawn
at all.
- `apps/app/scripts/generate-shine-sweep.mjs` writes the APNG with no
dependencies (`pnpm --filter @bb/app generate:shine-sweep`). The file
stays under Vite's 4 KB inline limit, so production CSS embeds it as a
data URI and no separate request is made.
- `.animate-shine` and `.animate-shine-icon` share one rule; the `shine`
and `shine-mask` keyframes are gone. Reduced motion and `inert` /
`aria-hidden` hosts set `mask-image: none`.
- `ThreadStatusGlyph`: removed the `animation-duration: 1.5s` override
on the plugin status icon, which no longer has any effect.

Behavior differences from the CSS sweep:

- Icons sweep once a second like labels, instead of on their own 2.6 s
cycle, and their edge alpha is 0.5 instead of 0.45.
- The sweep redraws 20 to 30 times a second instead of 60.
- All shimmering elements share the image's clock, so they sweep in
phase.
- The cadence lives in the file, so `animation-duration` /
`animation-play-state` no longer affect it.

No wire, CLI, config, or plugin API change. Plugins that use the classes
get the new behavior from the host CSS.

## How you verified

- New tests in `theme.test.ts` (fail before, pass after): the shared
mask rule and absence of a CSS animation, the reduced-motion and
hidden-host rules, and the APNG itself (frame count matches its control
chunk, loops forever, runs 1 s, under 4 KB).
- `pnpm exec turbo run test --filter=@bb/app --
src/components/ui/theme.test.ts
src/components/sidebar/ThreadRow.test.tsx
src/components/ui/height-transition.test.tsx
src/components/ui/scroll-to-bottom-button.test.tsx`: 127 tests pass.
- `pnpm exec turbo run typecheck lint --filter=@bb/app`: pass, 0 lint
errors.
- Other readers of `theme.css`: `pnpm exec turbo run test
--filter=@bb/mobile` (307 tests) and `pnpm exec turbo run generate
--filter=@bb/plugin-build` pass.
- `pnpm exec turbo run build --filter=@bb/app`: the PNG is inlined into
the main CSS byte-for-byte, no separate asset is emitted, and
`check-bundle-budget.mjs` passes.
- Measured in headless Chromium (per-process CPU from `/proc`, frame and
paint counts from a trace):

| | main-thread frames/s | paints/s | draws/s | CPU (% of a core) |
|---|---|---|---|---|
| Ladle streaming story, before | 60 | 240 | 60 | 13.3 |
| Ladle streaming story, after | 0 | 0 | 20 | 4.6 |
| Synthetic 2,500-row page, before | 60 | 300 | 60 | 53 |
| Synthetic 2,500-row page, after | 0 | 0 | 20 | 8 to 9 |
| Same page, shimmer inside a collapsed container, before | 60 | 60 | 0
| 32 |
| Same page, shimmer inside a collapsed container, after | 0 | 0 | 0 |
0.8 (idle) |

- Look: the mask frames use the same triangle profile as the CSS
gradient, a side-by-side real-time capture of the Ladle stories shows
the same sweep in Chromium, and the owner compared it with the old sweep
on an iPhone.
- Not verified: Firefox, and the CPU cost in WebKit (only the look was
checked there).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

Co-authored-by: Claude Code <[email protected]>
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