Skip to content

fix: bound combined diff editors and scope chat style invalidation - #23725

Merged
nwparker merged 3 commits into
mainfrom
nwparker/ci-diff-viewport-probe
Sep 29, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/ci-diff-viewport-probe

Conversation

@nwparker

@nwparker nwparker commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33

ELI5

Opening a large combined diff could freeze Orca for seconds when files changed. Keep nearby editors bounded by screen height and stop unrelated chat styles from making Chromium recalculate the entire document.

What Changed

  • Limit offscreen neighboring diff sections to one viewport of aggregate height per side, retaining the existing five-section cap and every visible section. Previously a single visible file could also mount five enormous offscreen Monaco editors.
  • Rewrite seven native-chat relational variants as direct ancestor selectors. Their previous generated form used a wildcard descendant inside :is(), which Chromium invalidated on the document body when Monaco changed its DOM. The resulting styles and keyboard-focus/goal-docking conditions stay the same.
  • Add five range tests and retain the large-diff responsiveness gate, now also asserting that its one visible enormous section mounts one editor.

Why

Profiling separated two costs. The old range mounted six editors and over 42,000 Monaco line nodes. Bounding the range helped but still failed Linux CI: traces showed two document-wide style recalculations over roughly 238,000 elements, lasting 2.8 and 2.3 seconds. Invalidation tracking named the seven chat selectors. Narrowing those rules avoids the broad invalidation without removing keyboard access, changing the diff viewport, or relaxing test limits.

Linked Issue

STA-3420; failures in https://github.com/stablyai/orca/actions/runs/36497243185

Visual Proof

The visible diff remains the same; fewer offscreen editors mount.

Before:
Before

After:
After

Keyboard-focused native-chat copy controls still reveal:
Keyboard focus

Testing

  • Local hidden Electron: both diff responsiveness scenarios passed; large burst maximum pause 119 ms, 358/360 samples.
  • Linux: both responsiveness scenarios and scroll restoration passed. Large burst maximum pause 1.8 ms, 360/360 samples: https://github.com/stablyai/orca/actions/runs/36502267771
  • 22 native-chat tests passed, covering control classes and goal/task-strip adjacency; five range unit tests passed in the initial range revision.
  • Rendered native-chat probe: controls hidden before keyboard focus, visible and clickable after focus; screenshot inspected.
  • Web typecheck and changed-code quality gate passed.
  • Before/fix-only Linux tracing: before, two body-wide invalidations spent 5,129.6 ms in style recalculation; after changing only these selectors, zero such invalidations and zero style-recalculation calls in the burst window, maximum pause 0.3 ms with 360/360 samples. Runs before / after deliberately throw after assertions to upload traces; the after assertions passed. The earlier range-only PR run failed and is not counted as a pass.

Review

No timeouts or responsiveness thresholds increased. No wire, execution-host, filesystem, or git-provider changes. SSH/folder-workspace diffs use the same renderer path. Linux and macOS exercised; Windows and live SSH rendering remain untested here. Large initial editor construction can still be expensive; this change addresses excess neighboring mounts and repeated document-wide style work.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Focused changes with measured before/after behavior.
  • Visual proof attached; keyboard access preserved.
  • Self-reviewed for correctness and performance.
  • Platform, remote, and provider scope considered.
  • Final PR checks complete.

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Optimizes rendering of large diffs by bounding offscreen work.

The PR appears safe to merge with a non-blocking limitation in height budgeting for image diffs.

Findings

  1. P2 Image heights exceed the budget ▶

Summary

The PR limits combined-diff prerendering to one viewport of estimated height on either side of visible sections, while retaining the five-section cap. It also updates native-chat focus and dock selectors and adds range and E2E assertions.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  V[Visible section range] --> R[Always render visible sections]
  V --> B[Check neighbors on each side]
  B --> H{Within height budget and five-section cap?}
  H -->|Yes| A[Include neighboring section]
  H -->|No| S[Stop in that direction]
Loading

Reviews (2) · Last reviewed commit: "perf: scope native chat relational style..."

