Revert "📝 (handleRenderComponent/index.tsx): Add useShallow import for zustand/react/shallow to optimize re-renders"
This reverts commit 9898d1cacd.
This commit is contained in:
parent
9898d1cacd
commit
e1c57d930c
3 changed files with 14 additions and 63 deletions
|
|
@ -3,7 +3,6 @@ import useFlowStore from "@/stores/flowStore";
|
||||||
import { nodeColorsName } from "@/utils/styleUtils";
|
import { nodeColorsName } from "@/utils/styleUtils";
|
||||||
import { Connection, Handle, Position } from "@xyflow/react";
|
import { Connection, Handle, Position } from "@xyflow/react";
|
||||||
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { useShallow } from "zustand/react/shallow";
|
|
||||||
import ShadTooltip from "../../../../components/common/shadTooltipComponent";
|
import ShadTooltip from "../../../../components/common/shadTooltipComponent";
|
||||||
import {
|
import {
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
|
|
@ -180,10 +179,6 @@ const HandleRenderComponent = memo(function HandleRenderComponent({
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const [openTooltip, setOpenTooltip] = useState(false);
|
const [openTooltip, setOpenTooltip] = useState(false);
|
||||||
|
|
||||||
const isLocked = useFlowStore(
|
|
||||||
useShallow((state) => state.currentFlow?.locked),
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setHandleDragging,
|
setHandleDragging,
|
||||||
setFilterType,
|
setFilterType,
|
||||||
|
|
@ -389,10 +384,16 @@ const HandleRenderComponent = memo(function HandleRenderComponent({
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Memoize the validation function
|
||||||
|
const validateConnection = useCallback(
|
||||||
|
(connection: any) => isValidConnection(connection),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
open={openTooltip && !isLocked}
|
open={openTooltip}
|
||||||
setOpen={setOpenTooltip}
|
setOpen={setOpenTooltip}
|
||||||
styleClasses={cn("tooltip-fixed-width custom-scroll nowheel bottom-2")}
|
styleClasses={cn("tooltip-fixed-width custom-scroll nowheel bottom-2")}
|
||||||
delayDuration={1000}
|
delayDuration={1000}
|
||||||
|
|
@ -413,16 +414,13 @@ const HandleRenderComponent = memo(function HandleRenderComponent({
|
||||||
position={left ? Position.Left : Position.Right}
|
position={left ? Position.Left : Position.Right}
|
||||||
id={myId}
|
id={myId}
|
||||||
isValidConnection={(connection) =>
|
isValidConnection={(connection) =>
|
||||||
isLocked ? false : isValidConnection(connection as Connection)
|
isValidConnection(connection as Connection)
|
||||||
}
|
}
|
||||||
className={cn(
|
className={cn(
|
||||||
`group/handle z-50 transition-all`,
|
`group/handle z-50 transition-all`,
|
||||||
!showNode && "no-show",
|
!showNode && "no-show",
|
||||||
)}
|
)}
|
||||||
style={{
|
style={BASE_HANDLE_STYLES}
|
||||||
...BASE_HANDLE_STYLES,
|
|
||||||
pointerEvents: isLocked ? "none" : "auto",
|
|
||||||
}}
|
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
onMouseUp={handleMouseUp}
|
onMouseUp={handleMouseUp}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={handleContextMenu}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import {
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useHotkeys } from "react-hotkeys-hook";
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
import { useShallow } from "zustand/react/shallow";
|
|
||||||
import GenericNode from "../../../../CustomNodes/GenericNode";
|
import GenericNode from "../../../../CustomNodes/GenericNode";
|
||||||
import {
|
import {
|
||||||
INVALID_SELECTION_ERROR_ALERT,
|
INVALID_SELECTION_ERROR_ALERT,
|
||||||
|
|
@ -125,10 +124,6 @@ export default function Page({
|
||||||
const [selectionMenuVisible, setSelectionMenuVisible] = useState(false);
|
const [selectionMenuVisible, setSelectionMenuVisible] = useState(false);
|
||||||
const edgeUpdateSuccessful = useRef(true);
|
const edgeUpdateSuccessful = useRef(true);
|
||||||
|
|
||||||
const isLocked = useFlowStore(
|
|
||||||
useShallow((state) => state.currentFlow?.locked),
|
|
||||||
);
|
|
||||||
|
|
||||||
const position = useRef({ x: 0, y: 0 });
|
const position = useRef({ x: 0, y: 0 });
|
||||||
const [lastSelection, setLastSelection] =
|
const [lastSelection, setLastSelection] =
|
||||||
useState<OnSelectionChangeParams | null>(null);
|
useState<OnSelectionChangeParams | null>(null);
|
||||||
|
|
@ -526,11 +521,6 @@ export default function Page({
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleEdgeClick = (event, edge) => {
|
const handleEdgeClick = (event, edge) => {
|
||||||
if (isLocked) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const color =
|
const color =
|
||||||
nodeColorsName[edge?.data?.sourceHandle?.output_types[0]] || "cyan";
|
nodeColorsName[edge?.data?.sourceHandle?.output_types[0]] || "cyan";
|
||||||
|
|
||||||
|
|
@ -594,13 +584,13 @@ export default function Page({
|
||||||
edges={edges}
|
edges={edges}
|
||||||
onNodesChange={onNodesChange}
|
onNodesChange={onNodesChange}
|
||||||
onEdgesChange={onEdgesChange}
|
onEdgesChange={onEdgesChange}
|
||||||
onConnect={isLocked ? undefined : onConnectMod}
|
onConnect={onConnectMod}
|
||||||
disableKeyboardA11y={true}
|
disableKeyboardA11y={true}
|
||||||
onInit={setReactFlowInstance}
|
onInit={setReactFlowInstance}
|
||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
onReconnect={isLocked ? undefined : onEdgeUpdate}
|
onReconnect={onEdgeUpdate}
|
||||||
onReconnectStart={isLocked ? undefined : onEdgeUpdateStart}
|
onReconnectStart={onEdgeUpdateStart}
|
||||||
onReconnectEnd={isLocked ? undefined : onEdgeUpdateEnd}
|
onReconnectEnd={onEdgeUpdateEnd}
|
||||||
onNodeDragStart={onNodeDragStart}
|
onNodeDragStart={onNodeDragStart}
|
||||||
onSelectionDragStart={onSelectionDragStart}
|
onSelectionDragStart={onSelectionDragStart}
|
||||||
elevateEdgesOnSelect={true}
|
elevateEdgesOnSelect={true}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { expect, Page, test } from "@playwright/test";
|
import { test } from "@playwright/test";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { awaitBootstrapTest } from "../../utils/await-bootstrap-test";
|
import { awaitBootstrapTest } from "../../utils/await-bootstrap-test";
|
||||||
|
|
@ -74,42 +74,5 @@ test(
|
||||||
timeout: 3000,
|
timeout: 3000,
|
||||||
state: "visible",
|
state: "visible",
|
||||||
});
|
});
|
||||||
|
|
||||||
await tryDeleteEdge(page);
|
|
||||||
await page.locator(".react-flow__edge-path").nth(0).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
let numberOfEdges = await page.locator(".react-flow__edge-path").count();
|
|
||||||
expect(numberOfEdges).toBe(2);
|
|
||||||
|
|
||||||
await page.locator(".react-flow__edge-path").nth(0).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
numberOfEdges = await page.locator(".react-flow__edge-path").count();
|
|
||||||
expect(numberOfEdges).toBe(1);
|
|
||||||
|
|
||||||
await page.locator(".react-flow__edge-path").nth(0).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
numberOfEdges = await page.locator(".react-flow__edge-path").count();
|
|
||||||
expect(numberOfEdges).toBe(0);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
async function tryDeleteEdge(page: Page) {
|
|
||||||
await page.getByTestId("lock_unlock").click();
|
|
||||||
|
|
||||||
let numberOfEdges = await page.locator(".react-flow__edge-path").count();
|
|
||||||
expect(numberOfEdges).toBe(3);
|
|
||||||
const numberOfTries = 50;
|
|
||||||
|
|
||||||
for (let i = 0; i < numberOfTries; i++) {
|
|
||||||
await page.locator(".react-flow__edge-path").nth(0).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
await page.locator(".react-flow__edge-path").nth(1).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
await page.locator(".react-flow__edge-path").nth(2).click();
|
|
||||||
await page.keyboard.press("Delete");
|
|
||||||
numberOfEdges = await page.locator(".react-flow__edge-path").count();
|
|
||||||
expect(numberOfEdges).toBe(3);
|
|
||||||
}
|
|
||||||
//unlock the flow
|
|
||||||
await page.getByTestId("lock_unlock").click();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue