You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First I got multiple mentions from users that files had been uploaded multiple times (one to about 6 times, varying). But I couldn't provoke it myself.
Today I happened to see it while developing: onFileUploadSuccess was called two times while uploading a single file. Both times returning the same info.uuid. Unfortunately I forgot to make a screenshot.
So I had to implement catching duplicates, see infoUuidsProcessed in the code below.
Sorry I can't build a reproducable example. So feel free to close this issue. I simply wanted to document it.
Expected behavior
onFileUploadSuccess should only occur once per file uploaded.
Code / screenshots
This is my component:
import{useCallback,useState,useRef,useContext,memo,useMemo,Suspense,}from'react'import{observer}from'mobx-react-lite'import{useApolloClient,useQuery,gql}from'@apollo/client'importstyledfrom'@emotion/styled'importupperFirstfrom'lodash/upperFirst'importButtonfrom'@mui/material/Button'importIconButtonfrom'@mui/material/IconButton'importSimpleBarfrom'simplebar-react'import{FaPlus,FaMinus,FaEye,FaEyeSlash,FaChevronLeft,FaChevronRight,}from'react-icons/fa6'import{useNavigate,useLocation,Outlet,useParams}from'react-router-dom'import'./index.css'import{ErrorBoundary}from'../ErrorBoundary.jsx'import{Error}from'../Error'import{Spinner}from'../Spinner'import{MenuBar}from'../MenuBar/index.jsx'import{apFileasapFileFragment,idealbiotopFileasidealbiotopFileFragment,popFileaspopFileFragment,tpopFileastpopFileFragment,tpopkontrFileastpopkontrFileFragment,tpopmassnFileastpopmassnFileFragment,}from'../fragments'import{Uploader}from'../Uploader/index.jsx'import{UploaderContext}from'../../../UploaderContext.js'import{File}from'./Files/File.jsx'import{isImageFile}from'./isImageFile.js'import{StoreContext}from'../../../storeContext.js'import{icon}from'leaflet'constContainer=styled.div` flex-grow: 1; display: flex; flex-direction: column;`constOutletContainer=styled.div` flex-grow: 1;`constfragmentObject={ap: apFileFragment,idealbiotop: idealbiotopFileFragment,pop: popFileFragment,tpop: tpopFileFragment,tpopkontr: tpopkontrFileFragment,tpopmassn: tpopmassnFileFragment,}exportconstFilesRouter=memo(observer(({ parentId ='99999999-9999-9999-9999-999999999999', parent })=>{conststore=useContext(StoreContext)const{ fileId }=useParams()constnavigate=useNavigate()const{ pathname }=useLocation()constisPreview=pathname.endsWith('Vorschau')constclient=useApolloClient()constuploaderCtx=useContext(UploaderContext)constapi=uploaderCtx?.current?.getAPI?.()constinfoUuidsProcessed=useRef([])constcontainerRef=useRef(null)constqueryName=`all${upperFirst(parent)}Files`constparentIdName=`${parent}Id`constfields=`${upperFirst(parent)}FileFields`constfragment=fragmentObject[parent]constquery=gql` query FileQuery($parentId: UUID!) {${queryName}( orderBy: NAME_ASC filter: { ${parentIdName}: { equalTo: $parentId } } ) { nodes { ...${fields} } } }${fragment} `const{ data, error, loading, refetch }=useQuery(query,{variables: { parentId },})constfiles=data?.[`all${upperFirst(parent)}Files`].nodes??[]constonCommonUploadSuccess=useCallback(async(info)=>{// reset infiUuidsProcessedinfoUuidsProcessed.current=[]// close the uploader or it will be open when navigating to the listapi?.doneFlow?.()// clear the uploader or it will show the last uploaded file when opened next timeapi?.removeAllFiles?.()// somehow this needs to be delayed or sometimes not all files will be uploadedsetTimeout(()=>refetch(),500)},[client,fields,fragment,parent,parentId,refetch],)// ISSUE: sometimes this is called multiple times with the same info.uuidconstonFileUploadSuccess=useCallback(async(info)=>{if(info){if(infoUuidsProcessed.current.includes(info.uuid))returninfoUuidsProcessed.current.push(info.uuid)letresponcetry{responce=awaitclient.mutate({mutation: gql` mutation insertFile { create${upperFirst(parent)}File( input: {${parent}File: { fileId: "${info.uuid}", fileMimeType: "${info.mimeType}",${parent}Id: "${parentId}", name: "${info.name}" } } ) {${parent}File { ...${fields} } } }${fragment} `,})}catch(error){console.log(error)store.enqueNotification({message: error.message,options: {variant: 'error',},})}console.log('FilesRouter.onFileUploadSuccess',{ info, responce })}},[client,fields,fragment,parent,parentId,refetch],)constonFileUploadFailed=useCallback((error)=>{console.error('Upload failed:',error)store.enqueNotification({message: error?.message??'Upload fehlgeschlagen',options: {variant: 'error',},})// close the uploader or it will be open when navigating to the listapi?.doneFlow?.()// clear the uploader or it will show the last uploaded file when opened next timeapi?.removeAllFiles?.()// somehow this needs to be delayed or sometimes not all files will be uploadedsetTimeout(()=>refetch(),500)},[])constfirstFileId=files?.[0]?.fileIdconstonClickPreview=useCallback(()=>navigate(`${firstFileId}/Vorschau`),[firstFileId],)constonClickClosePreview=useCallback(()=>{// relative navigation using ../.. does not work hereconstfileIdBeginsAt=pathname.indexOf(fileId)constnewPathname=pathname.slice(0,fileIdBeginsAt)navigate(newPathname)},[pathname,fileId])constmenus=useMemo(()=>[<IconButtonkey="vorschau_oeffnen"title="Vorschau öffnen"onClick={onClickPreview}><FaEye/></IconButton>,<IconButtonkey="dateien_hochladen"title="Dateien hochladen"onClick={api?.initFlow}><FaPlus/></IconButton>,],[onClickPreview],)constpreviewMenus=useMemo(()=>[<IconButtonkey="vorschau_schliessen"title="Vorschau schliessen"onClick={onClickClosePreview}><FaEyeSlash/></IconButton>,<IconButtonkey="dateien_hochladen"title="Dateien hochladen"onClick={api?.initFlow}><FaPlus/></IconButton>,<IconButtonkey="loeschen"title="löschen"onClick={()=>{console.log('TODO: delete. How to know which file?')}}><FaMinus/></IconButton>,<IconButtonkey="vorige_datei"title="vorige Datei"onClick={()=>{console.log('TODO: navigate. How to know which file?')}}><FaChevronLeft/></IconButton>,<IconButtonkey="naechste_datei"title="nächste Datei"onClick={()=>{console.log('TODO: navigate. How to know which file?')}}><FaChevronRight/></IconButton>,],[onClickClosePreview],)if(loading)return<Spinner/>if(error)return<Errorerror={error}/>return(<ErrorBoundary><Containerref={containerRef}><UploaderonFileUploadSuccess={onFileUploadSuccess}onFileUploadFailed={onFileUploadFailed}onCommonUploadSuccess={onCommonUploadSuccess}/><MenuBar>{isPreview ? previewMenus : menus}</MenuBar><OutletContainer><Suspensefallback={<Spinner/>}><Outletcontext={{ files, parent, parentId, refetch, containerRef }}/></Suspense></OutletContainer></Container></ErrorBoundary>)}),)
I have the same problem but with fileValidators, it is called multiple times, when you upload a file locally, it goes through the function 4 times.
and when I upload another file the second one, it happens 6 times.
and shows the previous file and then the current one. this breaks all my validation
Describe the bug
First I got multiple mentions from users that files had been uploaded multiple times (one to about 6 times, varying). But I couldn't provoke it myself.
Today I happened to see it while developing:
onFileUploadSuccess
was called two times while uploading a single file. Both times returning the same info.uuid. Unfortunately I forgot to make a screenshot.So I had to implement catching duplicates, see
infoUuidsProcessed
in the code below.Sorry I can't build a reproducable example. So feel free to close this issue. I simply wanted to document it.
Expected behavior
onFileUploadSuccess
should only occur once per file uploaded.Code / screenshots
This is my component:
Environment
The text was updated successfully, but these errors were encountered: