Skip to content

Speed up iOS Safari drawer interactions - #1356

Merged
SawyerHood merged 1 commit into
mainfrom
bb/profile-ios-safari-app-performance-thr_fsx4hg38ww
Aug 11, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/profile-ios-safari-app-performance-thr_fsx4hg38ww

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

  • move mobile sidebar open and close state updates after their compositor transitions
  • keep the sidebar trigger active and contain keyboard focus without changing the large background subtree
  • use one translate property for Tailwind and drag motion to prevent animation snaps
  • window every sidebar list and remove forced layout reads from prompt and timeline hot paths
  • defer heavy right-panel content until the bottom-sheet entrance finishes

Root cause

WebKit recalculated styles for large subtrees when inert, visibility, and drawer state changed inside tap handlers. These recalculations took about 280 ms and blocked the first animation frame. The right-panel sheet also mounted its full content inside the opening tap.

The updated paths start each compositor animation first. React applies the expensive state change after the panel reaches its resting position.

Measured impact

  • sidebar touch taps fell from about 280 ms to 0-2 ms in WebKit
  • right-panel open taps fell from 325-370 ms to about 2 ms in WebKit
  • Chrome and WebKit both keep the trigger active, close on a second press, and reopen correctly

Validation

  • pnpm exec turbo run typecheck test build --filter=@bb/app
  • 336 test files passed
  • 2,537 tests passed
  • production build passed

@SawyerHood

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

I am SlopCop. I started the security, code quality, architecture, performance, and browser review.

@SawyerHood
SawyerHood merged commit 5fcb4b3 into main Aug 11, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/profile-ios-safari-app-performance-thr_fsx4hg38ww branch August 11, 2026 23:36
return;
}

applySidebarMobileDragStyles({ progress: 1, settling: true });

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — The drawer passes taps to the page during its open transition

openMobile stays false for 220 ms after this call. The panel remains inert, and the closed backdrop ignores pointer input.

Chromium confirmed that an inert overlay passes a tap to the control below it. A rapid second tap can start an unintended action.

Make the backdrop receive pointer input before motion starts. Keep it active through the state commit.

// accessibility tree for hundreds of milliseconds. Keyboard and
// assistive-technology activation leave the trigger focus-visible, so
// keep the modal focus move for those paths.
const shouldMoveFocus =

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — The modal can leave focus in a background input

This check depends on :focus-visible, which does not cover a swipe or all assistive input.

A swipe can leave a background input focused. Normal keys can then change that input because the trap handles only Tab and Escape.

Move focus to a small guard at open start. Contain later focus changes until the drawer closes.

if (!rendersAsDrawer) {
return;
}
if (isDrawerOpen) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — Reduced motion waits for the full fallback

The animation event can be absent when reduced motion is on. This timer then keeps the skeleton for at least 700 ms.

Browser QA saw real content near one second after open. Realize on the next frame for reduced motion.

The drawer shell can also send the settle callback for zero-duration motion.

const observer = new ResizeObserver(() => {
refreshMaxScrollOffset(element);
});
observer.observe(element);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — The resize observer misses content-only height changes

This observer watches the fixed scroll port. An image load or disclosure can change scrollHeight without changing this box.

The old maximum can restore bottom attachment while the user is above the real bottom.

Observe an inner content wrapper. You can also refresh the cache when user scroll starts.

// A sidebar can contain many short sibling lists. Rendering each short list
// in full makes their aggregate offscreen subtree large, so every non-empty
// list participates in the shared-scrollport window.
const windowingEnabled =

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — Short mobile lists get the wrong placeholder height

Every short list now uses the window path. Each list starts with 30 px, but mobile rows use 36 or 40 px.

Offscreen lists cannot correct this value before display. Their later size change can move the scrollbar and visible rows.

Use a coarse-pointer CSS value or a shared scroll-port measurement.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5

The app opens a side box before it does the hard work. It is like opening a toy box before you fill it.

This makes the box move faster. Some taps and scrolls can still go to the wrong place.

Findings

  • High: The open sidebar stays inert for 220 ms. A second tap can reach and start an action behind it.
  • High: A swipe can leave focus in a background input. Normal keys can then change hidden content.
  • Medium: Reduced motion can show the panel skeleton for about one second.
  • Medium: Short mobile lists use a 30 px placeholder for rows that are 36 or 40 px.
  • Medium: The sticky-scroll cache can miss content-only height changes. It can then move a user back to the bottom.

I posted one inline comment for each defect.

Checks

The full app test passed 336 files and 2,537 tests. The app type check and all GitHub checks passed.

Browser checks used Chromium at 390 by 844. The sidebar motion, close, Escape, and both panel paths worked.

This browser cannot run WebKit. The Chromium check does not replace an iOS Safari check.

The browser also found an old Vaul body-style cost. I did not assign that old cost to this pull request.

Architecture

The root and thread views copy the same panel settle process. A shared hook can keep these paths equal.

Each short list also creates its own observer. A shared sidebar observer can reduce this work.

This review used comment-only actions. It did not approve the pull request or request changes.

SawyerHood added a commit that referenced this pull request Aug 12, 2026
Follow-up to #1356. This fixes findings 1 and 2 from the SlopCop review
of that PR.

## Backdrop tap-through during the deferred open

The deferred mobile open starts the slide 220 ms before the React state
commit. In that window the panel is `inert` and the backdrop class still
reads `pointer-events-none`, so a rapid second tap fell through to the
page below the drawer. `applySidebarMobileDragStyles` now writes inline
`pointer-events: auto` on the backdrop whenever the panel is on screen.
The clear helper and the state commit remove the override, so the
class-driven state owns pointer input again after settle. A tap the
backdrop absorbs mid-slide does not cancel the open; the settle guard
swallows the dismiss.

