diff --git a/packages/react/src/container/FlowRenderer/index.tsx b/packages/react/src/container/FlowRenderer/index.tsx index 1aa92c41..0c1d1db9 100644 --- a/packages/react/src/container/FlowRenderer/index.tsx +++ b/packages/react/src/container/FlowRenderer/index.tsx @@ -28,6 +28,8 @@ export type FlowRendererProps = Omit< children: ReactNode; }; +const win = typeof window === 'undefined' ? window : undefined; + const selector = (s: ReactFlowState) => { return { nodesSelectionActive: s.nodesSelectionActive, userSelectionActive: s.userSelectionActive }; }; @@ -70,8 +72,8 @@ function FlowRendererComponent({ isControlledViewport, }: FlowRendererProps) { const { nodesSelectionActive, userSelectionActive } = useStore(selector); - const selectionKeyPressed = useKeyPress(selectionKeyCode, { target: window }); - const panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: window }); + const selectionKeyPressed = useKeyPress(selectionKeyCode, { target: win }); + const panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: win }); const panOnDrag = panActivationKeyPressed || _panOnDrag; const panOnScroll = panActivationKeyPressed || _panOnScroll; diff --git a/packages/react/src/hooks/useGlobalKeyHandler.ts b/packages/react/src/hooks/useGlobalKeyHandler.ts index 8e0c34bb..10ba625c 100644 --- a/packages/react/src/hooks/useGlobalKeyHandler.ts +++ b/packages/react/src/hooks/useGlobalKeyHandler.ts @@ -9,6 +9,7 @@ import { Edge, Node } from '../types'; const selected = (item: Node | Edge) => item.selected; const deleteKeyOptions: UseKeyPressOptions = { actInsideInputWithModifier: false }; +const win = typeof window === 'undefined' ? window : undefined; /** * Hook for handling global key events. @@ -26,7 +27,7 @@ export function useGlobalKeyHandler({ const { deleteElements } = useReactFlow(); const deleteKeyPressed = useKeyPress(deleteKeyCode, deleteKeyOptions); - const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode, { target: window }); + const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode, { target: win }); useEffect(() => { if (deleteKeyPressed) {