WebViewer Version: 8.2.0
Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? Yes
Please give a brief summary of your issue:
The annotationManager.exportAnnotCommand() function removed the xfdf of a parent annotation but the child annotations still remain, causing a null issue when using annotManager.getAnnotationById(annotation.InReplyTo)
Please describe your issue and provide steps to reproduce it:
I am unsure of how my user has done it, but through a series of actions in webviewer, he has made it so that the annotationManager.exportAnnotCommand() generated xfdf that did not include a parent annotation. Initially this is fine and I assumed the user meant to delete that annotation, but the problem is upon realizing that the parent annotation’s children wasn’t deleted. I assume they are children of the parent annotation because they have inreplyto
fields that point to the deleted annotation’s name
. I also assume that child annotations are also deleted when the parent is.
This caused an issue in other parts of our system because there I iterate through a given file’s annotations for display purposes and the code I use there assume that if an annotation has an inreplyto
field, it points to a valid and existing annotation.
Please see below the firebase backup of one of our files that have this problem:
s32-prod-fb-Review-SPMMLS32-1246-18478-export-for-apryse.json (144.1 KB)
The Id/Name of the annotation that is missing is
06652318-7ed1-5445-71e9-40a44890cb71
Upon looking at our logs, I managed to find the latest xfdf of the parent annotation before and after it got overwritten:
parent-annotation-before.xml (8.3 KB)
parent-annotation-after.xml (1.9 KB)
You will see that in the “before” file, the annotation with Id
06652318-7ed1-5445-71e9-40a44890cb71
is there, while in the “after” file, it is gone. Meanwhile, the other annotations in the “after” file point to the now missing annotation and even after looking for it in the firebase backup, it cannot be found.
(The key is there but looking at the xfdf value of that key, none of the annotations there have a name
value of 06652318-7ed1-5445-71e9-40a44890cb71
)
The code below shows how we handle webviewer annotation events.
Our code is based on PDFTron’s realtime collaboration code that uses firebase.
annotManager.addEventListener('annotationChanged', async (annotations, type, { imported }) => {
if (imported)
return;
try {
const xfdf = await annotManager.exportAnnotCommand();
const processAnnotations = async () => {
for (var i = 0; i < annotations.length; i++) {
let annotation = annotations[i];
if (type === 'add') {
let parentAuthorId = null;
if (annotation.InReplyTo) {
parentAuthorId = annotManager.getAnnotationById(annotation.InReplyTo).authorId || 'default';
}
if (authorId) {
annotation.authorId = authorId;
annotation.setCustomData('userId', authorId);
}
let result = await server.createAnnotation(annotation.Id, {
authorId: authorId,
parentAuthorId: parentAuthorId,
xfdf: xfdf
});
} else if (type === 'modify') {
let parentAuthorId = null;
if (!adminMode) {
if (authorId != annotation.authorId)
return;
}
if (annotation.InReplyTo) {
parentAuthorId = annotManager.getAnnotationById(annotation.InReplyTo).authorId || 'default';
}
let result = await server.updateAnnotation(annotation.Id, {
authorId: annotation.authorId,
parentAuthorId: parentAuthorId,
xfdf: xfdf
});
The code that causes an exception is in another part of the system but basically it calls
annotManager.getAnnotationById(annotation.InReplyTo)
and returns null, which I was not expecting to happen.
My questions are:
1.) Isn’t it supposed to be impossible for a parent annotation to not exist while there are still child annotations existing?
2.) Is this an issue on PDFTron webviewer? Or an issue on our side?
Please provide a link to a minimal sample where the issue is reproducible: N/A