Skip to content

Commit 76ce649

Browse files
authored
fix dependency panel edges (#6753)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Fixes #6692. Use static ids instead of useId. Reverts a previous lint fix. ![CleanShot 2025-10-13 at 11 35 05](https://github.com/user-attachments/assets/f67e6e83-b6b2-4302-b3fe-c599cfcfacf5) ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent 36647e2 commit 76ce649

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

frontend/src/components/dependency-graph/custom-node.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22

33
import { useAtomValue } from "jotai";
4-
import React, { memo, use, useId } from "react";
4+
import React, { memo, use } from "react";
55
import { Handle, Position, useStore } from "reactflow";
66
import { TinyCode } from "@/components/editor/cell/TinyCode";
77
import { useCellIds } from "@/core/cells/cells";
88
import { displayCellName } from "@/core/cells/names";
99
import { cn } from "@/utils/cn";
10-
import { type CustomNodeProps, getNodeHeight } from "./elements";
10+
import {
11+
type CustomNodeProps,
12+
getNodeHeight,
13+
INPUTS_HANDLE_ID,
14+
OUTPUTS_HANDLE_ID,
15+
} from "./elements";
1116
import type { LayoutDirection } from "./types";
1217

1318
function getWidth(canvasWidth: number) {
@@ -37,24 +42,19 @@ export const CustomNode = memo((props: CustomNodeProps) => {
3742
const reactFlowWidth = useStore(({ width }) => width);
3843
const edgeMarkers = use(EdgeMarkerContext);
3944

40-
const inputOneId = useId();
41-
const inputTwoId = useId();
42-
const outputOneId = useId();
43-
const outputTwoId = useId();
44-
4545
const linesOfCode = cell.code.split("\n").length;
4646
return (
4747
<div>
4848
<Handle
4949
type="target"
50-
id={inputOneId}
50+
id={INPUTS_HANDLE_ID}
5151
data-testid="input-one"
5252
position={edgeMarkers === "LR" ? Position.Left : Position.Top}
5353
style={{ background: color }}
5454
/>
5555
<Handle
5656
type="source"
57-
id={inputTwoId}
57+
id={INPUTS_HANDLE_ID}
5858
data-testid="input-two"
5959
position={edgeMarkers === "LR" ? Position.Left : Position.Top}
6060
style={{ background: color }}
@@ -76,14 +76,14 @@ export const CustomNode = memo((props: CustomNodeProps) => {
7676
</div>
7777
<Handle
7878
type="source"
79-
id={outputOneId}
79+
id={OUTPUTS_HANDLE_ID}
8080
data-testid="output-one"
8181
position={edgeMarkers === "LR" ? Position.Right : Position.Bottom}
8282
style={{ background: color }}
8383
/>
8484
<Handle
8585
type="target"
86-
id={outputTwoId}
86+
id={OUTPUTS_HANDLE_ID}
8787
data-testid="output-two"
8888
position={edgeMarkers === "LR" ? Position.Right : Position.Bottom}
8989
style={{ background: color }}

frontend/src/components/dependency-graph/elements.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export function getNodeHeight(linesOfCode: number) {
1919
return Math.min(linesOfCode * LINE_HEIGHT + 35, 200);
2020
}
2121

22+
// The nodes must have the same handle IDs to ensure edges connect correctly
23+
export const OUTPUTS_HANDLE_ID = "outputs";
24+
export const INPUTS_HANDLE_ID = "inputs";
25+
2226
interface ElementsBuilder {
2327
createElements: (
2428
cellIds: CellId[],
@@ -93,8 +97,8 @@ export class VerticalElementsBuilder implements ElementsBuilder {
9397
}
9498
visited.add(key);
9599
edges.push(
96-
this.createEdge(fromId, toId, "inputs"),
97-
this.createEdge(fromId, toId, "outputs"),
100+
this.createEdge(fromId, toId, INPUTS_HANDLE_ID),
101+
this.createEdge(fromId, toId, OUTPUTS_HANDLE_ID),
98102
);
99103
}
100104
}
@@ -114,8 +118,9 @@ export class TreeElementsBuilder implements ElementsBuilder {
114118
// Make thicker
115119
style: { strokeWidth: 2 },
116120
source: source,
117-
sourceHandle: "outputs",
118-
targetHandle: "inputs",
121+
// Use the same handle ids as the custom node
122+
sourceHandle: OUTPUTS_HANDLE_ID,
123+
targetHandle: INPUTS_HANDLE_ID,
119124
target: target,
120125
};
121126
}

frontend/src/components/dependency-graph/panels.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
WorkflowIcon,
1313
XIcon,
1414
} from "lucide-react";
15-
import React, { memo } from "react";
15+
import React, { memo, useId } from "react";
1616
import { type Edge, Panel } from "reactflow";
1717
import { getCellEditorView } from "@/core/cells/cells";
1818
import type { CellId } from "@/core/cells/ids";
@@ -44,6 +44,8 @@ export const GraphToolbar: React.FC<Props> = memo(
4444
onSettingsChange({ ...settings, [key]: value });
4545
};
4646

47+
const checkboxId = useId();
48+
4749
const settingsButton = (
4850
<Popover>
4951
<PopoverTrigger asChild={true}>
@@ -56,13 +58,13 @@ export const GraphToolbar: React.FC<Props> = memo(
5658
<div className="flex items-center gap-2">
5759
<Checkbox
5860
data-testid="hide-pure-markdown-checkbox"
59-
id="hide-pure-markdown"
61+
id={checkboxId}
6062
checked={settings.hidePureMarkdown}
6163
onCheckedChange={(checked) =>
6264
handleSettingChange("hidePureMarkdown", Boolean(checked))
6365
}
6466
/>
65-
<Label htmlFor="hide-pure-markdown">Hide pure markdown</Label>
67+
<Label htmlFor={checkboxId}>Hide pure markdown</Label>
6668
</div>
6769
</PopoverContent>
6870
</Popover>
@@ -114,7 +116,7 @@ export const GraphSelectionPanel: React.FC<{
114116
onClearSelection: () => void;
115117
edges: Edge[];
116118
variables: Variables;
117-
}> = memo(({ selection, edges, variables, onClearSelection }) => {
119+
}> = memo(({ selection, variables, onClearSelection }) => {
118120
if (!selection) {
119121
return null;
120122
}

0 commit comments

Comments
 (0)