Skip to content

fix(desktop): stop spurious folder picker on settings → dashboard nav#3602

Merged
Kitenite merged 2 commits intomainfrom
emerald-tent
Apr 21, 2026
Merged

fix(desktop): stop spurious folder picker on settings → dashboard nav#3602
Kitenite merged 2 commits intomainfrom
emerald-tent

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Apr 21, 2026

Summary

  • Folder picker was opening unprompted every time the user navigated from Settings back to the dashboard, once they had ever used "Import existing folder" in the session.
  • Root cause: folder-first import was wired through a zustand counter + useEffect in AddRepositoryModals. Settings lives outside _dashboard, so returning to the dashboard remounted AddRepositoryModals, and the effect fired again with the already-incremented counter.
  • Fix: delete the pulse. DashboardSidebarHeader now owns useFolderFirstImport and renders FolderFirstImportModal; the dropdown item calls folderImport.start() directly on click.

Why / Context

The "pulse via counter + effect" pattern is the wrong shape for "invoke this imperative thing on user click." useEffect fires on every mount regardless of whether the dep actually changed since last render — it has no memory of the prior mount's value. A module-scoped counter that outlives the component is therefore indistinguishable from an increment on remount, and the existing === 0 guard only caught the pristine initial-load case.

The only reason the indirection existed was that the header didn't have a reference to the hook instance owned by AddRepositoryModals. Collapsing both into the header removes that coupling entirely.

