diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx index 3356188618..4707c97875 100644 --- a/web/app/components/workflow/index.tsx +++ b/web/app/components/workflow/index.tsx @@ -152,6 +152,7 @@ export const Workflow: FC = memo(({ setShowConfirm, setControlPromptEditorRerenderKey, setSyncWorkflowDraftHash, + setClipboardElements, } = workflowStore.getState() const { handleSyncWorkflowDraft, @@ -178,6 +179,21 @@ export const Workflow: FC = memo(({ } }) + const handleVisibilityChange = useCallback(() => { + if (document.visibilityState === 'visible') { + const storedElements = localStorage.getItem('clipboard_elements') + setClipboardElements(storedElements ? JSON.parse(storedElements) : []) + } + }, [setClipboardElements]) + + useEffect(() => { + document.addEventListener('visibilitychange', handleVisibilityChange) + + return () => { + document.removeEventListener('visibilitychange', handleVisibilityChange) + } + }, []) + useEffect(() => { setAutoFreeze(false) diff --git a/web/app/components/workflow/store/workflow/workflow-slice.ts b/web/app/components/workflow/store/workflow/workflow-slice.ts index 6bb69cdfcd..d034080b52 100644 --- a/web/app/components/workflow/store/workflow/workflow-slice.ts +++ b/web/app/components/workflow/store/workflow/workflow-slice.ts @@ -37,8 +37,14 @@ export type WorkflowSliceShape = { export const createWorkflowSlice: StateCreator = set => ({ workflowRunningData: undefined, setWorkflowRunningData: workflowRunningData => set(() => ({ workflowRunningData })), - clipboardElements: [], - setClipboardElements: clipboardElements => set(() => ({ clipboardElements })), + clipboardElements: (() => { + const storedElements = localStorage.getItem('clipboard_elements') + return storedElements ? JSON.parse(storedElements) : [] + })(), + setClipboardElements: (clipboardElements) => { + set(() => ({ clipboardElements })) + localStorage.setItem('clipboard_elements', JSON.stringify(clipboardElements)) + }, selection: null, setSelection: selection => set(() => ({ selection })), bundleNodeSize: null,