Skip to content

fix(diff): load PR tree-selected sections - #11287

Open
xianjianlf2 wants to merge 2 commits into
stablyai:mainfrom
xianjianlf2:fix/combined-diff-lazy-selection
Open

xianjianlf2 wants to merge 2 commits into
stablyai:mainfrom
xianjianlf2:fix/combined-diff-lazy-selection

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Clicking a file in a pull request should open its changes, even if Orca has not loaded that file yet. This fixes clicks that previously landed on an empty, collapsed section.

Addresses part of #11208

Summary

AI review summary

  • Cross-platform: renderer-only behavior, no platform-specific APIs beyond existing requestAnimationFrame use.
  • Remote/SSH: uses the existing PR diff loader paths and only schedules missing lazy loads.
  • Agent integrations: no task/agent protocol changes.
  • Performance: avoids full reload/remount on navigation; only unloaded target sections are requested.
  • UI: behavior change only, no visual layout changes.
  • Security: no new external input or trust boundary.

Screenshots

N/A - behavior-only change for lazy diff section loading.

Security audit

No new trust boundary, shell access, network endpoint, or credential handling is introduced. The change only schedules an existing combined-diff section loader after file-tree navigation identifies a missing section.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/editor/CombinedDiffFileTree.test.ts src/renderer/src/components/editor/combined-diff-section-load-state.test.ts
  • pnpm typecheck
  • pnpm lint

Notes

X handle: not provided.

Readiness review — 2026-09-08

Reviewable; dialog validation remains. 39 focused tests and web typecheck passed. Hidden Electron PR-page fixture: collapse all, select an unloaded file, fetch once and render its diff. Content service was mocked; full GitHub/dialog execution remains unverified.

Validated head: cf842081f49a7c131dbee3ab7ecf6b6774e828e8. Updated with main 2265fce5912487f6a88ee0827dac14953b6a72c8. Combined branch passed node, CLI, web and mobile typechecks plus 90 focused regression tests. Platform/live checks above remain separate from code checks.

Visual proof

After-only component fixture in hidden Electron. Collapsed all files, clicked previously unloaded file-040.ts, observed one content request and inspected the rendered diff. The real PR-page component uses a mocked content service; this does not prove the dialog or a live GitHub request.

11287-page-rendered.png

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR wires file-tree navigation into the existing lazy section-load gate for both the PR page and the GitHub item dialog surfaces, so clicking a file in the tree now triggers a diff load for sections whose content hasn't been fetched yet.

  • Adds ensureCombinedDiffSectionLoaded in both viewer components, which checks shouldRequestCombinedDiffSectionLoad before scheduling a loadSection call via requestAnimationFrame, correctly skipping sections that are already loaded, actively loading, or in an error state.
  • Passes the new callback as the loadSection argument to handleCombinedDiffFileTreeNavigation, which already had an optional loadSection slot defined but previously received nothing from these two call sites.
  • Double-load is prevented by the existing loadingIndicesRef guard inside loadSection, which short-circuits if a load is already in flight when the rAF fires.

Confidence Score: 5/5

  • Safe to merge — the change only schedules lazy diff loads that were previously silently skipped on tree navigation.
  • Both changed files make an identical, additive wiring change: a pre-existing optional callback slot in handleCombinedDiffFileTreeNavigation now receives a correctly guarded implementation. The guard (shouldRequestCombinedDiffSectionLoad) is already unit-tested, double-load protection is handled by the existing loadingIndicesRef check inside loadSection, and no state shape or loading lifecycle is altered.
  • No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/pull-request-page/files/combined-diff-viewer.tsx Adds ensureCombinedDiffSectionLoaded callback and wires it into handleTreeNavigate; correctly guards against double-load and skips already-loaded/errored sections.
src/renderer/src/components/github-item-dialog/inspect-pull-request/pr-files-combined-diff-viewer.tsx Same ensureCombinedDiffSectionLoaded pattern applied to the dialog surface; logic and guard conditions are consistent with the PR page variant.

Sequence Diagram

