mirror of
https://github.com/langgenius/dify.git
synced 2026-07-29 16:29:36 +08:00
fix(workflow): avoid false draft save error during Strict Mode initia… (#39353)
This commit is contained in:
parent
4f8477427e
commit
f5024f5440
@ -421,6 +421,7 @@ const WorkflowMain = ({ nodes, edges, viewport }: WorkflowMainProps) => {
|
||||
viewport={viewport}
|
||||
onWorkflowDataUpdate={handleWorkflowDataUpdate}
|
||||
hooksStore={hooksStore as unknown as Partial<HooksStoreShape>}
|
||||
isCollaborationEnabled={isCollaborationEnabled}
|
||||
cursors={filteredCursors}
|
||||
myUserId={myUserId}
|
||||
onlineUsers={onlineUsers}
|
||||
|
||||
@ -25,6 +25,7 @@ const reactFlowBridge = vi.hoisted(() => ({
|
||||
}))
|
||||
|
||||
const collaborationBridge = vi.hoisted(() => ({
|
||||
canPersistLocalGraph: vi.fn(),
|
||||
graphImportHandler: null as null | ((payload: { nodes: Node[]; edges: Edge[] }) => void),
|
||||
historyActionHandler: null as null | ((payload: unknown) => void),
|
||||
restoreIntentHandler: null as
|
||||
@ -196,6 +197,7 @@ vi.mock('@langgenius/dify-ui/toast', () => ({
|
||||
|
||||
vi.mock('../collaboration/core/collaboration-manager', () => ({
|
||||
collaborationManager: {
|
||||
canPersistLocalGraph: collaborationBridge.canPersistLocalGraph,
|
||||
onGraphImport: (handler: (payload: { nodes: Node[]; edges: Edge[] }) => void) => {
|
||||
collaborationBridge.graphImportHandler = handler
|
||||
return vi.fn()
|
||||
@ -453,12 +455,18 @@ function renderSubject(options?: {
|
||||
nodes?: Node[]
|
||||
edges?: Edge[]
|
||||
initialStoreState?: Record<string, unknown>
|
||||
isCollaborationEnabled?: boolean
|
||||
}) {
|
||||
const { nodes = baseNodes, edges = baseEdges, initialStoreState } = options ?? {}
|
||||
const {
|
||||
nodes = baseNodes,
|
||||
edges = baseEdges,
|
||||
initialStoreState,
|
||||
isCollaborationEnabled,
|
||||
} = options ?? {}
|
||||
|
||||
return renderWorkflowComponent(
|
||||
<ReactFlowProvider>
|
||||
<Workflow nodes={nodes} edges={edges}>
|
||||
<Workflow nodes={nodes} edges={edges} isCollaborationEnabled={isCollaborationEnabled}>
|
||||
<ReactFlowEdgeBootstrap nodes={nodes} edges={edges} />
|
||||
</Workflow>
|
||||
</ReactFlowProvider>,
|
||||
@ -514,6 +522,7 @@ vi.mock('@/context/permission-state', async () => {
|
||||
describe('Workflow edge event wiring', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
collaborationBridge.canPersistLocalGraph.mockReturnValue(true)
|
||||
eventEmitterState.subscription = null
|
||||
reactFlowBridge.store = null
|
||||
collaborationBridge.graphImportHandler = null
|
||||
@ -615,7 +624,7 @@ describe('Workflow edge event wiring', () => {
|
||||
},
|
||||
)
|
||||
|
||||
const { unmount } = renderSubject()
|
||||
const { unmount } = renderSubject({ isCollaborationEnabled: true })
|
||||
|
||||
unmount()
|
||||
|
||||
@ -624,6 +633,17 @@ describe('Workflow edge event wiring', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should skip the unmount save while the collaborative graph is not ready', () => {
|
||||
collaborationBridge.canPersistLocalGraph.mockReturnValue(false)
|
||||
|
||||
const { unmount } = renderSubject({ isCollaborationEnabled: true })
|
||||
|
||||
unmount()
|
||||
|
||||
expect(workflowHookMocks.handleSyncWorkflowDraft).not.toHaveBeenCalled()
|
||||
expect(toastErrorMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should render confirm description and clear showConfirm when cancelled', async () => {
|
||||
const onConfirm = vi.fn()
|
||||
const { store } = renderSubject({
|
||||
|
||||
@ -125,6 +125,7 @@ export type WorkflowProps = {
|
||||
viewport?: Viewport
|
||||
children?: React.ReactNode
|
||||
onWorkflowDataUpdate?: (v: WorkflowDataUpdatePayload) => void
|
||||
isCollaborationEnabled?: boolean
|
||||
cursors?: Record<string, CursorPosition>
|
||||
myUserId?: string | null
|
||||
onlineUsers?: OnlineUser[]
|
||||
@ -168,6 +169,7 @@ export const Workflow: FC<WorkflowProps> = memo(
|
||||
viewport,
|
||||
children,
|
||||
onWorkflowDataUpdate,
|
||||
isCollaborationEnabled = false,
|
||||
cursors,
|
||||
myUserId,
|
||||
onlineUsers,
|
||||
@ -364,6 +366,8 @@ export const Workflow: FC<WorkflowProps> = memo(
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (isCollaborationEnabled && !collaborationManager.canPersistLocalGraph()) return
|
||||
|
||||
handleSyncWorkflowDraft(true, true, {
|
||||
onError: () => {
|
||||
toast.error(
|
||||
@ -375,7 +379,7 @@ export const Workflow: FC<WorkflowProps> = memo(
|
||||
},
|
||||
})
|
||||
}
|
||||
}, [handleSyncWorkflowDraft, t])
|
||||
}, [handleSyncWorkflowDraft, isCollaborationEnabled, t])
|
||||
|
||||
const handlePendingCommentPositionChange = useCallback(
|
||||
(position: NonNullable<WorkflowSliceShape['pendingComment']>) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user