In tracker-history.js and tracker-history.es6.js there are several cases where previousSibling is being used and that causes issues with whitespace.

Example: Controller \Drupal\tracker\Controller\TrackerUserTab::getContent

This renders a table with 5 td's per row and the JavaScript in tracker-history.js processes the indicators for new comments like this:

  function processNewRepliesIndicators($placeholders) {
    var placeholdersToUpdate = {};
    $placeholders.each(function (index, placeholder) {
      var timestamp = parseInt(placeholder.getAttribute('data-history-node-last-comment-timestamp'), 10);
      var nodeID = placeholder.previousSibling.previousSibling.getAttribute('data-history-node-id');
      var lastViewTimestamp = Drupal.history.getLastRead(nodeID);

      if (timestamp > lastViewTimestamp) {
        placeholdersToUpdate[nodeID] = placeholder;
      }
    });

    var nodeIDs = Object.keys(placeholdersToUpdate);
    if (nodeIDs.length === 0) {
      return;
    }
    $.ajax({
      url: Drupal.url('comments/render_new_comments_node_links'),
      type: 'POST',
      data: { 'node_ids[]': nodeIDs },
      dataType: 'json',
      success: function success(results) {
        for (var nodeID in results) {
          if (results.hasOwnProperty(nodeID) && placeholdersToUpdate.hasOwnProperty(nodeID)) {
            var url = results[nodeID].first_new_comment_link;
            var text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new');
            $(placeholdersToUpdate[nodeID]).append('<br /><a href="' + url + '">' + text + '</a>');
          }
        }
      }
    });
  }

The 2 instances of previousSibling are returning the wrong td because the first previousSibling returns a text node and not the previous td node. As a result, the nodeID is NULL and then nodeIDs contains one element NULL which causes the ajax to being fired and that causes trouble in the backend.

I guess all instances of previousSibling should be replaced with previousElementSibling to securely avoid that. I'll submit a patch in a second.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jurgenhaas created an issue. See original summary.

jurgenhaas’s picture

Status: Active » Needs review
FileSize
3.82 KB

This patch should fix this and similar problems in the tracker module.

Status: Needs review » Needs work

The last submitted patch, 2: replace_previoussibling-2915993-2.patch, failed testing. View results

jurgenhaas’s picture

Status: Needs work » Needs review
FileSize
3.85 KB

Change path to files.

jurgenhaas’s picture

Title: Replace previousSibling with previousElementSibling in tracker history » Adjust render_new_comments_node_links to fix issues
FileSize
3.81 KB

In addition to the original problem, the tracker is also missing the second parameter "field_name" which is required by the backend handler. The attached patch is including the data attribute during rendering as well as adding it as a POST argument in javascript.

The logic is borrowed from core's CommentLinkBuilder::buildCommentedEntityLinks.

jurgenhaas’s picture

The last submitted patch, 5: replace_previoussibling-2915993-5.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: replace_previoussibling-2915993-6.patch, failed testing. View results

jurgenhaas’s picture

Status: Needs work » Needs review
FileSize
6.22 KB

Properly merge the two patches

Status: Needs review » Needs work

The last submitted patch, 9: adjust-2915993-9.patch, failed testing. View results

jurgenhaas’s picture

Status: Needs work » Needs review
FileSize
7.17 KB

Fix the page builder such that nodes without comment fields will still be listed but with an empty comment cell which won't break the javascript handler.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hanoii’s picture

I needed this too, and this works!!

hanoii’s picture

I just related #2620748: New comments link is not being displayed on activity pages which discussed the field_name among other things. I also modified slightly the table and this fails again. I know this is beyond core in a way but with a small modification it could be done probably more resilient to this kind of things.

I might submit a patch that only focus on the traversing side of the issue and it's probably worth to move the field_name fix/discussion to the other thread which has more attention.

hanoii’s picture

Status: Needs review » Closed (duplicate)

After working on this and the other issue I think this is now a duplicate of #2620748: New comments link is not being displayed on activity pages.

I submitted a patch to #2620748-31: New comments link is not being displayed on activity pages that addresses the same two things you did here, only differently, hopefully with a simpler patch.

The other issue also has more activity and core contributors had chip in, so it's likely to get more attention. The root of the issue is the same.

The patch is for 8.6, but I will soon submit one to 8.5.x as it doesn't apply cleanly.

hanoii’s picture

Please do go to the issue and comment on it, as if that gets accepted or moved forward, you deserve credit too.