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): save agent configure draft on route leave (#38620)

yyheb74946b2511
diff --git a/web/features/agent-v2/agent-detail/configure/__tests__/use-agent-configure-sync.spec.tsx b/web/features/agent-v2/agent-detail/configure/__tests__/use-agent-configure-sync.spec.tsx
index 55148b316b3..0061772e233 100644
--- a/web/features/agent-v2/agent-detail/configure/__tests__/use-agent-configure-sync.spec.tsx
+++ b/web/features/agent-v2/agent-detail/configure/__tests__/use-agent-configure-sync.spec.tsx
@@ -315,6 +315,40 @@ describe('useAgentConfigureSync', () => {
})
})
+ it('should save the latest dirty draft when Configure unmounts before autosave runs', async () => {
+ const { store, unmount } = renderUseAgentConfigureSync()
+
+ act(() => {
+ store.set(agentComposerDraftAtom, {
+ ...defaultAgentSoulConfigFormState,
+ prompt: 'Route leave prompt',
+ })
+ })
+
+ expect(composerPutMutationFn).not.toHaveBeenCalled()
+
+ await act(async () => {
+ unmount()
+ await Promise.resolve()
+ })
+
+ expect(composerPutMutationFn).toHaveBeenCalledTimes(1)
+ expect(composerPutMutationFn).toHaveBeenCalledWith(expect.objectContaining({
+ params: {
+ agent_id: 'agent-1',
+ },
+ body: expect.objectContaining({
+ variant: 'agent_app',
+ save_strategy: 'save_to_current_version',
+ agent_soul: expect.objectContaining({
+ prompt: expect.objectContaining({
+ system_prompt: 'Route leave prompt',
+ }),
+ }),
+ }),
+ }))
+ })
+
it('should include Agent Soul files when autosaving file changes', async () => {
const { store } = renderUseAgentConfigureSync()
diff --git a/web/features/agent-v2/agent-detail/configure/use-agent-configure-sync.ts b/web/features/agent-v2/agent-detail/configure/use-agent-configure-sync.ts
index 96ee788e0f9..98c92c0efe6 100644
--- a/web/features/agent-v2/agent-detail/configure/use-agent-configure-sync.ts
+++ b/web/features/agent-v2/agent-detail/configure/use-agent-configure-sync.ts
@@ -208,12 +208,6 @@ export function useAgentConfigureSync({
})
}, [debouncedSaveDraft, getAgentSoulDraft, store])
- useEffect(() => {
- return () => {
- debouncedSaveDraft.flush?.()
- }
- }, [debouncedSaveDraft])
-
useEffect(() => {
const saveDraftWhenPageHidden = () => {
if (document.visibilityState === 'hidden')
@@ -232,6 +226,12 @@ export function useAgentConfigureSync({
}
}, [saveDirtyDraftOnPageClose])
+ useEffect(() => {
+ return () => {
+ saveDirtyDraftOnPageClose()
+ }
+ }, [saveDirtyDraftOnPageClose])
+
const publishDraft = useCallback(async () => {
if (publishInFlightRef.current)
return