Skip to content

Commit b1801d4

Browse files
fix
1 parent 14356f1 commit b1801d4

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

chrome/src/components/TreeItem.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ RenderKey.displayName = "RenderKey";
6161

6262
export const TreeItem = ({
6363
node,
64-
// isScrolling,
6564
className,
6665
withKey = true,
6766
withTag = true,
@@ -73,7 +72,6 @@ export const TreeItem = ({
7372
width?: number;
7473
node: PlainNode;
7574
className?: string;
76-
// isScrolling?: boolean;
7775
withCollapse?: boolean;
7876
withTrigger?: boolean;
7977
withSelect?: boolean;
@@ -159,11 +157,11 @@ export const TreeItem = ({
159157
setClose(node.i);
160158
}}
161159
>
162-
{hasChild ? (
160+
{hasChild && (
163161
<Tooltip content={!currentIsClose ? "Toggle to close" : "Toggle to open"} delay={800} showArrow color="foreground">
164162
{StateIcon}
165163
</Tooltip>
166-
) : null}
164+
)}
167165
</span>
168166
)}
169167
<p className="node-name line-clamp-1">{finalName}</p>

chrome/src/components/TreeView.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
33
import { Virtuoso } from "react-virtuoso";
44

55
import { useAppTree } from "@/hooks/useAppTree";
6-
import { useCallbackRef } from "@/hooks/useCallbackRef";
6+
// import { useCallbackRef } from "@/hooks/useCallbackRef";
77
import { useSelectNode } from "@/hooks/useSelectNode";
88
import { useDomSize } from "@/hooks/useSize";
99
import { UISize, useUISize } from "@/hooks/useUISize";
@@ -56,22 +56,22 @@ const TreeViewImpl = memo(({ onScroll, data, onMount }: { onScroll: () => void;
5656

5757
const size = useUISize.useShallowStableSelector((s) => s.state);
5858

59-
const render = useCallbackRef((index: number, _: unknown) => {
59+
const render = (index: number, _: unknown) => {
6060
const node = data[index];
6161

6262
if (!node) return null;
6363

6464
return <TreeItem node={node} className={size === UISize.sm ? "text-[12px]" : size === UISize.md ? "text-[14px]" : "text-[16px]"} />;
65-
});
65+
};
6666

6767
useEffect(() => {
68-
onScroll();
69-
7068
const cb = useSelectNode.subscribe(
7169
(s) => s.scroll,
7270
() => {
7371
const select = useSelectNode.getReadonlyState().select;
72+
7473
const index = dataRef.current?.findIndex((item) => item.i === select);
74+
7575
if (index !== -1) {
7676
ref.current?.scrollIntoView({ index, align: "center", done: onScroll });
7777
}
@@ -87,16 +87,6 @@ const TreeViewImpl = memo(({ onScroll, data, onMount }: { onScroll: () => void;
8787
return () => onMount();
8888
}, [onMount]);
8989

90-
useEffect(() => {
91-
chrome.devtools?.inspectedWindow?.eval?.(`(() => {
92-
if (window['$$$$0'] !== $0) {
93-
window.__MY_REACT_DEVTOOL_INTERNAL__?.setSelectDom?.($0);
94-
window.__MY_REACT_DEVTOOL_INTERNAL__?.notifySelectSync?.();
95-
window['$$$$0'] = $0;
96-
}
97-
})()`);
98-
}, []);
99-
10090
return <Virtuoso ref={ref} increaseViewportBy={500} onScroll={onScroll} totalCount={data.length} itemContent={render} />;
10191
});
10292

@@ -107,7 +97,7 @@ export const TreeView = memo(() => {
10797

10898
const nodes = useAppTree.useShallowStableSelector((s) => s.list) as PlainNode[];
10999

110-
const { width } = useDomSize({ ref });
100+
const { width, height } = useDomSize({ ref });
111101

112102
const [r, setR] = useState<VirtuosoHandle>();
113103

@@ -125,7 +115,7 @@ export const TreeView = memo(() => {
125115

126116
useEffect(() => {
127117
onScroll();
128-
}, [onScroll, width]);
118+
}, [onScroll, width, height, nodes.length]);
129119

130120
return (
131121
<div className="tree-view h-full p-1">

0 commit comments

Comments
 (0)