0

The "New" marker above comments does not vanish in my theme. It is basically vanilla Bartik with some tweaks. The marker is hidden by default and inserted via JS according to this comment in comment.html.twig:

Hide the "new" indicator by default, let a piece of JavaScript ask the server which comments are new for the user. Rendering the final "new" indicator here would break the render cache.

This seems to be working as the marker is displayed after loading. The problem is that it is always displayed even on repeated views of the article. I have investigated it for some time now. It appears that the AJAX call to /history/NID/read always returns the current timestamp, not the timestamp of the previous view. Returning the timestamp of the current request does not make a lot of sense to me.

Is my analysis correct so far? Should /history/NID/read return the last instead of the current? If that is true, what could be going wrong here?

Thanks in advance,
Eric

1 Answer 1

2
+100

Trying this out in vanilla Bartik doesnt have issues. I couldn't say for sure without looking at your "modifications". But on digging a little deeper I assume it's one of the following

The reason for your issue is most likely your modifications to node.html.twig(or node--article.html.twig)

  1. You would have rendered 'comments' outside of

    <article{{ attributes}}>
    </article>
    

    in your template.

  2. You would have removed a required attribute "data-history-node-id" from

    <article>
    </article>
    

    tags in your template

Details:

/history/NID/read always returns the current timestamp

The module in question here is the new core 'history' module. The path "/history/NID/read", if you check history.routing.yml, resolves to readNode() in HistoryController In there you can find a call to history_write($node->id()); first and then followed by a call to history_read($node->id()) which would return the current timestamp (because it has just updated it in the previous history_write line)

According to the function description

"Marks a node as read by the current user right now."

so it is used to mark a node as read by the user and not to get a node's last read timestamp.

The new marker logic is at core 'comments' module comments/js/comment-new-indicator.js processCommentNewIndicators() function.

The following line will not return a value

    var $node = $placeholder.closest('[data-history-node-id]');
  • if the $placeholder(marker) was not inside tag with attribute "data-history-node-id"

  • if the article didn't have the attribute "data-history-node-id". Make sure you don't remove it from your node.html.twig (or equivalent)

1
  • Thanks a lot. The comments were moved outside of the acticle element for layout reasons (which is stupid, shame on me). Now the comments are back inside the article and the layout was solved in a different way. Most imporantly the new-indicator is working again. Thanks you, thank you, thank you. Commented Jan 3, 2018 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.