Comment on lines +41 to +45
rangeExtractor: (range) =>
getCombinedDiffRenderRange(
range,
estimateSize,
scrollContainerRef.current?.clientHeight ?? 0

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 Image heights exceed the budget

The new height limit uses an estimate of 88px for an image diff that renders at its natural height. If several large image diffs are near the visible section, they can all fit within the estimated budget and mount offscreen. That leaves image-heavy combined diffs exposed to the rendering work this change aims to avoid. Please account for their measured heights when choosing the render range.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@pullfrog pullfrog 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.

ℹ️ No critical issues — one defer-able scope question and a render-path nit.

Reviewed changes

  • Height-bounded render range — new getCombinedDiffRenderRange extends the visible range by at most overscan neighbors per side but stops before the first neighbor that pushes cumulative estimated height past one viewport.
  • Virtualizer wiring — use-combined-diff-virtualizer.ts lifts estimateSize and adds a rangeExtractor that reads the scroll container's clientHeight (0 before measured → visible only).
  • Unit tests — 5 cases pin visible large sections, one-viewport neighbor pre-render, stopping at an oversized neighbor (both directions), the row-count/boundary case, and the unmeasured viewport.
  • E2E assertion — the 8×15k-line freeze fixture now asserts exactly one section row mounts.

ℹ️ Sibling PR-file combined-diff viewers keep the unbounded overscan

The new bound is wired only into the worktree viewer. Both PR-file viewers render the same DiffSectionItem (full Monaco), pass the same getDiffSectionRowEstimatedHeight, and keep overscan: PR_DIFF_OVERSCAN with no height budget, so an oversized offscreen section there still mounts its full editor. This is a scope question rather than a defect in this diff — the reported freeze is watcher-driven and worktree-specific — but the helper is now generic enough to reuse if the same pathology shows up on PR review pages.

Technical details
# Should the PR-file viewers adopt the height-bounded range extractor?

## Affected sites
- `src/renderer/src/components/pull-request-page/files/combined-diff-viewer.tsx:199` — inline `useVirtualizer`, `overscan: PR_DIFF_OVERSCAN`, no `rangeExtractor`.
- `src/renderer/src/components/github-item-dialog/inspect-pull-request/pr-files-combined-diff-viewer.tsx:240` — same shape.

## Required outcome
- Confirm whether these surfaces can hit the same offscreen large-section rendering cost. If they can, route them through `getCombinedDiffRenderRange` too; if the freeze is genuinely watcher-specific, a one-line note in the PR body saying so would settle it.

## Open questions for the human
- Is the regression STA-3420 reproduces specific to watcher-driven invalidation, or does it also apply to opening/scrolling a large PR diff?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

},
estimateSize,
// Offscreen Monaco sections render their full height; bound that work by pixels, too.
rangeExtractor: (range) =>

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.

Nit: this inline closure changes identity every render, and TanStack uses rangeExtractor as a memo key for getVirtualIndexes (the previous default extractor was stable). That forces getVirtualIndexes → getVirtualItems to rebuild — and the renderedIndicesRef layout effect to re-run — on every render, not just when the range or sizes change. A useCallback keyed on [sections, sectionHeights] (with a matching stable estimateSize) restores memoization; clientHeight is still read fresh at call time because options are re-set each render. Low impact, but this PR is a render-path perf fix.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4fef2e5e-3c45-49ed-b00e-fe1e56cd3bc5

📥 Commits

Reviewing files that changed from the base of the PR and between 07ac8eb and 425bae6.

📒 Files selected for processing (5)
  • src/renderer/src/components/native-chat/NativeChatBackgroundTasksStatus.tsx
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRow.test.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRow.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.goal-dock.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The combined-diff virtualizer now uses getCombinedDiffRenderRange to select indices based on estimated section heights and viewport height. Unit tests cover neighboring section sizes, overscan limits, list boundaries, and zero viewport height. An end-to-end test checks that one combined-diff section row remains after an external-file-change burst. Native-chat styles and related tests now use :has() selectors for adjacent-element and focus-visible styling.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 425ba

The height-bounded range should reduce unnecessary offscreen diff rendering. A Linux burst run reportedly still stalled, but available evidence does not connect that stall to this change; no actionable merge-blocking risk is established.

Architecture Summary

Architecture risk: 🟡 Medium · up to 07ac8

The change affects 2 systems.

Changed systems: src, tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 3 changed files map to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-render-range.test.ts: Adds imports for Vitest and getCombinedDiffRenderRange.
  • observed — Modified behavior in src/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-render-range.test.ts: Adds a test expecting the visible range [2, 3] when the visible sections have large neighbors.
  • observed — Modified behavior in src/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-render-range.test.ts: Adds a test expecting two small sections on each side of the visible range, producing [2, 3, 4, 5, 6, 7].
  • observed — Modified behavior in src/renderer/src/components/editor/combined-diff/scroll-viewport/combined-diff-render-range.test.ts: Adds a test expecting [2, 3] when large neighboring sections occur on both sides of the visible section.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes both primary changes: bounding combined-diff editor rendering and scoping chat style invalidation.
Description check ✅ Passed The description is complete and on-topic. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, platform scope, and remaining limitations.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@nwparker nwparker changed the title fix(editor): bound offscreen combined diff rendering by height fix: bound combined diff editors and scope chat style invalidation Sep 29, 2026

@pullfrog pullfrog 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.

