Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): update every Human Input variable block on workflow changes (#44620)

Winorenb91f4fd11d82
diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/__tests__/variable-block.spec.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/__tests__/variable-block.spec.tsx
index b24b4426ff3..8e9bc8c8c54 100644
--- a/web/app/components/base/prompt-editor/plugins/hitl-input-block/__tests__/variable-block.spec.tsx
+++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/__tests__/variable-block.spec.tsx
@@ -123,24 +123,72 @@ describe('HITLInputVariableBlockComponent', () => {
const editor = getEditor()
expect(editor).not.toBeNull()
- let handled = false
act(() => {
editor!.update(() => {
$getRoot().selectEnd()
})
- handled = editor!.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, {
+ editor!.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, {
workflowNodesMap: createWorkflowNodesMap(),
availableVariables: [],
})
})
- expect(handled).toBe(true)
await waitFor(() => {
expect(screen.getByText('Node One')).toBeInTheDocument()
})
})
})
+ it('refreshes every Human Input variable block from a single workflow map update', async () => {
+ let editor: LexicalEditor | null = null
+ render(
+ <LexicalComposer
+ initialConfig={{
+ namespace: 'hitl-variable-broadcast-test',
+ nodes: [HITLInputNode],
+ onError: (error: Error) => {
+ throw error
+ },
+ }}
+ >
+ <HITLInputVariableBlockComponent variables={['node-1', 'first']} workflowNodesMap={{}} />
+ <HITLInputVariableBlockComponent variables={['node-1', 'second']} workflowNodesMap={{}} />
+ <CaptureEditorPlugin
+ onReady={(value) => {
+ editor = value
+ }}
+ />
+ </LexicalComposer>,
+ )
+
+ await waitFor(() => {
+ expect(editor).not.toBeNull()
+ })
+ expect(screen.queryByText('Node One')).not.toBeInTheDocument()
+
+ act(() => {
+ editor!.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, {
+ workflowNodesMap: createWorkflowNodesMap(),
+ availableVariables: [],
+ })
+ })
+ await waitFor(() => {
+ expect(screen.getAllByText('Node One')).toHaveLength(2)
+ })
+
+ // Later edits must also reach both references, rather than retaining a stale title.
+ act(() => {
+ editor!.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, {
+ workflowNodesMap: createWorkflowNodesMap('Renamed Node'),
+ availableVariables: [],
+ })
+ })
+ await waitFor(() => {
+ expect(screen.getAllByText('Renamed Node')).toHaveLength(2)
+ })
+ expect(screen.queryByText('Node One')).not.toBeInTheDocument()
+ })
+
describe('Validation branches', () => {
it('should show invalid state for env variable when environment list does not contain selector', async () => {
const user = userEvent.setup()
diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/variable-block.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/variable-block.tsx
index 3c05651cc18..1d51a178555 100644
--- a/web/app/components/base/prompt-editor/plugins/hitl-input-block/variable-block.tsx
+++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/variable-block.tsx
@@ -98,7 +98,8 @@ const HITLInputVariableBlockComponent = ({
UPDATE_WORKFLOW_NODES_MAP,
(payload: UpdateWorkflowNodesMapPayload) => {
setLocalWorkflowNodesMap(payload.workflowNodesMap)
- return true
+ // Every rendered variable block must receive this broadcast update.
+ return false
},
COMMAND_PRIORITY_EDITOR,
),
diff --git a/web/app/components/plugins/plugin-auth/authorized/__tests__/index.spec.tsx b/web/app/components/plugins/plugin-auth/authorized/__tests__/index.spec.tsx
index 7537638b789..5e81f074b8e 100644
--- a/web/app/components/plugins/plugin-auth/authorized/__tests__/index.spec.tsx
+++ b/web/app/components/plugins/plugin-auth/authorized/__tests__/index.spec.tsx
@@ -156,8 +156,10 @@ describe('Authorized credential management', () => {
await user.click(confirm)
expect(confirm).toBeDisabled()
await user.click(confirm)
- expect(requests.post).toHaveBeenCalledExactlyOnceWith(`${baseUrl}/delete`, {
- body: { credential_id: 'credential-b' },
+ await waitFor(() => {
+ expect(requests.post).toHaveBeenCalledExactlyOnceWith(`${baseUrl}/delete`, {
+ body: { credential_id: 'credential-b' },
+ })
})
expect(onUpdate).not.toHaveBeenCalled()
await act(async () => {