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.
Comment | File | Size | Author |
---|---|---|---|
#11 | adjust-2915993-11.patch | 7.17 KB | jurgenhaas |
Comments
Comment #2
jurgenhaasThis patch should fix this and similar problems in the tracker module.
Comment #4
jurgenhaasChange path to files.
Comment #5
jurgenhaasIn 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.
Comment #6
jurgenhaasPatch syntax fix
Comment #9
jurgenhaasProperly merge the two patches
Comment #11
jurgenhaasFix 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.
Comment #13
hanoiiI needed this too, and this works!!
Comment #14
hanoiiI 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.
Comment #15
hanoiiAfter 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.
Comment #16
hanoiiPlease do go to the issue and comment on it, as if that gets accepted or moved forward, you deserve credit too.