Avoid eager sidebar collection allocation
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
20f37f367a
commit
a504c7bf88
1 file changed
+14
-14
@@ -323,7 +323,7 @@ interface SidebarThreadRowProps {
|
||||
renamingCommittedRef: React.RefObject<boolean>;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
setConfirmingArchiveThreadKey: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
confirmArchiveButtonRefs: React.RefObject<Map<string, HTMLButtonElement>>;
|
||||
confirmArchiveButtonRefs: Map<string, HTMLButtonElement>;
|
||||
handleThreadClick: (
|
||||
event: React.MouseEvent,
|
||||
threadRef: ScopedThreadRef,
|
||||
@@ -608,9 +608,9 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
const handleConfirmArchiveRef = useCallback(
|
||||
(element: HTMLButtonElement | null) => {
|
||||
if (element) {
|
||||
confirmArchiveButtonRefs.current.set(threadKey, element);
|
||||
confirmArchiveButtonRefs.set(threadKey, element);
|
||||
} else {
|
||||
confirmArchiveButtonRefs.current.delete(threadKey);
|
||||
confirmArchiveButtonRefs.delete(threadKey);
|
||||
}
|
||||
},
|
||||
[confirmArchiveButtonRefs, threadKey],
|
||||
@@ -636,7 +636,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
event.stopPropagation();
|
||||
setConfirmingArchiveThreadKey(threadKey);
|
||||
requestAnimationFrame(() => {
|
||||
confirmArchiveButtonRefs.current.get(threadKey)?.focus();
|
||||
confirmArchiveButtonRefs.get(threadKey)?.focus();
|
||||
});
|
||||
},
|
||||
[confirmArchiveButtonRefs, setConfirmingArchiveThreadKey, threadKey],
|
||||
@@ -888,7 +888,7 @@ interface SidebarProjectThreadListProps {
|
||||
renamingCommittedRef: React.RefObject<boolean>;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
setConfirmingArchiveThreadKey: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
confirmArchiveButtonRefs: React.RefObject<Map<string, HTMLButtonElement>>;
|
||||
confirmArchiveButtonRefs: Map<string, HTMLButtonElement>;
|
||||
attachThreadListAutoAnimateRef: (node: HTMLElement | null) => void;
|
||||
handleThreadClick: (
|
||||
event: React.MouseEvent,
|
||||
@@ -1223,7 +1223,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
|
||||
>("inherit");
|
||||
const renamingCommittedRef = useRef(false);
|
||||
const renamingInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const confirmArchiveButtonRefs = useRef(new Map<string, HTMLButtonElement>());
|
||||
const confirmArchiveButtonRefs = useMemo(() => new Map<string, HTMLButtonElement>(), []);
|
||||
const memberProjectByScopedKey = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
@@ -3246,23 +3246,23 @@ export default function Sidebar() {
|
||||
dragInProgressRef.current = false;
|
||||
}, []);
|
||||
|
||||
const animatedProjectListsRef = useRef(new WeakSet<HTMLElement>());
|
||||
const animatedProjectLists = useMemo(() => new WeakSet<HTMLElement>(), []);
|
||||
const attachProjectListAutoAnimateRef = useCallback((node: HTMLElement | null) => {
|
||||
if (!node || animatedProjectListsRef.current.has(node)) {
|
||||
if (!node || animatedProjectLists.has(node)) {
|
||||
return;
|
||||
}
|
||||
autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS);
|
||||
animatedProjectListsRef.current.add(node);
|
||||
}, []);
|
||||
animatedProjectLists.add(node);
|
||||
}, [animatedProjectLists]);
|
||||
|
||||
const animatedThreadListsRef = useRef(new WeakSet<HTMLElement>());
|
||||
const animatedThreadLists = useMemo(() => new WeakSet<HTMLElement>(), []);
|
||||
const attachThreadListAutoAnimateRef = useCallback((node: HTMLElement | null) => {
|
||||
if (!node || animatedThreadListsRef.current.has(node)) {
|
||||
if (!node || animatedThreadLists.has(node)) {
|
||||
return;
|
||||
}
|
||||
autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS);
|
||||
animatedThreadListsRef.current.add(node);
|
||||
}, []);
|
||||
animatedThreadLists.add(node);
|
||||
}, [animatedThreadLists]);
|
||||
|
||||
const visibleThreads = useMemo(
|
||||
() => sidebarThreads.filter((thread) => thread.archivedAt === null),
|
||||
|
||||
Reference in new issue
Block a user