fix: clear uploaded files when clicking clear button in workflow (#29884)

This commit is contained in:
Guangjing Yan 2025-12-22 09:40:01 +08:00 committed by GitHub
parent 6cf71366ba
commit f8ccc75cde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -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<FileStore | undefined>(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 (
<FileContext.Provider value={storeRef.current}>
{children}