recogito / recogito-js

A JavaScript library for text annotation
BSD 3-Clause "New" or "Revised" License
349 stars 38 forks source link

Possible glitch when reloading annotations #104

Closed hbast closed 2 months ago

hbast commented 2 months ago

We want to use recogito as an annotation tool so that several users can annotate a document at the same time. We use the events to interact with a REST API and Django (Python). This works very reliably, but we have a problem with the automatic reload of annotations.

I wrote a function in JS that checks every 5s if there are new annotations in the database and then reloads them using loadAnnotations(). If a user has opened a annotation and the annotations are reloaded from the database in the background, it seems that the position (X,Y) of the annotation is lost during re-rendering and the annotation is re-rendered at a default position.

Is there a way to prevent this from happening? Can I somehow preserve the position of open annotations? Do you know how this is handled in other projects?

rsimon commented 2 months ago

Hi, hm - sounds like something else might go wrong. Because once the annotation is created and the character offsets are stored in the annotation.target, it would re-generate correctly. Are there any errors in the console?

FWIW: if your goal is to guild collaborative realtime annotation, you might want to look into the Text Annotator, the upcoming successor to RecogitoJS. It's built exactly for these use cases in mind. Caveat: it's not very well documented yet. But would probably provide built-in handling of many of the concurrency issues you'd be facing along the road.

rsimon commented 2 months ago

Ah wait - or do you mean the position of the popup (rather than the annotation highlight)? Yes, this might not actually handle the case correctly if you delete or replace and annotation programmatically, if the user has currently opened it.

hbast commented 2 months ago

Sorry that I didn't express myself very clearly. I meant the popup. This will be re-rendered. The actual annotation remains in place. Can the new library handle something like this?

rsimon commented 2 months ago

Well, sort of. The vanilla JS version doesn't have a popup. (Since everyone pretty much ended up building their own popups anyway, I left it out of scope this time.) The React wrapper package has a utility, however, which does essentially handle the case. (Or, more precisely, the way React works means that the popup doesn't fully re-render just because the annotation changes.)

hbast commented 2 months ago

We found a solutions. We swichted to some sort of notification if there are new annotations. The user then can re-load the annotation on his own.