Annotations check for document content is broken

  1. Enable setting “Display annotations by default”
  2. Open a wiki page with context action view (normal mode)
  3. Open any other viewer (information, comments, history)
  4. See warning Annotations could not be loaded because the content is not available.

The warning is coming from initialize function of the Annotation class in the script loaded from /bin/jsx/AnnotationCode/Script.
It is thrown when the class property annotatedElement is not defined. As you can see in the bottom of the file, the Annotation script is initialized with element $('#xwikicontent')[0].

There is a check earlier on:

if (XWiki.contextaction != 'view' || !$('xwikicontent')) {
   return;
}

The return value of $('xwikicontent') is an object of zero or multiple elements by tag “xwikicontent” and therefore never undefined so the AnnotationCode does not notice that it should stop to run.
=> $('#xwikicontent')[0] should be used

Hi!

It seems the issue could not be reproduced on my side on XWiki 18.1.0 and XWiki 17.10.3 (tested on Jetty/HSQL distribution, Chrome 145, @atarata tested as well). The reproduction steps we performed:

  1. Go to Administer Wiki > Content > Annotations
  2. Tick “Display annotations by default” and Save
  3. Go to a page that has some text content (Main Page, Sandbox or a page created by the user) in View Mode
  4. Clicked on Comments, Attachments, History and Information Tabs

Tried also to add some annotations to the text before clicking on the tabs (between Steps 3 and 4), performed some page refreshes / cleared cache.

However, the message Annotations could not be loaded because the content is not available. was encountered indeed, but in the case where a page that is accessed was deleted (see the reported issue: XWIKI-24071).

If there is other (additional info) that leads to reproducing the issue, please add comments on XWIKI-24071.

Thank you!

Hey, I just confirmed the bug on XWiki Docker 18.1.0 and 17.10.3 (Tomcat/PostgreSQL distribution, Firefox 148).

Please make sure to manually clear the cache after saving settings.

  1. Go to Administer Wiki > Content > Annotations
  2. Tick “Display annotations by default” to enable
  3. Save settings
  4. Clear cache for the new setting to apply (the annotation code is cached poorly - in Firefox the cache can be cleared using the shortcut Ctrl+Shift+R)
  5. Go to Sandbox page in view mode
  6. Open the dropdown menu in the top right of the wiki page header
  7. Open information viewer

Can you reproduce this?

The encountered message will display on any page that is opened in view mode but has no #xwikicontent container (includes deleted pages, information viewer, comments viewer and more).

The issue likely is that the initial check for the page content container is broken (xwiki-platform/xwiki-platform-core/xwiki-platform-annotation/xwiki-platform-annotation-ui/src/main/resources/AnnotationCode/Script.xml at e1355827a6a05ff733e8cbe23dc2596ffb0ec564 · xwiki/xwiki-platform · GitHub).

Hi!

Yes, I can reproduce the issue using the steps you provided. I added a comment on XWIKI-24071.

Thank you!