Skip to content

fix(ui): decouple OpenPrsSection from parent via context#1503

Merged
arnestrickmann merged 1 commit intomainfrom
emdash/beni-refresh-issue-4be
Mar 16, 2026
Merged

fix(ui): decouple OpenPrsSection from parent via context#1503
arnestrickmann merged 1 commit intomainfrom
emdash/beni-refresh-issue-4be

Conversation

@arnestrickmann
Copy link
Contributor

Summary

  • Removes the onReviewPr prop from OpenPrsSection, replacing it with handleOpenExternalTask from TaskManagementContext
  • Adds handleOpenExternalTask to useTaskManagement hook which upserts the task into the cache before selecting it, preventing stale/missing task list entries
  • Wraps handleSelectTask in useCallback for stable reference
  • Introduces upsertTaskInList utility to safely insert or update a task in the cached task list (with matching by id or path)

Test plan

  • Unit tests for upsertTaskInList cover insert, update-by-id, and update-by-path scenarios
  • Open a project with GitHub connected, click "Review" on a PR, and verify the task appears in the sidebar and opens correctly
  • Verify existing task selection still works normally

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 16, 2026 7:34pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

Decouples OpenPrsSection from its parent by replacing the onReviewPr prop with handleOpenExternalTask consumed from TaskManagementContext. The new handleOpenExternalTask in useTaskManagement optimistically upserts the task into the React Query cache (via a new upsertTaskInList utility) before selecting it, preventing stale/missing sidebar entries when clicking "Review" on a PR. A background cache invalidation follows to reconcile with the database.

  • Removes onReviewPr prop drilling from ProjectMainViewOpenPrsSection; the component now self-sources its task management via context
  • Adds handleOpenExternalTask to the useTaskManagement hook, combining cache upsert + task selection + query invalidation
  • Wraps handleSelectTask in useCallback for a stable reference used by handleOpenExternalTask
  • Introduces upsertTaskInList utility in taskListCache.ts with matching by id or path to handle optimistic-to-real ID transitions
  • Unit tests cover insert, update-by-id, and update-by-path scenarios

Confidence Score: 5/5

  • This PR is safe to merge — it's a focused refactor that decouples a component from prop drilling with well-tested utility code and correct React memoization.
  • All changes are straightforward: prop removal, context consumption, a new utility with full test coverage, and correct useCallback memoization with complete dependency arrays. No remaining references to the old prop, no logic bugs, and the optimistic update + invalidation pattern is consistent with the rest of the codebase.
  • No files require special attention.

Important Files Changed

Filename Overview
src/renderer/components/OpenPrsSection.tsx Replaces onReviewPr prop with handleOpenExternalTask from context; clean decoupling with no leftover references.
src/renderer/components/ProjectMainView.tsx Removes onReviewPr prop from OpenPrsSection usage; minimal and correct change.
src/renderer/hooks/useTaskManagement.ts Adds handleOpenExternalTask with optimistic cache upsert + background refetch; wraps handleSelectTask in useCallback with correct dependencies.
src/renderer/lib/taskListCache.ts New upsertTaskInList utility: matches by id or path, preserves position on update, prepends on insert. Clean immutable implementation.
src/test/renderer/taskListCache.test.ts Good test coverage for insert, update-by-id, and update-by-path scenarios in upsertTaskInList.

Sequence Diagram

sequenceDiagram
    participant User
    participant OpenPrsSection
    participant ElectronAPI
    participant TaskManagementContext
    participant ReactQueryCache
    participant Database

    User->>OpenPrsSection: Click "Review" on PR
    OpenPrsSection->>ElectronAPI: githubCreatePullRequestWorktree()
    ElectronAPI-->>OpenPrsSection: { success, task/worktree }
    OpenPrsSection->>TaskManagementContext: handleOpenExternalTask(task)
    TaskManagementContext->>ReactQueryCache: upsertTaskInList (optimistic)
    TaskManagementContext->>TaskManagementContext: handleSelectTask(task)
    TaskManagementContext->>ReactQueryCache: invalidateQueries (background)
    ReactQueryCache->>Database: refetch tasks
    Database-->>ReactQueryCache: reconciled task list
Loading

Last reviewed commit: 1bf5442

@arnestrickmann arnestrickmann merged commit 96deb70 into main Mar 16, 2026
5 checks passed
@arnestrickmann arnestrickmann deleted the emdash/beni-refresh-issue-4be branch March 16, 2026 21:00
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