Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import { memo, useCallback, useEffect, useMemo, useState } from "react";
import { createPortal } from "react-dom";
import { useDashboardSidebarState } from "renderer/routes/_authenticated/hooks/useDashboardSidebarState";
import { DashboardSidebarHeader } from "./components/DashboardSidebarHeader";
import { DashboardSidebarHoverCardOverlay } from "./components/DashboardSidebarHoverCardOverlay";
import { DashboardSidebarPortsList } from "./components/DashboardSidebarPortsList";
import { DashboardSidebarProjectSection } from "./components/DashboardSidebarProjectSection";
import { DashboardSidebarSectionRenameProvider } from "./components/DashboardSidebarSectionRenameContext";
import { useDashboardSidebarData } from "./hooks/useDashboardSidebarData";
import { useDashboardSidebarShortcuts } from "./hooks/useDashboardSidebarShortcuts";
import { DashboardSidebarHoverProvider } from "./providers/DashboardSidebarHoverProvider";
import type { DashboardSidebarProject } from "./types";

interface DashboardSidebarProps {
Expand Down Expand Up @@ -136,61 +138,65 @@ export function DashboardSidebar({

return (
<DashboardSidebarSectionRenameProvider>
<div className="flex h-full flex-col border-r border-border bg-muted/45 dark:bg-muted/35">
<DashboardSidebarHeader isCollapsed={isCollapsed} />
<DashboardSidebarHoverProvider>
<DashboardSidebarHoverCardOverlay>
<div className="flex h-full flex-col border-r border-border bg-muted/45 dark:bg-muted/35">
<DashboardSidebarHeader isCollapsed={isCollapsed} />

<div className="flex-1 overflow-y-auto hide-scrollbar">
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
measuring={{
droppable: { strategy: MeasuringStrategy.Always },
}}
onDragStart={({ active }) => {
const project = groups.find((p) => p.id === active.id);
setActiveProject(project ?? null);
}}
onDragEnd={handleDragEnd}
onDragCancel={() => setActiveProject(null)}
>
<SortableContext
items={projectOrder}
strategy={verticalListSortingStrategy}
>
{orderedGroups.map((project) => (
<SortableProjectWrapper
key={project.id}
project={project}
isCollapsed={isCollapsed}
isDraggingProject={activeProject != null}
workspaceShortcutLabels={workspaceShortcutLabels}
onWorkspaceHover={refreshWorkspacePullRequest}
onToggleCollapse={toggleProjectCollapsed}
/>
))}
</SortableContext>

{createPortal(
<DragOverlay dropAnimation={null}>
{activeProject && (
<div className="bg-background shadow-lg border-b border-border">
<DashboardSidebarProjectSection
project={activeProject}
isSidebarCollapsed={isCollapsed}
isDraggingProject
<div className="flex-1 overflow-y-auto hide-scrollbar">
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
measuring={{
droppable: { strategy: MeasuringStrategy.Always },
}}
onDragStart={({ active }) => {
const project = groups.find((p) => p.id === active.id);
setActiveProject(project ?? null);
}}
onDragEnd={handleDragEnd}
onDragCancel={() => setActiveProject(null)}
>
<SortableContext
items={projectOrder}
strategy={verticalListSortingStrategy}
>
{orderedGroups.map((project) => (
<SortableProjectWrapper
key={project.id}
project={project}
isCollapsed={isCollapsed}
isDraggingProject={activeProject != null}
workspaceShortcutLabels={workspaceShortcutLabels}
onWorkspaceHover={() => {}}
onToggleCollapse={() => {}}
onWorkspaceHover={refreshWorkspacePullRequest}
onToggleCollapse={toggleProjectCollapsed}
/>
</div>
))}
</SortableContext>

{createPortal(
<DragOverlay dropAnimation={null}>
{activeProject && (
<div className="bg-background shadow-lg border-b border-border">
<DashboardSidebarProjectSection
project={activeProject}
isSidebarCollapsed={isCollapsed}
isDraggingProject
workspaceShortcutLabels={workspaceShortcutLabels}
onWorkspaceHover={() => {}}
onToggleCollapse={() => {}}
/>
</div>
)}
</DragOverlay>,
document.body,
)}
</DragOverlay>,
document.body,
)}
</DndContext>
</div>
{!isCollapsed && <DashboardSidebarPortsList />}
</div>
</DndContext>
</div>
{!isCollapsed && <DashboardSidebarPortsList />}
</div>
</DashboardSidebarHoverCardOverlay>
</DashboardSidebarHoverProvider>
</DashboardSidebarSectionRenameProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Animate the sidebar hover card sliding between rows. Targets the
* Radix popper wrapper (which carries the position transform) only after
* it has been placed at its anchor (`data-…="ready"`), so the initial
* measuring jump from translate(0, -200%) is not animated. */
[data-radix-popper-content-wrapper]:has(
> [data-dashboard-sidebar-hover-card="ready"]
) {
transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Popover, PopoverAnchor, PopoverContent } from "@superset/ui/popover";
import type { RefObject } from "react";
import { useEffect, useRef, useState } from "react";
import { useDiffStats } from "renderer/hooks/host-service/useDiffStats";
import { useDashboardSidebarHover } from "../../providers/DashboardSidebarHoverProvider";
import { DashboardSidebarWorkspaceHoverCardContent } from "../DashboardSidebarWorkspaceItem/components/DashboardSidebarWorkspaceHoverCardContent";
import "./DashboardSidebarHoverCardOverlay.css";

type Measurable = { getBoundingClientRect(): DOMRect };

export function DashboardSidebarHoverCardOverlay({
children,
}: {
children: React.ReactNode;
}) {
const {
hoveredId,
anchorElement,
payload,
contextMenuOpen,
cancelClose,
requestClose,
forceClose,
} = useDashboardSidebarHover();

const virtualRef = useRef<Measurable | null>(null);
virtualRef.current = anchorElement;

const open = hoveredId !== null && payload !== null && !contextMenuOpen;
const diffStats = useDiffStats(hoveredId ?? "");

// Suppress the transform transition until Radix has placed the popover at
// its real anchor — otherwise the initial jump from the off-screen measuring
// position (translate(0, -200%)) gets animated.
const [hasPositioned, setHasPositioned] = useState(false);
const frameRef = useRef<number | null>(null);
useEffect(() => {
if (!open) {
setHasPositioned(false);
return;
}
const first = requestAnimationFrame(() => {
frameRef.current = requestAnimationFrame(() => setHasPositioned(true));
});
frameRef.current = first;
return () => {
if (frameRef.current !== null) cancelAnimationFrame(frameRef.current);
};
}, [open]);

return (
<Popover
open={open}
onOpenChange={(nextOpen) => {
if (!nextOpen) forceClose();
}}
>
{children}
<PopoverAnchor virtualRef={virtualRef as RefObject<Measurable>} />
{payload && (
<PopoverContent
side="right"
align="start"
className="w-72"
data-dashboard-sidebar-hover-card={hasPositioned ? "ready" : ""}
onOpenAutoFocus={(event) => event.preventDefault()}
onPointerEnter={cancelClose}
onPointerLeave={() => {
if (hoveredId) requestClose(hoveredId);
}}
>
<DashboardSidebarWorkspaceHoverCardContent
workspace={payload.workspace}
diffStats={diffStats}
onEditBranchClick={payload.onEditBranchClick}
/>
</PopoverContent>
)}
</Popover>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { DashboardSidebarHoverCardOverlay } from "./DashboardSidebarHoverCardOverlay";
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useNavigate } from "@tanstack/react-router";
import { useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useDiffStats } from "renderer/hooks/host-service/useDiffStats";
import { useOptimisticCollectionActions } from "renderer/routes/_authenticated/hooks/useOptimisticCollectionActions";
import { useDeletingWorkspaces } from "renderer/routes/_authenticated/providers/DeletingWorkspacesProvider";
import { RenameBranchDialog } from "renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/components";
import { useV2WorkspaceNotificationStatus } from "renderer/stores/v2-notifications";
import { useDashboardSidebarHover } from "../../providers/DashboardSidebarHoverProvider";
import type { DashboardSidebarWorkspace } from "../../types";
import { DashboardSidebarDeleteDialog } from "../DashboardSidebarDeleteDialog";
import { DashboardSidebarCollapsedWorkspaceButton } from "./components/DashboardSidebarCollapsedWorkspaceButton";
import { DashboardSidebarExpandedWorkspaceRow } from "./components/DashboardSidebarExpandedWorkspaceRow";
import { DashboardSidebarWorkspaceContextMenu } from "./components/DashboardSidebarWorkspaceContextMenu/DashboardSidebarWorkspaceContextMenu";
import { DashboardSidebarWorkspaceHoverCardContent } from "./components/DashboardSidebarWorkspaceHoverCardContent";
import { useDashboardSidebarWorkspaceItemActions } from "./hooks/useDashboardSidebarWorkspaceItemActions";

interface DashboardSidebarWorkspaceItemProps {
Expand Down Expand Up @@ -89,9 +89,46 @@ export function DashboardSidebarWorkspaceItem({
}
: undefined;

const {
hoveredId: hoverHoveredId,
requestOpen: hoverRequestOpen,
requestClose: hoverRequestClose,
syncIfHovered: hoverSyncIfHovered,
} = useDashboardSidebarHover();
const rowRef = useRef<HTMLDivElement>(null);
const hoverEligible = !isPending;
const hoverPayload = useMemo(
() => ({ workspace, onEditBranchClick: setRenameBranchTarget }),
[workspace],
);

const handleMouseEnter = useCallback(() => {
if (!hoverEligible || !rowRef.current) return;
hoverRequestOpen(id, rowRef.current, hoverPayload);
}, [hoverEligible, hoverRequestOpen, id, hoverPayload]);
const handleMouseLeave = useCallback(() => {
if (!hoverEligible) return;
hoverRequestClose(id);
}, [hoverEligible, hoverRequestClose, id]);

const isHovered = hoverHoveredId === id;
useEffect(() => {
if (isHovered && hostType === "local-device") onHoverCardOpen?.();
}, [isHovered, hostType, onHoverCardOpen]);
useEffect(() => {
if (!isHovered) return;
hoverSyncIfHovered(id, hoverPayload);
}, [isHovered, hoverSyncIfHovered, id, hoverPayload]);
Comment on lines +114 to +121
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 No unmount cleanup for hover state

If a workspace item unmounts while its hover card is open (e.g., the workspace is closed/deleted remotely while the card is showing), hoveredId stays set in the context and the popover remains visible with a detached anchor. getBoundingClientRect() on a detached element returns all-zeros, so the card jumps to the top-left of the screen and stays there until the user moves their mouse.

Adding a cleanup effect that calls hoverRequestClose(id) on unmount prevents this:

useEffect(() => {
  return () => {
    hoverRequestClose(id);
  };
}, [hoverRequestClose, id]);
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/DashboardSidebarWorkspaceItem/DashboardSidebarWorkspaceItem.tsx
Line: 114-121

Comment:
**No unmount cleanup for hover state**

If a workspace item unmounts while its hover card is open (e.g., the workspace is closed/deleted remotely while the card is showing), `hoveredId` stays set in the context and the popover remains visible with a detached anchor. `getBoundingClientRect()` on a detached element returns all-zeros, so the card jumps to the top-left of the screen and stays there until the user moves their mouse.

Adding a cleanup effect that calls `hoverRequestClose(id)` on unmount prevents this:

```ts
useEffect(() => {
  return () => {
    hoverRequestClose(id);
  };
}, [hoverRequestClose, id]);
```

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


if (isCollapsed) {
const content = (
<div className="relative flex w-full justify-center">
// biome-ignore lint/a11y/noStaticElementInteractions: hover handlers drive a non-interactive popover, no new keyboard semantics
<div
ref={rowRef}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
className="relative flex w-full justify-center"
>
{(accentColor || isActive) && (
<div
className="absolute inset-y-0 left-0 w-0.5"
Expand Down Expand Up @@ -126,16 +163,6 @@ export function DashboardSidebarWorkspaceItem({
projectId={projectId}
isInSection={isInSection}
isUnread={isUnread}
onHoverCardOpen={
hostType === "local-device" ? onHoverCardOpen : undefined
}
hoverCardContent={
<DashboardSidebarWorkspaceHoverCardContent
workspace={workspace}
diffStats={diffStats}
onEditBranchClick={setRenameBranchTarget}
/>
}
isLocalWorkspace={hostType === "local-device"}
onCreateSection={handleCreateSection}
onMoveToSection={(targetSectionId) =>
Expand Down Expand Up @@ -181,22 +208,29 @@ export function DashboardSidebarWorkspaceItem({
}

const expandedContent = (
<DashboardSidebarExpandedWorkspaceRow
workspace={workspace}
isActive={isActive}
isRenaming={isRenaming}
renameValue={renameValue}
shortcutLabel={shortcutLabel}
diffStats={isPending ? null : diffStats}
workspaceStatus={workspaceStatus}
onClick={isPending ? handlePendingClick : handleClick}
onDoubleClick={isPending ? undefined : startRename}
onRemoveFromSidebarClick={handleRemoveFromSidebar}
onCloseWorkspaceClick={() => setIsDeleteDialogOpen(true)}
onRenameValueChange={setRenameValue}
onSubmitRename={submitRename}
onCancelRename={cancelRename}
/>
// biome-ignore lint/a11y/noStaticElementInteractions: hover handlers drive a non-interactive popover, no new keyboard semantics
<div
ref={rowRef}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<DashboardSidebarExpandedWorkspaceRow
workspace={workspace}
isActive={isActive}
isRenaming={isRenaming}
renameValue={renameValue}
shortcutLabel={shortcutLabel}
diffStats={isPending ? null : diffStats}
workspaceStatus={workspaceStatus}
onClick={isPending ? handlePendingClick : handleClick}
onDoubleClick={isPending ? undefined : startRename}
onRemoveFromSidebarClick={handleRemoveFromSidebar}
onCloseWorkspaceClick={() => setIsDeleteDialogOpen(true)}
onRenameValueChange={setRenameValue}
onSubmitRename={submitRename}
onCancelRename={cancelRename}
/>
</div>
);

return (
Expand All @@ -209,16 +243,6 @@ export function DashboardSidebarWorkspaceItem({
projectId={projectId}
isInSection={isInSection}
isUnread={isUnread}
onHoverCardOpen={
hostType === "local-device" ? onHoverCardOpen : undefined
}
hoverCardContent={
<DashboardSidebarWorkspaceHoverCardContent
workspace={workspace}
diffStats={diffStats}
onEditBranchClick={setRenameBranchTarget}
/>
}
onCreateSection={handleCreateSection}
onMoveToSection={(targetSectionId) =>
moveWorkspaceToSection(id, projectId, targetSectionId)
Expand Down
Loading
Loading