From f8ccc75cdef3d9750e35e1cc05109a91d1c99d9e Mon Sep 17 00:00:00 2001 From: Guangjing Yan <125958391+GuangjingYan@users.noreply.github.com> Date: Mon, 22 Dec 2025 09:40:01 +0800 Subject: [PATCH] fix: clear uploaded files when clicking clear button in workflow (#29884) --- web/app/components/base/file-uploader/store.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/app/components/base/file-uploader/store.tsx b/web/app/components/base/file-uploader/store.tsx index cddfdf6f27..917e5fc646 100644 --- a/web/app/components/base/file-uploader/store.tsx +++ b/web/app/components/base/file-uploader/store.tsx @@ -1,6 +1,7 @@ import { createContext, useContext, + useEffect, useRef, } from 'react' import { @@ -10,6 +11,7 @@ import { import type { FileEntity, } from './types' +import { isEqual } from 'lodash-es' type Shape = { files: FileEntity[] @@ -55,10 +57,20 @@ export const FileContextProvider = ({ onChange, }: FileProviderProps) => { const storeRef = useRef(undefined) - if (!storeRef.current) storeRef.current = createFileStore(value, onChange) + useEffect(() => { + if (!storeRef.current) + return + if (isEqual(value, storeRef.current.getState().files)) + return + + storeRef.current.setState({ + files: value ? [...value] : [], + }) + }, [value]) + return ( {children}