How It Works

  • DashboardSidebarHeader calls useFolderFirstImport({ onSuccess, onError }) directly and renders <FolderFirstImportModal> (Dialog portals, so DOM position doesn't matter).
  • Both "Import existing folder" dropdown items (collapsed + expanded variants) use onSelect={handleImportFolder}, which calls folderImport.start() and toasts on rejection.
  • AddRepositoryModals now only owns NewProjectModal.
  • folderImportTrigger, triggerFolderImport, useFolderImportTrigger, useTriggerFolderImport removed from the zustand store.

Manual QA Checklist

  • Click "Import existing folder" in the sidebar dropdown — native directory picker opens.
  • Cancel picker — no modal, no toast.
  • Pick a folder with no matching project — "Create as new" modal appears.
  • Pick a folder with a single matching project — setup runs, success toast.
  • After importing once, navigate to Settings and back — picker does not open.
  • Repeat the settings → dashboard round-trip several times — still no picker.
  • "New project" dropdown item still opens NewProjectModal.
  • Both collapsed and expanded sidebar variants behave the same.

Testing

  • bun run typecheck

Summary by cubic

Fixes the folder picker opening unexpectedly when returning from Settings to the dashboard. The folder import flow is now triggered directly on click in the sidebar header, so remounts no longer reopen the picker.

  • Bug Fixes

    • Stop the native directory picker from reopening on dashboard remounts.
    • Replace the zustand counter + useEffect trigger with direct folderImport.start() on dropdown item click.
    • Move useFolderFirstImport and FolderFirstImportModal into the dashboard sidebar header.
  • Refactors

    • AddRepositoryModals now only renders NewProjectModal.
    • Remove folderImportTrigger and related selectors from the add-repository-modal store.
    • Handle success/error toasts in the header.
    • Drop redundant promise catch around folderImport.start(); errors are handled by the hook.

Written for commit 30a9b0e. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Added success and error toast notifications for folder import actions.
  • Bug Fixes

    • Fixed duplicate/errant folder-import triggers and improved error handling during imports.
  • Refactor

    • Moved the folder-first import flow out of the Add Repository modal into the sidebar and simplified modal behavior; cleaned up related state management.

The folder-first import flow was plumbed through a zustand counter plus a
useEffect in AddRepositoryModals. The counter outlives component mounts,
but the effect runs on every mount — so once a user ever clicked "Import
existing folder," every subsequent remount of the dashboard layout
(including the one that happens when navigating back from Settings)
re-ran the effect and re-opened the native directory picker.

Remove the indirection. DashboardSidebarHeader now owns useFolderFirstImport
and renders FolderFirstImportModal itself; the dropdown item calls
folderImport.start() directly on click. No store pulse, no effect.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 040fb142-f0f8-4780-9d43-e3565ca02961

📥 Commits

Reviewing files that changed from the base of the PR and between d86030f and 30a9b0e.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx

📝 Walkthrough

Walkthrough

Folder-first import was removed from AddRepositoryModals and reimplemented in DashboardSidebarHeader using a local useFolderFirstImport flow with Sonner toasts; the modal store no longer tracks a folder-import trigger or exposes trigger selectors.

Changes

Cohort / File(s) Summary
AddRepositoryModals Component
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/AddRepositoryModals/AddRepositoryModals.tsx
Removed folder-first import integration: deleted usage of useFolderImportTrigger, FolderFirstImportModal, and useFolderFirstImport. Component now only renders NewProjectModal.
DashboardSidebarHeader Component
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx
Replaced useTriggerFolderImport with useFolderFirstImport; added folderImport handlers (start, cancel, confirmCreateAsNew) and Sonner toast callbacks for success/error; renders FolderFirstImportModal in collapsed and expanded layouts and updates the import dropdown to call folderImport.start().
Repository Modal Store
apps/desktop/src/renderer/stores/add-repository-modal.ts
Removed folderImportTrigger state and triggerFolderImport action and the exported selectors useFolderImportTrigger / useTriggerFolderImport. Store now exposes modal active, openNewProject, and close only.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SidebarHeader as Sidebar Header
    participant FolderModal as FolderFirstImportModal
    participant Toast as Sonner Toast

    User->>SidebarHeader: Click "Import existing folder"
    SidebarHeader->>FolderModal: folderImport.start() (open modal)
    FolderModal->>SidebarHeader: return state (confirm / cancel)
    alt confirmCreateAsNew
        SidebarHeader->>Toast: onSuccess toast (rgba(40,167,69,0.5))
    else error
        SidebarHeader->>Toast: onError toast (rgba(220,53,69,0.5))
    end
    SidebarHeader->>FolderModal: folderImport.cancel() (close modal)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hopping from store to sidebar's light,
I nudge the folder modal into sight,
Toasts cheer on success, grumbles hush errors away,
A tidy refactor to brighten the day,
Sniff, nibble, ship — I code and play! 🥕✨

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: stopping the spurious folder picker that opens on settings-to-dashboard navigation, which is the primary objective of this PR.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering the bug, root cause, fix, context, implementation details, QA checklist, and testing confirmation. It goes beyond the template but includes all critical information.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emerald-tent

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 and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 21, 2026

Greptile Summary

This PR fixes a bug where the native folder picker opened unprompted every time the user navigated from Settings back to the dashboard, after having used "Import existing folder" at least once in the session.

Root cause fixed: The old architecture threaded the "start folder import" signal through a module-scoped Zustand counter incremented on user click, then consumed it in a useEffect inside AddRepositoryModals. Because AddRepositoryModals remounts on every dashboard entry and useEffect has no memory of prior mount values, any non-zero counter value re-fired the folder picker on remount.

Fix: The indirection is removed entirely. DashboardSidebarHeader now calls useFolderFirstImport directly and both "Import existing folder" dropdown items (collapsed + expanded) call folderImport.start() on onSelect. FolderFirstImportModal is rendered (as a Dialog portal) at the bottom of each branch. AddRepositoryModals is reduced to only managing NewProjectModal.

Key changes:

  • folderImportTrigger counter, triggerFolderImport, useFolderImportTrigger, and useTriggerFolderImport removed from the Zustand store
  • FolderFirstImportModal and useFolderFirstImport moved from AddRepositoryModals into DashboardSidebarHeader
  • handleImportFolder wires the dropdown onSelect directly to folderImport.start(), with a defensive .catch() (see inline comment — slightly redundant since start() never rejects, but harmless)
  • Both collapsed and expanded sidebar variants share one hook instance and render one modal each (only one branch mounts at a time)

Confidence Score: 5/5

Safe to merge — the fix is correct, the root cause is well-understood, and the new architecture is simpler and more direct.

The counter+effect anti-pattern is eliminated and replaced with a direct event handler. The hook instance is correctly shared across both collapsed/expanded branches (single call at component level), only one FolderFirstImportModal renders at a time (mutually exclusive return branches), and the Zustand store is properly cleaned up. The only minor observation is a redundant .catch() that cannot cause harm beyond a theoretical double-toast in unreachable error conditions.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx Now owns useFolderFirstImport and renders FolderFirstImportModal (Dialog portal) in both collapsed/expanded branches sharing one hook instance. Both DropdownMenuItems call handleImportFolder directly on select, eliminating the effect-based indirect trigger.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/AddRepositoryModals/AddRepositoryModals.tsx Simplified to only own NewProjectModal; FolderFirstImportModal and its hook moved to DashboardSidebarHeader. The counter+effect pattern and related imports/refs are cleanly removed.
apps/desktop/src/renderer/stores/add-repository-modal.ts Zustand store simplified: folderImportTrigger counter, triggerFolderImport action, and related selectors removed. Only new-project modal state remains.

Sequence Diagram

sequenceDiagram
    participant User
    participant DropdownMenuItem
    participant DashboardSidebarHeader
    participant useFolderFirstImport
    participant FolderFirstImportModal

    Note over DashboardSidebarHeader,useFolderFirstImport: Before (broken): counter in Zustand + useEffect in AddRepositoryModals
    Note over DashboardSidebarHeader,useFolderFirstImport: After (fixed): direct call on user click

    User->>DropdownMenuItem: clicks "Import existing folder"
    DropdownMenuItem->>DashboardSidebarHeader: onSelect → handleImportFolder()
    DashboardSidebarHeader->>useFolderFirstImport: folderImport.start()
    useFolderFirstImport->>User: Native directory picker opens
    User->>useFolderFirstImport: picks folder (or cancels)
    alt Cancelled
        useFolderFirstImport-->>DashboardSidebarHeader: returns (no-op)
    else No matching project
        useFolderFirstImport->>FolderFirstImportModal: state → no-match
        FolderFirstImportModal->>User: "Create as new" dialog
        User->>FolderFirstImportModal: confirms name
        FolderFirstImportModal->>useFolderFirstImport: confirmCreateAsNew()
        useFolderFirstImport-->>DashboardSidebarHeader: onSuccess toast
    else Single match
        useFolderFirstImport->>useFolderFirstImport: runSetup()
        useFolderFirstImport-->>DashboardSidebarHeader: onSuccess toast
    end
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx
Line: 50-55

Comment:
**Redundant `.catch()` on non-rejecting promise**

`folderImport.start()` is an `async` function that catches every error path internally (all three `try/catch` blocks in the hook return early after calling `reportError`, never re-throwing). This means `start()` will always resolve, never reject — making the `.catch()` in `handleImportFolder` unreachable in normal and error flows alike.

If `start()` did somehow throw unexpectedly, the user would see **two** error toasts: one from the `onError` callback registered with `useFolderFirstImport`, and a second from this `.catch()`. Consider removing the outer catch and relying solely on the `onError` option already passed to the hook, keeping the code DRY:

```suggestion
	const handleImportFolder = () => {
		void folderImport.start();
	};
```

If you prefer to keep it as a defensive belt-and-suspenders guard, that's also fine — just be aware of the potential double-toast if the hook's internal error handling ever changes.

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

Reviews (1): Last reviewed commit: "fix(desktop): stop spurious folder picke..." | Re-trigger Greptile

Comment on lines +50 to +55
const handleImportFolder = () => {
folderImport.start().catch((err) => {
toast.error(
`Import failed: ${err instanceof Error ? err.message : String(err)}`,
);
});
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 Redundant .catch() on non-rejecting promise

folderImport.start() is an async function that catches every error path internally (all three try/catch blocks in the hook return early after calling reportError, never re-throwing). This means start() will always resolve, never reject — making the .catch() in handleImportFolder unreachable in normal and error flows alike.

If start() did somehow throw unexpectedly, the user would see two error toasts: one from the onError callback registered with useFolderFirstImport, and a second from this .catch(). Consider removing the outer catch and relying solely on the onError option already passed to the hook, keeping the code DRY:

Suggested change
const handleImportFolder = () => {
folderImport.start().catch((err) => {
toast.error(
`Import failed: ${err instanceof Error ? err.message : String(err)}`,
);
});
const handleImportFolder = () => {
void folderImport.start();
};

If you prefer to keep it as a defensive belt-and-suspenders guard, that's also fine — just be aware of the potential double-toast if the hook's internal error handling ever changes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx
Line: 50-55

Comment:
**Redundant `.catch()` on non-rejecting promise**

`folderImport.start()` is an `async` function that catches every error path internally (all three `try/catch` blocks in the hook return early after calling `reportError`, never re-throwing). This means `start()` will always resolve, never reject — making the `.catch()` in `handleImportFolder` unreachable in normal and error flows alike.

If `start()` did somehow throw unexpectedly, the user would see **two** error toasts: one from the `onError` callback registered with `useFolderFirstImport`, and a second from this `.catch()`. Consider removing the outer catch and relying solely on the `onError` option already passed to the hook, keeping the code DRY:

```suggestion
	const handleImportFolder = () => {
		void folderImport.start();
	};
```

If you prefer to keep it as a defensive belt-and-suspenders guard, that's also fine — just be aware of the potential double-toast if the hook's internal error handling ever changes.

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx (1)

25-26: Move folder-import internals out of AddRepositoryModals.

This component now owns the folder-first flow, but it still imports the modal/hook from the old AddRepositoryModals subtree. Please relocate them under DashboardSidebarHeader if single-use, or a shared dashboard-level folder if reused.

♻️ Suggested import shape after relocating
-import { FolderFirstImportModal } from "renderer/routes/_authenticated/_dashboard/components/AddRepositoryModals/components/FolderFirstImportModal";
-import { useFolderFirstImport } from "renderer/routes/_authenticated/_dashboard/components/AddRepositoryModals/hooks/useFolderFirstImport";
+import { FolderFirstImportModal } from "./components/FolderFirstImportModal";
+import { useFolderFirstImport } from "./hooks/useFolderFirstImport";

As per coding guidelines, “Co-locate dependencies (utils, hooks, constants, config, tests, stories) next to the file using them. If a utility is used once, nest it under the parent's directory. If used 2+ times, promote it to the highest shared parent's directory or top-level components/.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx`
around lines 25 - 26, The DashboardSidebarHeader component currently imports
FolderFirstImportModal and useFolderFirstImport from the AddRepositoryModals
subtree; move these two single-use internals into the DashboardSidebarHeader
directory (or into a shared dashboard-level folder if they are used elsewhere),
update their file paths and imports inside DashboardSidebarHeader to the new
local locations, and ensure any related tests/stories/constants are co-located
as well; specifically relocate the FolderFirstImportModal component and the
useFolderFirstImport hook and update all imports referencing these symbols so
DashboardSidebarHeader imports them from the new local/shared dashboard path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx`:
- Around line 25-26: The DashboardSidebarHeader component currently imports
FolderFirstImportModal and useFolderFirstImport from the AddRepositoryModals
subtree; move these two single-use internals into the DashboardSidebarHeader
directory (or into a shared dashboard-level folder if they are used elsewhere),
update their file paths and imports inside DashboardSidebarHeader to the new
local locations, and ensure any related tests/stories/constants are co-located
as well; specifically relocate the FolderFirstImportModal component and the
useFolderFirstImport hook and update all imports referencing these symbols so
DashboardSidebarHeader imports them from the new local/shared dashboard path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95d4fca5-5dab-4a81-abeb-1dcc7e4352aa

📥 Commits

Reviewing files that changed from the base of the PR and between daf0e16 and d86030f.

📒 Files selected for processing (3)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/AddRepositoryModals/AddRepositoryModals.tsx
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarHeader/DashboardSidebarHeader.tsx
  • apps/desktop/src/renderer/stores/add-repository-modal.ts
💤 Files with no reviewable changes (1)
  • apps/desktop/src/renderer/stores/add-repository-modal.ts

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@Kitenite Kitenite merged commit e964940 into main Apr 21, 2026
6 of 7 checks passed
@Kitenite Kitenite deleted the emerald-tent branch April 21, 2026 04:52
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

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