Skip to content

fix(task-input): preserve picked folder when adding to recents#2277

Open
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/fix-folder-picker-selection
Open

fix(task-input): preserve picked folder when adding to recents#2277
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/fix-folder-picker-selection

Conversation

@richardsolomou
Copy link
Copy Markdown
Member

Problem

When creating a new task and clicking Open folder... in local/worktree mode, the selected folder is added to the Recent list but isn't actually selected as the task's folder.

Changes

The useEffect in TaskInput.tsx that syncs selectedDirectory from view.folderId had folders in its dependency array and re-ran every time folders changed. Picking a new folder via the file dialog triggers addFolder, which invalidates getFolders, which refetches and updates folders — causing the effect to fire and revert selectedDirectory back to the original view.folderId folder, overwriting the user's pick.

Track the last applied folderId in a ref so the effect only syncs when view.folderId actually changes, not on every folders refetch. The dependency on folders is preserved so the initial sync still works when the folder list hasn't loaded yet on mount.

How did you test this?

  • Typecheck (pnpm --filter code typecheck) passes.
  • Build (pnpm build) succeeds.
  • pnpm --filter code test — all TaskInput-related tests pass; the 2 failing tests are pre-existing archive service integration timeouts unrelated to this change.
  • Did not manually verify in the running app — no display available in this environment.

Publish to changelog?

no


Created with PostHog Code

The useEffect that syncs selectedDirectory from view.folderId was
re-running whenever the folders list changed. Picking a new folder via
"Open folder..." triggers addFolder, which invalidates getFolders, which
refetches folders, which fires this effect and reverts selectedDirectory
back to the original view.folderId folder.

Track the last applied folderId in a ref so the effect only syncs when
view.folderId actually changes, not on every folders refetch.

Generated-By: PostHog Code
Task-Id: 0dcecc53-ea9a-4a39-8a6e-63973bea25bb
@richardsolomou richardsolomou requested a review from a team May 21, 2026 05:22
@richardsolomou richardsolomou marked this pull request as ready for review May 21, 2026 05:22
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/task-detail/components/TaskInput.tsx:404-416
**No regression test for the fixed behaviour**

The bug being fixed (folder selection reverted after `addFolder` triggers a `folders` refetch) is subtle enough that it could be reintroduced silently. There are currently no test files for `TaskInput`, so a dedicated unit/integration test — e.g. mounting the component with a `view.folderId`, simulating a `folders` list change after `addFolder`, and asserting that `selectedDirectory` retains the user-picked path — would pin the contract and prevent future regressions.

Reviews (1): Last reviewed commit: "fix(task-input): preserve picked folder ..." | Re-trigger Greptile

Comment on lines 404 to 416
const lastInitializedFolderIdRef = useRef<string | undefined>(undefined);
useEffect(() => {
if (view.folderId) {
const folder = folders.find((f) => f.id === view.folderId);
if (folder) {
setSelectedDirectory(folder.path);
}
if (!view.folderId) {
lastInitializedFolderIdRef.current = undefined;
return;
}
if (lastInitializedFolderIdRef.current === view.folderId) return;
const folder = folders.find((f) => f.id === view.folderId);
if (folder) {
setSelectedDirectory(folder.path);
lastInitializedFolderIdRef.current = view.folderId;
}
}, [view.folderId, folders]);
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.

P2 No regression test for the fixed behaviour

The bug being fixed (folder selection reverted after addFolder triggers a folders refetch) is subtle enough that it could be reintroduced silently. There are currently no test files for TaskInput, so a dedicated unit/integration test — e.g. mounting the component with a view.folderId, simulating a folders list change after addFolder, and asserting that selectedDirectory retains the user-picked path — would pin the contract and prevent future regressions.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/task-detail/components/TaskInput.tsx
Line: 404-416

Comment:
**No regression test for the fixed behaviour**

The bug being fixed (folder selection reverted after `addFolder` triggers a `folders` refetch) is subtle enough that it could be reintroduced silently. There are currently no test files for `TaskInput`, so a dedicated unit/integration test — e.g. mounting the component with a `view.folderId`, simulating a `folders` list change after `addFolder`, and asserting that `selectedDirectory` retains the user-picked path — would pin the contract and prevent future regressions.

How can I resolve this? If you propose a fix, please make it concise.

Extract the folder-id-to-directory sync into useInitialDirectoryFromFolderId
so the contract can be tested in isolation: the hook syncs once when the
folder list resolves, ignores later folders refetches (the case that
broke the picker), and re-syncs only when folderId changes.

Generated-By: PostHog Code
Task-Id: 0dcecc53-ea9a-4a39-8a6e-63973bea25bb
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