mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix jank w/ stale connections
This commit is contained in:
parent
c359ab6d9b
commit
e3a143eaed
@ -7,6 +7,8 @@ import { useIsValidConnection } from 'features/nodes/hooks/useIsValidConnection'
|
|||||||
import { useWorkflowWatcher } from 'features/nodes/hooks/useWorkflowWatcher';
|
import { useWorkflowWatcher } from 'features/nodes/hooks/useWorkflowWatcher';
|
||||||
import {
|
import {
|
||||||
$cursorPos,
|
$cursorPos,
|
||||||
|
$isAddNodePopoverOpen,
|
||||||
|
$pendingConnection,
|
||||||
$viewport,
|
$viewport,
|
||||||
connectionMade,
|
connectionMade,
|
||||||
edgeAdded,
|
edgeAdded,
|
||||||
@ -33,8 +35,9 @@ import type {
|
|||||||
OnNodesDelete,
|
OnNodesDelete,
|
||||||
ProOptions,
|
ProOptions,
|
||||||
ReactFlowProps,
|
ReactFlowProps,
|
||||||
|
ReactFlowState,
|
||||||
} from 'reactflow';
|
} from 'reactflow';
|
||||||
import { Background, ReactFlow } from 'reactflow';
|
import { Background, ReactFlow, useStore as useReactFlowStore } from 'reactflow';
|
||||||
|
|
||||||
import CustomConnectionLine from './connectionLines/CustomConnectionLine';
|
import CustomConnectionLine from './connectionLines/CustomConnectionLine';
|
||||||
import InvocationCollapsedEdge from './edges/InvocationCollapsedEdge';
|
import InvocationCollapsedEdge from './edges/InvocationCollapsedEdge';
|
||||||
@ -61,6 +64,8 @@ const proOptions: ProOptions = { hideAttribution: true };
|
|||||||
|
|
||||||
const snapGrid: [number, number] = [25, 25];
|
const snapGrid: [number, number] = [25, 25];
|
||||||
|
|
||||||
|
const selectCancelConnection = (state: ReactFlowState) => state.cancelConnection;
|
||||||
|
|
||||||
export const Flow = memo(() => {
|
export const Flow = memo(() => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const nodes = useAppSelector((s) => s.nodes.present.nodes);
|
const nodes = useAppSelector((s) => s.nodes.present.nodes);
|
||||||
@ -73,6 +78,7 @@ export const Flow = memo(() => {
|
|||||||
const { onConnectStart, onConnect, onConnectEnd } = useConnection();
|
const { onConnectStart, onConnect, onConnectEnd } = useConnection();
|
||||||
const flowWrapper = useRef<HTMLDivElement>(null);
|
const flowWrapper = useRef<HTMLDivElement>(null);
|
||||||
const isValidConnection = useIsValidConnection();
|
const isValidConnection = useIsValidConnection();
|
||||||
|
const cancelConnection = useReactFlowStore(selectCancelConnection);
|
||||||
useWorkflowWatcher();
|
useWorkflowWatcher();
|
||||||
const [borderRadius] = useToken('radii', ['base']);
|
const [borderRadius] = useToken('radii', ['base']);
|
||||||
|
|
||||||
@ -234,6 +240,13 @@ export const Flow = memo(() => {
|
|||||||
}, [dispatch, mayRedo]);
|
}, [dispatch, mayRedo]);
|
||||||
useHotkeys(['meta+shift+z', 'ctrl+shift+z'], onRedoHotkey);
|
useHotkeys(['meta+shift+z', 'ctrl+shift+z'], onRedoHotkey);
|
||||||
|
|
||||||
|
const onEscapeHotkey = useCallback(() => {
|
||||||
|
$pendingConnection.set(null);
|
||||||
|
$isAddNodePopoverOpen.set(false);
|
||||||
|
cancelConnection();
|
||||||
|
}, [cancelConnection]);
|
||||||
|
useHotkeys('esc', onEscapeHotkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
id="workflow-editor"
|
id="workflow-editor"
|
||||||
|
@ -95,7 +95,15 @@ const InputField = ({ nodeId, fieldName }: Props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<InputFieldWrapper shouldDim={shouldDim}>
|
<InputFieldWrapper shouldDim={shouldDim}>
|
||||||
<FormControl isInvalid={isMissingInput} isDisabled={isConnected} orientation="vertical" px={2}>
|
<FormControl
|
||||||
|
isInvalid={isMissingInput}
|
||||||
|
isDisabled={isConnected}
|
||||||
|
// Without pointerEvents prop, disabled inputs don't trigger reactflow events. For example, when making a
|
||||||
|
// connection, the mouse up to end the connection won't fire, leaving the connection in-progress.
|
||||||
|
pointerEvents={isConnected ? 'none' : 'auto'}
|
||||||
|
orientation="vertical"
|
||||||
|
px={2}
|
||||||
|
>
|
||||||
<Flex flexDir="column" w="full" gap={1} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
<Flex flexDir="column" w="full" gap={1} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
||||||
<Flex>
|
<Flex>
|
||||||
<EditableFieldTitle
|
<EditableFieldTitle
|
||||||
|
Loading…
Reference in New Issue
Block a user