## Stale sticky-bottom scroll cache

`useStickyBottomScroll` caches the maximum scroll offset and refreshes
it from a `ResizeObserver` on the scroll port. The port box is fixed, so
content-only height changes (an image load, a disclosure toggle) never
fired the observer. The stale cache could re-stick a user at the old
bottom, or block the re-stick at the real bottom. The hook now exposes a
`contentRef`, and `TimelineDetailScroll` wraps its children in a div
bound to it. The observer watches both boxes and feeds the same cache.

## Tests

- `sidebar.test.tsx`: the backdrop intercepts taps during the deferred
open, the absorbed tap does not cancel the open, and no stale override
survives the close.
- `useStickyBottomScroll.test.tsx`: a content-only growth refreshes the
cache, the old bottom does not re-stick, and the real bottom does.

`turbo run test --filter=@bb/app`: 2539 tests pass. Typecheck passes.

> AGENT GENERATED: by Claude Fable 5

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

Co-authored-by: Claude Fable 5 <[email protected]>
fahmiirsyadk pushed a commit to fahmiirsyadk/bb that referenced this pull request Aug 12, 2026
Follow-up to get-bb#1356. This fixes findings 1 and 2 from the SlopCop review
of that PR.

## Backdrop tap-through during the deferred open

The deferred mobile open starts the slide 220 ms before the React state
commit. In that window the panel is `inert` and the backdrop class still
reads `pointer-events-none`, so a rapid second tap fell through to the
page below the drawer. `applySidebarMobileDragStyles` now writes inline
`pointer-events: auto` on the backdrop whenever the panel is on screen.
The clear helper and the state commit remove the override, so the
class-driven state owns pointer input again after settle. A tap the
backdrop absorbs mid-slide does not cancel the open; the settle guard
swallows the dismiss.

## Stale sticky-bottom scroll cache

`useStickyBottomScroll` caches the maximum scroll offset and refreshes
it from a `ResizeObserver` on the scroll port. The port box is fixed, so
content-only height changes (an image load, a disclosure toggle) never
fired the observer. The stale cache could re-stick a user at the old
bottom, or block the re-stick at the real bottom. The hook now exposes a
`contentRef`, and `TimelineDetailScroll` wraps its children in a div
bound to it. The observer watches both boxes and feeds the same cache.

## Tests

- `sidebar.test.tsx`: the backdrop intercepts taps during the deferred
open, the absorbed tap does not cancel the open, and no stale override
survives the close.
- `useStickyBottomScroll.test.tsx`: a content-only growth refreshes the
cache, the old bottom does not re-stick, and the real bottom does.

`turbo run test --filter=@bb/app`: 2539 tests pass. Typecheck passes.

> AGENT GENERATED: by Claude Fable 5

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

Co-authored-by: Claude Fable 5 <[email protected]>
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…7) (#1893)

## What was wrong

On compact viewports `AppLayout` mounts the sidebar before the lazy
route element, and `SidebarMobilePanel` always rendered its children.
`ProjectList`, its DnD contexts, search hooks and slot subscriptions
therefore ran on the boot critical path for a panel that sits translated
off-screen and `inert` (audit finding A7).

## What changed

- `apps/app/src/components/ui/sidebar.tsx`: `SidebarProvider` owns a
one-shot realization latch (`isMobileSidebarRealized`). The panel
element stays mounted from the first commit (the swipe helpers select
it; no visibility flip, per #1261/#1356), but the compact `Sidebar`
renders its children only once the latch is set:
- `openMobileSidebar()` (trigger tap) realizes at slide start so the
subtree commits during the slide.
- The swipe path and direct `setOpenMobile(true)` callers realize in the
same render (render-time state adjust).
- A drawer that stays closed realizes from `requestIdleCallback` with a
1 s timeout; browsers without idle callbacks use two animation frames
plus the same 1 s timeout.
- The latch never resets, so app/settings/tools mode swaps and reopen
keep the retained subtree. Desktop renders children directly as before.

## How you verified

- New tests in `apps/app/src/components/ui/sidebar.test.tsx` (fail
before, pass after): closed panel is mounted, inert and empty at boot,
then realized in place after the settle window; `requestIdleCallback` is
preferred with `timeout: 1000` and frames alone do not realize; a
deferred open realizes before React state flips and content is retained
across close; desktop SSR renders children synchronously; swipe-open
realizes in the same commit.
- `pnpm exec turbo run test --filter=@bb/app --
src/components/ui/sidebar.test.tsx
src/components/layout/AppLayoutSidebar.test.tsx
src/components/plugin/PluginNavSidebarItems.test.tsx` and `--
src/components/layout/ src/components/sidebar/ ...`: all pass (37 files,
289 tests).
- `pnpm exec turbo run typecheck lint --filter=@bb/app`: pass; lint
warning count unchanged (148 before and after, none in sidebar.tsx).

Fixes: part of the mobile / iOS Safari performance program (verified
sweep report in the bb thread; no single issue).


## Stack context

Layer 14 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below): `bb/mobile-perf/icon-core-map` (#1892).
- Next layer: `bb/mobile-perf/pierre-pool-and-route-closure` (#1894).
- Audit findings addressed: see title IDs. Review: approved.
- Wire/contract: None. No server/daemon wire, protocol version, CLI,
config, or plugin API changes. SidebarContext (internal, apps/app only)
gains `isMobileSidebarRealized: boolean`.

> AGENT GENERATED: by Claude Code (claude-mangosteen-eap)

Co-authored-by: Claude <[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