Files
dify/web/app/components/workflow/header/scroll-to-selected-node-button.tsx
twwu 3ce404de2a perf(workflow): reduce canvas drag rendering and sync overhead
Isolate node data and search subscriptions to avoid unnecessary renders
of the workflow root and floating controls during position updates.

Reuse unchanged node references and broadcast incremental CRDT updates,
with catch-up after session reauthorization.

Add regression coverage for node data synchronization, toolbar behavior,
and collaborative graph updates.
2026-10-16 11:56:40 +08:00

33 lines
1.2 KiB
TypeScript

import type { FC } from 'react'
import type { CommonNodeType } from '../types'
import { cn } from '@langgenius/dify-ui/cn'
import { useTranslation } from 'react-i18next'
import { useStore } from 'reactflow'
import { scrollToWorkflowNode } from '../utils/node-navigation'
const ScrollToSelectedNodeButton: FC = () => {
const { t } = useTranslation(['workflow'])
const selectedNodeId = useStore((state) => {
for (const node of state.nodeInternals.values()) {
if ((node.data as CommonNodeType).selected) return node.id
}
return undefined
})
if (!selectedNodeId) return null
return (
<button
type="button"
className={cn(
'flex h-6 cursor-pointer appearance-none items-center justify-center rounded-md border-[0.5px] border-effects-highlight bg-components-actionbar-bg px-3 system-xs-medium whitespace-nowrap text-text-tertiary shadow-lg backdrop-blur-xs transition-colors duration-200 hover:text-text-accent focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden',
)}
onClick={() => scrollToWorkflowNode(selectedNodeId)}
>
{t(($) => $['panel.scrollToSelectedNode'], { ns: 'workflow' })}
</button>
)
}
export default ScrollToSelectedNodeButton