ℹ️ No critical issues — the selector rewrite is match-equivalent and registers a narrower invalidation subject; one minor cleanup nit inline.

Reviewed changes

  • Rewrote the seven native-chat relational variants (message-row copy/timestamp reveal, code-block copy button, background-task dock rules) from Tailwind's group-has-* / group-[…] forms to direct ancestor selectors ([.group:has(:focus-visible)_&], [class~='group/code']:has(:focus-visible)_&, [data-native-chat-background-tasks]:has(…)_&), dropping the :is(… *) wildcard subject Chromium was invalidating document-wide.
  • Updated the two tests that pin the exact class tokens (NativeChatMessageRow.test.tsx, the goal-dock STRIP_DOCK_RULE).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

>
{/* When the goal tab is the next sibling, take its width and share its top edge. */}
<div className="mx-auto w-full max-w-4xl group-has-[+[data-native-chat-thread-goal]]/tasks:px-2">
<div className="mx-auto w-full max-w-4xl [[data-native-chat-background-tasks]:has(+[data-native-chat-thread-goal])_&]:px-2">

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.

With the dock selectors now keyed on [data-native-chat-background-tasks], the group/tasks marker on the parent (line 178) is no longer referenced by any selector, yet NativeChatStructuredSession.goal-dock.test.tsx:101 still asserts it as load-bearing. Drop the marker and that assertion, or keep the marker with a note if a future variant needs it.

@nwparker
nwparker merged commit da48d98 into main Sep 29, 2026
49 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…oal-dock selector

Main's #23725 rewrote the strip's goal-dock variants from `group-has-[...]/tasks:` to an
ancestor-scoped `[[data-native-chat-background-tasks]:has(+[data-native-chat-thread-goal])_&]:`
selector. The merged head renders byte-identically to main for this fixture; only the golden
was captured before that change.
naufaldi added a commit to naufaldi/orca that referenced this pull request Oct 28, 2026
… Mermaid renders

Opening a Markdown preview with many Mermaid diagrams froze scrolling for
tens of seconds. Mermaid measures each label with getBBox /
getComputedTextLength / getTotalLength, and every call forces a style
recalc. Three rules made each of those recalcs cover the whole document:

- body:has(> overlay) .app-layout > :not(.window-controls) (modal blur)
- group-has-[:focus-visible]/row (SshTargetCard)
- group-has-[:focus-visible]/reasoning (NativeChatReasoningDisclosure)

Each one alone was enough. The blur now flows through a body custom
property set by a subject-only body:has(), the same shape stablyai#23721 used
for the toaster z-index. The two Tailwind utilities use the scoped
[[class~='group/x']:has(:focus-visible)_&] form from stablyai#23725.

On the issue's 19-diagram repro (dev build), all diagrams render in
4.2 s instead of 47.5 s, style recalc during open drops from ~35 s to
0.36 s, and scrolling while diagrams render goes from about 1 fps to a
16.7 ms median frame.

Refs stablyai#34312

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nwparker added a commit that referenced this pull request Oct 29, 2026
…ole subtrees

Tailwind compiles group-has-* to `.x:is(:where(.group\/g):has(...) *)`: a
non-subject :has() whose subject is `*`. Together with any attribute :has()
in the sheet (e.g. card.tsx has-data-[slot=card-action]) and a non-subject
:has() on a large ancestor, Blink restyles the whole subtree under the
anchor on every mutation, so Mermaid label measurement, streaming code
blocks and rich-editor edits paid for thousands of elements per forced
style read.

(a) SshTargetCard and NativeChatReasoningChevron use the scoped
    [[class~='group/x']:has(:focus-visible)_&] shape from #23725, keeping
    the keyboard-only reveal (#19426). This is the whole measured win.
(b) rich-markdown-editor.css drops a redundant :has(): .markdown-toc-header
    only renders inside .markdown-toc-panel. Defence in depth; measured
    close to neutral once (a) lands.

Guard: check-has-restyle-scope.mjs compiles the renderer's Tailwind CSS
with Tailwind's own API, adds the plain renderer stylesheets, lowers
nesting with lightningcss and walks its selector AST. It flags any
non-subject :has() (outside sibling-only arguments) whose subject compound
has no class, id or attribute, carrying context through :is/:where/:not.
Reading compiled output covers the Tailwind spellings, @apply and nested
CSS forms tested so far. It runs in pnpm lint, check:changed and PR CI.

Hidden Electron 43.8.1, real compiled Tailwind, ~8.3k-node DOM, per
iteration, all from (a): rich editor with TOC 19.4 -> 1.6 ms; native-chat
code block append 12.5 -> 3.6 ms (3,184 -> 3 elements restyled); large
group row 8.0 -> 2.4 ms (2,003 -> 2).

Fixes #34312

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