Skip to content

Studio: keep the composer still when switching chats in WebKit - #16076

Merged
shimmyshimmer merged 2 commits into
mainfrom
studio-composer-switch-glitch
Oct 30, 2026
Merged

shimmyshimmer merged 2 commits into
mainfrom
studio-composer-switch-glitch

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

What changed

Switching chats no longer makes the composer jump sideways for a frame or two. This happened in WebKit (the macOS Desktop app, Safari) when classic scroll bars are showing, for example with a mouse connected.

Why

In WebKit, the thread viewport's scrollbar-gutter: stable both-edges reserves both gutters on the right, so watchThreadGutter shifts the column back with data-gutter-shift. The composer dock measures that column to set its side padding (--composer-dock-inset-*). When a scroll bar appears (for example, a chat's messages arrive after the switch), the dock's ResizeObserver could fire before the gutter watcher's. The dock then measured the unshifted column and padded the composer 10px/40px instead of 25px/25px. That put the composer one scroll bar width (about 15px) left of centre until the gutter caught up.

  • The dock calls the new syncThreadGutter(viewport) before it measures, so it always measures the shifted column.
  • watchThreadGutter attaches in a layout effect instead of a passive one, so a viewport remounted by a thread switch is shifted before its first paint.

Verification

  • npm run typecheck, npm run build: clean.
  • npm test: 14,459 of 14,463 pass. The 4 failures are in hub-gguf-card-unified-budget.test.ts and fail identically on main.
  • New tests in tests/thread-gutter.test.ts: syncThreadGutter applies the shift before the gutter's own observer fires, and the source asserts the layout-effect watcher and the sync-before-measure order. They fail on main.
  • Playwright WebKit with classic scroll bars forced, switching between two long chats while logging the composer's position at the end of every DOM mutation:
    • Before: on the first switch to a chat that wasn't loaded yet, the dock padding went to 10px/40px and the composer to x=473 instead of 488. This happened on every run.
    • After: x=488 and symmetric padding on all 90 switches.
  • Chromium: unchanged. 0 of 16 switches off-position, same settled insets.

Not covered

Headless WebKit corrects the bad padding before it paints, so the visible one-frame jump itself was only seen in a screen recording from the Desktop app, not reproduced here.

The dock's ResizeObserver could measure the message column before the gutter
watcher shifted it, so with classic scroll bars the composer was padded
10px/40px and painted a scrollbar width left of centre for a frame or two.
The dock now syncs the gutter before measuring, and the watcher attaches in a
layout effect so a remounted viewport is shifted before the first paint.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T07:32:54.155368Z 37defbc Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 37defbc843

ℹ️ 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".

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 30, 2026
@shimmyshimmer
shimmyshimmer merged commit 0d5d40c into main Oct 30, 2026
1 of 42 checks passed
@shimmyshimmer
shimmyshimmer deleted the studio-composer-switch-glitch branch October 30, 2026 07:42
shimmyshimmer added a commit that referenced this pull request Oct 30, 2026
…issal (#16077)

## What changed

Closing a dropdown by clicking elsewhere no longer leaves text
highlighted. Before, a quick second click selected a word, and a third
selected a whole message or, in Settings, the entire dialog. This
affected every dropdown, select and popover, on every page.

## Why

The OS counts the press that closes a menu as click 1 of a click
sequence. The menu swallows that press, so people click again, and the
next quick clicks arrive with click count 2 and 3. The browser treats
those as a double click (select word) and a triple click (select block).

A capture-phase guard, installed once in `AppProvider`
(`src/lib/dismiss-click-streak.ts`), notes when a left press lands
outside an open Radix menu, listbox or popover. For the rest of that
click sequence, each press selects as if the dismissing click had not
counted:
- click 2 places the caret
- click 3 selects the word (`Intl.Segmenter`, since `Selection.modify`
word steps differ by platform)
- click 4 and later select the enclosing block

The press that closes the menu is untouched, and so are text fields.
Double and triple clicks select as usual when no menu was just closed,
and a fast run of clicks still ends up selecting text.

## Verification

- `npm run typecheck`, `npm run build`: clean.
- `npm test`: 14,463 of 14,468 pass, 1 skipped. The 4 failures are in
`hub-gguf-card-unified-budget.test.ts` and fail identically on `main`.
- New `tests/dismiss-click-streak.test.ts`:
  - follow-ups after a dismissal select one step finer
  - the click-count to granularity mapping
  - word bounds from `Intl.Segmenter`
  - normal double and triple clicks still select
  - a new click sequence resets the guard
  - presses inside the menu and in text fields keep native selection
  - the guard installs once and removes its listeners
- Playwright, WebKit and Chromium. Each case opens a menu, then sends a
hand-paced click sequence (click count 1, 2, 3, about 180ms apart) onto
nearby text:

    | Menu | Before (click 2 / click 3) | After (click 2 / click 3) |
  | --- | --- | --- |
  | Settings Theme | "Accent" / "Accent " | nothing / "Accent" |
  | Settings UI font | "Contrast" / "Contrast " | nothing / "Contrast" |
| Composer "Approve for me" | "Lorem" / whole 347-char message | nothing
/ "Lorem" |
| Account menu | "Lorem" / whole 347-char message | nothing / "Lorem" |

- A fast run of 8 clicks after a dismissal selects the caret, the word,
then the block, instead of nothing.
- At 12 points across four words, the word and block selected after a
dismissal match a native double and triple click in 47 of 48 cases. The
exception is Chromium on the last 2px of a word's final letter, where
native selects the following space.

## Also in this PR

Comment-only trims to `thread.tsx`, `images-page.tsx` and
`video-page.tsx`, carried over from #16076 and #16081, which merged
before their final comment pass.

## Not covered

Not tested in the Desktop app's native WebView or on touch input. The
guard only acts on mouse click counts above 1.
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