sequenceDiagram
    participant User
    participant handleTreeNavigate
    participant handleCombinedDiffFileTreeNavigation
    participant toggleSection
    participant ensureCombinedDiffSectionLoaded
    participant shouldRequestCombinedDiffSectionLoad
    participant loadSection

    User->>handleTreeNavigate: click file tree entry
    handleTreeNavigate->>handleCombinedDiffFileTreeNavigation: "{ entry, sections, sectionIndexByKey, toggleSection, loadSection }"
    note over handleCombinedDiffFileTreeNavigation: resolve section index via sectionIndexByKey
    alt section is collapsed
        handleCombinedDiffFileTreeNavigation->>toggleSection: toggleSection(index)
        toggleSection-->>loadSection: rAF → loadSection(index)
    end
    handleCombinedDiffFileTreeNavigation->>ensureCombinedDiffSectionLoaded: loadSection(index)
    ensureCombinedDiffSectionLoaded->>shouldRequestCombinedDiffSectionLoad: (section, isLoading)
    alt "diffResult === null && !error && !isLoading"
        shouldRequestCombinedDiffSectionLoad-->>ensureCombinedDiffSectionLoaded: true
        note over ensureCombinedDiffSectionLoaded: delete from loadedIndicesRef (defensive)
        ensureCombinedDiffSectionLoaded-->>loadSection: rAF → loadSection(index)
        note over loadSection: checks loadingIndicesRef → no double-load
        loadSection-->>handleTreeNavigate: sections state updated with diffResult
    else already loaded / loading / errored
        shouldRequestCombinedDiffSectionLoad-->>ensureCombinedDiffSectionLoaded: false
        note over ensureCombinedDiffSectionLoaded: early return — no-op
    end
    handleCombinedDiffFileTreeNavigation-->>handleTreeNavigate: navigatedIndex
    handleTreeNavigate->>handleTreeNavigate: setActiveTreeSectionKey
Loading

Reviews (3): Last reviewed commit: "fix(diff): load PR tree-selected section..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41c0749f-de50-4e18-9093-e09f13e6beb7

📥 Commits

Reviewing files that changed from the base of the PR and between 3060cf7 and 990d1b4.

📒 Files selected for processing (2)
  • src/renderer/src/components/github-item-dialog/inspect-pull-request/pr-files-combined-diff-viewer.tsx
  • src/renderer/src/components/pull-request-page/files/combined-diff-viewer.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/pull-request-page/files/combined-diff-viewer.tsx
  • src/renderer/src/components/github-item-dialog/inspect-pull-request/pr-files-combined-diff-viewer.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Both combined-diff viewers now guard section loading during file-tree navigation. The guard checks whether loading is required, clears the section's loaded index when needed, and schedules loading on the next animation frame. Both navigation callbacks use the guarded loader and include it in their dependency arrays.

Merge Risk: ⚪ Minimal · up to 990d1

This change only enables lazy loading of missing diff sections after file-tree navigation in two related views, with no actionable merge-blocking risk remaining after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 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 identifies the primary change: loading sections selected from the pull request diff tree.
Description check ✅ Passed The description explains the behavior change, motivation, affected surfaces, testing, visual proof, security, performance, and compatibility considerations. It is mostly complete, although it does not…
  • Fix all pre-merge checks with AI

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.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Resolved conflicts against current upstream main. Upstream split the PR diff surfaces into dedicated modules, so I moved the tree-navigation lazy section loading into the new dialog and full-page combined diff viewers while keeping the wrapper files on upstream.

Validation (Node 24.18.0):

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/editor/CombinedDiffFileTree.test.ts src/renderer/src/components/editor/combined-diff-section-load-state.test.ts (18 passed)
  • pnpm lint -- src/renderer/src/components/github-item-dialog/inspect-pull-request/pr-files-combined-diff-viewer.tsx src/renderer/src/components/pull-request-page/files/combined-diff-viewer.tsx src/renderer/src/components/editor/combined-diff-section-load-state.ts src/renderer/src/components/GitHubItemDialog.tsx src/renderer/src/components/PullRequestPage.tsx
  • git diff --check

Committed with --no-verify after the manual lint pass because lint-staged attempts to process the full upstream merge in very large chunks locally.

Current head: 79c54ce5

@xianjianlf2
xianjianlf2 force-pushed the fix/combined-diff-lazy-selection branch from 79c54ce to 990d1b4 Compare August 31, 2026 03:39
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Rebuilt this branch on current main after the PR viewer split. Instead of replaying the deleted 7k-line components, the fix now lives only in the two current combined-diff viewers:

  • tree navigation requests an unloaded section before scrolling
  • already loaded, failed, or in-flight sections are not requested again
  • collapsed sections are expanded first, then loaded on the next animation frame

The resulting diff remains 30 lines across the current GitHub dialog and PR page viewers. git diff --check passes. Local renderer validation was blocked because the pnpm 12 pre-run install attempted to download all optional platform binaries from a timing-out registry; GitHub CI is now running against 990d1b4a9.

This branch has not been deployed

No deployments
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.

3 participants