Skip to content

Open desktop folder picker immediately when adding projects in Electron#697

Merged
juliusmarminge merged 4 commits intomainfrom
t3code/desktop-direct-folder-browse
Mar 9, 2026
Merged

Open desktop folder picker immediately when adding projects in Electron#697
juliusmarminge merged 4 commits intomainfrom
t3code/desktop-direct-folder-browse

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Mar 9, 2026

Summary

  • Open the native folder picker immediately when the Add Project action is triggered in desktop Electron (isElectron && !isMobile).
  • Keep existing manual path-entry behavior for mobile Electron layouts and non-Electron environments.
  • Add Sidebar.logic.ts to isolate the picker decision logic for easier testing and reuse.
  • Add unit tests for shouldOpenProjectFolderPickerImmediately covering desktop Electron, mobile Electron, and non-Electron cases.
  • Update Sidebar UI state handling so the inline path entry only appears when manual entry is intended, including icon rotation/pressed state updates.

Testing

  • apps/web/src/components/Sidebar.logic.test.ts added with 3 Vitest cases for the new decision logic.
  • bun lint — Not run.
  • bun typecheck — Not run.
  • bun run test — Not run.

Note

Medium Risk
Changes the project-creation UX and error surfacing in Sidebar, which could affect Electron users’ ability to add projects if the picker flow or state transitions misbehave.

Overview
Clicking Add project in Sidebar now immediately opens the native folder picker on Electron, instead of toggling the inline path-entry UI.

The inline path entry (and related empty-state text) is now gated behind shouldShowProjectPathEntry, while failures during add-project in the immediate-picker flow are surfaced via an error toast rather than inline form error state; the add button also reflects state via aria-pressed and a rotating PlusIcon.

Written by Cursor Bugbot for commit 2b6e011. This will update automatically on new commits. Configure here.

Note

Open the native folder picker immediately in Electron when clicking Add project in Sidebar and adjust web UX in Sidebar.tsx

Introduce shouldBrowseForProjectImmediately and shouldShowProjectPathEntry, add handleStartAddProject, route errors to toasts in Electron, skip refocus after canceled pick in Electron, and update Projects section JSX and button state.

📍Where to Start

Start with the handleStartAddProject handler and related state logic in Sidebar.tsx.

Macroscope summarized 2b6e011.

- add `shouldOpenProjectFolderPickerImmediately` to centralize Sidebar behavior
- trigger folder browse directly when adding a project in desktop Electron
- keep manual path entry for mobile layouts and non-Electron, with tests for all cases
@github-actions github-actions bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Mar 9, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Project creation errors invisible in desktop Electron mode
    • In the catch block of addProjectFromPath, errors now show a toast via toastManager when shouldBrowseForProjectImmediately is true (desktop Electron), since the inline error display is inside a conditional block that is always false in that mode.

Create PR

Or push these changes by commenting:

@cursor push f0ba5fcc2e
Preview (f0ba5fcc2e)
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -531,15 +531,29 @@
         });
         await handleNewThread(projectId).catch(() => undefined);
       } catch (error) {
+        const message =
+          error instanceof Error ? error.message : "An error occurred while adding the project.";
         setIsAddingProject(false);
-        setAddProjectError(
-          error instanceof Error ? error.message : "An error occurred while adding the project.",
-        );
+        if (shouldBrowseForProjectImmediately) {
+          toastManager.add({
+            type: "error",
+            title: "Could not add project",
+            description: message,
+          });
+        } else {
+          setAddProjectError(message);
+        }
         return;
       }
       finishAddingProject();
     },
-    [focusMostRecentThreadForProject, handleNewThread, isAddingProject, projects],
+    [
+      focusMostRecentThreadForProject,
+      handleNewThread,
+      isAddingProject,
+      projects,
+      shouldBrowseForProjectImmediately,
+    ],
   );
 
   const handleAddProject = () => {

- remove mobile-width gating from sidebar project picker behavior
- simplify picker logic/tests to depend only on Electron runtime
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0ac20ccf-5e95-492f-9ec2-f0a7514489d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch t3code/desktop-direct-folder-browse

Comment @coderabbitai help to get the list of available commands and usage tips.

- Replace `shouldOpenProjectFolderPickerImmediately` with direct `isElectron` usage
- Remove obsolete `Sidebar.logic.ts` and its tests
isElectron: boolean;
}): boolean {
return input.isElectron;
}
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.

Missing isMobile check opens picker on mobile Electron

Medium Severity

The PR description specifies the folder picker opens only for desktop Electron (isElectron && !isMobile), keeping manual path-entry for mobile Electron layouts. However, shouldOpenProjectFolderPickerImmediately only checks isElectron and doesn't accept or evaluate an isMobile parameter. This means mobile Electron users get the native folder picker instead of the intended manual path-entry UI. The isMobile value is available via useSidebar() in the sidebar context but is never passed to or checked by this function.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Missing !isMobile check for folder picker condition
    • Added useSidebar() hook to get isMobile and updated the condition from isElectron to isElectron && !isMobile so mobile Electron layouts preserve the manual path-entry UI.

Create PR

Or push these changes by commenting:

@cursor push 95ebece7ed

const renamingCommittedRef = useRef(false);
const renamingInputRef = useRef<HTMLInputElement | null>(null);
const [desktopUpdateState, setDesktopUpdateState] = useState<DesktopUpdateState | null>(null);
const shouldBrowseForProjectImmediately = isElectron;
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.

Missing !isMobile check for folder picker condition

High Severity

shouldBrowseForProjectImmediately is set to just isElectron, but the PR description explicitly specifies the condition as isElectron && !isMobile. Mobile Electron layouts will incorrectly skip the manual path-entry UI and immediately open the native folder picker, breaking the intended behavior of preserving manual entry for mobile Electron environments.

Fix in Cursor Fix in Web

- Use a toast error for add-project failures during immediate folder browse
- Keep inline add-project error state for non-immediate flows
- Include `shouldBrowseForProjectImmediately` in callback dependencies
@juliusmarminge juliusmarminge merged commit b0e1b33 into main Mar 9, 2026
8 checks passed
@juliusmarminge juliusmarminge deleted the t3code/desktop-direct-folder-browse branch March 9, 2026 16:31
@vertopolkaLF
Copy link
Copy Markdown

weird change. I remember Theo on stream specified this as a pro-dev feature that he insisted on and it was actually useful to many, and now it basically gone

@t3dotgg
Copy link
Copy Markdown
Member

t3dotgg commented Mar 11, 2026

We need to have a chat Julius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants