Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export default function Sidebar() {
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

const shouldShowProjectPathEntry = addingProject && !shouldBrowseForProjectImmediately;
const pendingApprovalByThreadId = useMemo(() => {
const map = new Map<ThreadId, boolean>();
for (const thread of threads) {
Expand Down Expand Up @@ -523,15 +525,29 @@ export default function Sidebar() {
});
await handleNewThread(projectId).catch(() => undefined);
} catch (error) {
const description =
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: "Failed to add project",
description,
});
} else {
setAddProjectError(description);
}
return;
}
finishAddingProject();
},
[focusMostRecentThreadForProject, handleNewThread, isAddingProject, projects],
[
focusMostRecentThreadForProject,
handleNewThread,
isAddingProject,
projects,
shouldBrowseForProjectImmediately,
],
);

const handleAddProject = () => {
Expand All @@ -550,12 +566,21 @@ export default function Sidebar() {
}
if (pickedPath) {
await addProjectFromPath(pickedPath);
} else {
} else if (!shouldBrowseForProjectImmediately) {
addProjectInputRef.current?.focus();
}
setIsPickingFolder(false);
};

const handleStartAddProject = () => {
setAddProjectError(null);
if (shouldBrowseForProjectImmediately) {
void handlePickFolder();
return;
}
setAddingProject((prev) => !prev);
};

const cancelRename = useCallback(() => {
setRenamingThreadId(null);
renamingInputRef.current = null;
Expand Down Expand Up @@ -1075,21 +1100,23 @@ export default function Sidebar() {
<button
type="button"
aria-label="Add project"
aria-pressed={shouldShowProjectPathEntry}
className="inline-flex size-5 items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground"
onClick={() => {
setAddingProject((prev) => !prev);
setAddProjectError(null);
}}
onClick={handleStartAddProject}
/>
}
>
<PlusIcon className="size-3.5" />
<PlusIcon
className={`size-3.5 transition-transform duration-150 ${
shouldShowProjectPathEntry ? "rotate-45" : "rotate-0"
}`}
/>
</TooltipTrigger>
<TooltipPopup side="right">Add project</TooltipPopup>
</Tooltip>
</div>

{addingProject && (
{shouldShowProjectPathEntry && (
<div className="mb-2 px-1">
{isElectron && (
<button
Expand Down Expand Up @@ -1415,7 +1442,7 @@ export default function Sidebar() {
})}
</SidebarMenu>

{projects.length === 0 && !addingProject && (
{projects.length === 0 && !shouldShowProjectPathEntry && (
<div className="px-2 pt-4 text-center text-xs text-muted-foreground/60">
No projects yet
</div>
Expand Down