@@ -194,6 +194,13 @@ function ForwardAnnotator(
194194 // remember last tool
195195 const memorizeToolLabel = useRef < Record < ToolName , Attribute > > ( { } as Record < ToolName , Attribute > ) ;
196196 const [ attributeModalOpen , setAttributeModalOpen ] = useState < boolean > ( false ) ;
197+ const isPreAnnotationEmpty = useMemo ( ( ) => {
198+ if ( typeof preAnnotations === 'undefined' ) {
199+ return true ;
200+ }
201+
202+ return Object . values ( preAnnotations ) . every ( ( item ) => item . length === 0 ) ;
203+ } , [ preAnnotations ] ) ;
197204
198205 useEffect ( ( ) => {
199206 setCurrentSample ( editingSample || samples ?. [ 0 ] ) ;
@@ -340,7 +347,7 @@ function ForwardAnnotator(
340347 }
341348 } ) ;
342349
343- if ( preAnnotations ) {
350+ if ( ! isPreAnnotationEmpty ) {
344351 Object . keys ( preAnnotations ?? { } ) . forEach ( ( key ) => {
345352 if ( TOOL_NAMES . includes ( key as ToolName ) ) {
346353 engine ?. loadData (
@@ -356,7 +363,7 @@ function ForwardAnnotator(
356363 }
357364 } ) ;
358365 // eslint-disable-next-line react-hooks/exhaustive-deps
359- } , [ annotationsFromSample , config , currentSample , engine , preAnnotations , tools ] ) ;
366+ } , [ annotationsFromSample , config , currentSample , engine , preAnnotations , tools , isPreAnnotationEmpty ] ) ;
360367
361368 const selectedIndexRef = useRef < number > ( - 1 ) ;
362369
@@ -388,7 +395,7 @@ function ForwardAnnotator(
388395 const _data = currentSample ?. data ?? { } ;
389396 const _preData = preAnnotations ?? { } ;
390397
391- if ( preAnnotations ) {
398+ if ( ! isPreAnnotationEmpty ) {
392399 Object . keys ( _preData ) . forEach ( ( key ) => {
393400 _preData [ key as AllAnnotationType ] ?. forEach ( ( item ) => {
394401 mapping [ item . id ] = {
@@ -409,7 +416,7 @@ function ForwardAnnotator(
409416 } ) ;
410417
411418 return mapping ;
412- } , [ currentSample ?. data , preAnnotations ] ) ;
419+ } , [ currentSample ?. data , isPreAnnotationEmpty , preAnnotations ] ) ;
413420
414421 const [ annotationsWithGlobal , updateAnnotationsWithGlobal , redo , undo , pastRef , futureRef , reset ] =
415422 useRedoUndo < AllAnnotationMapping > ( annotationsMapping , {
0 commit comments