Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Other users discussion comments not displayed until manual page refresh

edited May 2018 in Vanilla 2.0 - 2.8

The forum I run sometimes has fast moving threads (covering live sport events), and a frequent scenario we have is a user may post several consecutive posts within the same discussion, but other user's post during that time period are not displayed. A manual page refresh is required to see other user's comments.

Is there a setting I can enable to refresh the page (so any new comments from other users appear) on each new discussion comment? Would this cause a big hit to performance?

Thanks again for any assistance!



  • edited May 2018

    @R_J So I found this plugin it appears you authored back in 2014:

    I installed it and enabled it, but it does not appear to refresh the page when I post a new comment.

  • R_JR_J Ex-Fanboy Munich Admin

    I'll be slightly handicapped for the next one or two months so writing isn't easy. I can try to look at it but whenever JavaScript is involved, I have to admit that I'm not happy to work on it.

  • @R_J understood!

    I'm poking around myself.. the javascript function does not get called, in dev tools console I see this error:

    TypeError: $(...).livequery is not a function[Learn More]

    Googling around looks like livequery is deprecated. I changed the jQuery to .on('click',function().... and now at least code gets called when clicking the post comment button..

    still not doing the refresh.. i'll keep poking around at that to see if i can figure it out

  • Also had to make modification to get latest comment ID in the javascript.. changed to this which seems to work:

    lastCommentID = document.getElementById('latest');

    provides me with a value of something like: Comment_239

    So I've got it where it's getting right values for the ajax params.. (LastCommentID, DiscussionID, and Page#) these are all correct verified by console.log statements..

    Now the AJAX post to url: gdn.url('/discussion/discussionrefresh/' + discussionID + '/' + lastCommentID + '/' + page), is returning an error

    {"readyState":4,"responseText":"<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"\">\n<html xmlns=\"\" xml:lang=\"en\">\n<head>\n <title>Something has gone wrong.</title>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"/applications/dashboard/design/error.css\" /></head>\n<body>\n<div id=\"Content\">\n <div class=\"SplashInfo\">\n <h1>Something has gone wrong.</h1>\n\n <p>\n We've run into a problem and are unable to handle this request right now.\n <br/>Please check back in a little while.\n </p>\n </div>\n</div>\n</body>\n</html>\n","status":256,"statusText":"No Reason Phrase"}

    Headed out to church now so I have to stop.. let me know if you've got any ideas. I'll come back and poke at it some more when I get time.

  • @R_J Yeah looks I'm probably going to be at your mercy for now. I'm stuck at the GET of /discussion/discussionrefresh/[discussionID]/[lastCommentID]/[page] as it returns 500 error.

    Do you know is this discussionrefresh api described somewhere? I don't see it in the swagger api provided with core. What provides it? The plugin or is it in core?

  • @Linc just fyi I have also opened an issue on Github as this seems like it should be fixed at core level as it seems to be a true defect. See

    Would be forever grateful to get a resolution to this before football season kicks off and the live game threads on my site start up! Anyhow, appreciate yalls work.

  • LincLinc Detroit Admin

    The page asynchronously adding comments isn’t a current feature. We used to have it in core as an option, but it was a scaling issue so we removed it until such time as we can reapproach it.

    There are a lot of design decisions to be made to create this feature in a scalable, user-friendly way.

  • edited May 2018

    @Linc thinking out loud here.. possible solution would be each time "Post Comment" button is clicked to then query database for last comment id # of that discussion and compare that with comment id# of the last comment <li> tag of the discussions page. If the difference is greater than 1 then someone else has posted and the entire discussion page can then be refreshed automatically to show other comments.

    This I think would prevent page refresh with every post comment unless it is needed (at the expense of an additional database lookup).

    Also, being able to turn this feature on and off would likely be useful. Toggling this feature at the thread level would be ideal for me as I am able to predict which threads will encounter this issue, but admittedly my case may be fringe case..

  • R_JR_J Ex-Fanboy Munich Admin

    @PackFansNation: I cannot write that much, but I can still read! =)

    From looking at the plugin I can see that at least the livequery is a problem:
    I'm not really fluent in JavaScript but it might be possible that already replacing livequery with on might be enough. Simply try that :wink:

    Using /discussion/discussionrefresh/[discussionID]/[lastCommentID]/[page] is only possible when the plugin is enabled since that end point is created by the plugin.

    The plugin fetches the "LastCOmmentID" from the page (search the source of e.g this page to see what I mean) and then queries for newer comments in this discussion. If there are some, they are returned and inserted.

    If you want to use the API, you would have to replace all comments of this page since the API only allows fetching comments by discussion and page, not all comments of a discussion newer than a given CommentID. But as I said: it could also be done with the API and since "page" calls of comments to the database are queries, it might make more sense. Not sure if formatting might be a problem, though.

  • @R_J livequery did indeed need to be changed to on method.

    There is one comment above that I forgot to tag you in that you may have missed.

    I don't see any elements on this page with an ID of LastCommentID.. I had to improvise a bit as I posted in that missed comment. Still not having luck with the GET rest api.

    Off topic a bit, but good for learning, I'm totally confused how the plugin is creating this GET rest api /discussion/discussionrefresh/[discussionID]/[lastCommentID]/[page] (it does seem like it's enabled as now I get a 256 return code.. but not returning what is expected). I only see js and class.discussionrefresh.plugin.php files in the plugin with no obvious code that enables it.

  • R_JR_J Ex-Fanboy Munich Admin

    That line in my plugin creates the end point:
    public function discussionController_discussionRefresh_create($Sender, $Args) {

    It is documented here:

    The element with the LastCommentID ID seems to be gone, you are correct. There is a span#latest inside the comment list element which is quite idiotic because you cannot simply select the latest comment based on that- But with a little JavaScript you can do it as you have shown above

  • R_JR_J Ex-Fanboy Munich Admin

    Without testing anything I will not be able to support you much, sorry. But there is one obvious problem that I've spotted:

    WriteComment($Comment, $this, $Session, $ItemCount);

    The $this must be replaced with $Sender

  • LincLinc Detroit Admin

    The scaling issue is two parts: The frequency of polling (requests) and the database query required (as you described it) because it doesn’t line up with how we cache. Your spitball addresses one of those, and I’m not convinced only refreshing AFTER posting is a good experience.

  • R_JR_J Ex-Fanboy Munich Admin

    This is not the first discussion on this topic (and it will most probably not be the last):

    There are two intersting points in there, @Linc
    1. caching a complete page is fast
    2. you like the feature :awesome:

    I don't know if back then you had the time to discuss it with @Todd but now it is more than 4 years later and it would be great if at least you could have a talk at that topic again.

    Since I like to post readable content, I use the preview feature. And since I want to see if my answer still makes sense, I like to answer to the most recent comment. Therefore I do
    1. click on [Preview]
    2. click on [Save Draft]
    3. hit [F5] to reload the page
    4. and finish that with a click n [Post Comment]

    And sometimes, when a discussion is "hot" I reload the page directly after posting to make sure that I do not miss a post.

    Sometimes I witch between browser tabs and refresh the discussion index to make sure that nothing has happened while I was typing a comment.

    If a page load is not too costly, I would love to see the following mechanism:

    • Form_Comment should be filled with a LastCommentID
    • so that on POST this ID gets sent to the server (via AJAX as it is already now)
    • new comment is saved as normal
    • but instead of loading that one comment, all comments of current page are loaded
    • only comments > LastCommentID will be returned and inserted into the page
    • LastCommentID in the Form_Comment must certainly be adopted

    The only "problem" for the user would be if he is writing slowly and his comment is the Maximum.Comments.PerPage +1 so that hiscomment will be the first on a new page. He would have to look at the previous page to make sure he hasn't missed anything, but that's the only user experience drawback. Compared to what users like me have to do nowadys, that would be paradise... :wink:

  • edited May 2018

    Just want to echo @R_J comments. In my setup users already encountering this on "hot threads" and received a issue reported of not seeing other's posts.

    R_J: I'm very close to having your old discussionrefresh plugin working again (learning tons), but loaded comments are showing "Unknown" for the user and "-" for the content.. see screen cap.

    Here is a link to sample of the html returned by the json object's UnreadComments property received by the js file ->

    So I'm still tinkering trying to figure out why it's not getting the username, comment content, and comment id is also missing in the returned html.. I realize you are busy, but if this jogs your brain for any thoughts or advice as to what's going let me know!

    Changes required thus far:
    -change livequery() to on('click')
    -get lastCommentID from last <li> comment tag's id attribute and then parse it to get the integer value

    var lastCommentID = document.querySelector("ul.Comments");
    lastCommentID = lastCommentID.substring(lastCommentID.indexOf("_") + 1);

    -update WriteComment function as you suggsted to now use $Sender
    WriteComment($Comment, $Sender, $Session, $ItemCount);

  • To offer one more thought, I feel like I could get this mostly working with the way I'm implementing, but with the lastCommentID hack I'm using I think it may be prone to bugs for the 1st comment, or when comments overflow to new pages.. an eventual well designed solution in core as R_J suggests would certainly be the way to go.

  • LincLinc Detroit Admin

    @R_J said:
    2. you like the feature :awesome:

    If that was the only criteria for something being in Vanilla we'd have a very different product, lol.

    @R_J said:
    If a page load is not too costly, I would love to see the following mechanism:

    So, this is the easy part of the problem. What's left is the messy work of designing the final workflow and scaling accommodations.

    @R_J said:
    The only "problem" for the user would be if he is writing slowly and his comment is the Maximum.Comments.PerPage +1 so that hiscomment will be the first on a new page.

    It's even messier than that. What if they were already going to be a new page anyway? Or, what if a whole additional page gets authored in the interim? What if they write their comment, then refresh the page after all that - redirect? What if someone splits or merges a discussion as you're commenting? If you're doing asynchronous new comments, what about asynchronously loading edits during the timeout window?

    We're way beyond the product stage where we can build half a feature and hope it's good enough for now. Vanilla in 2018 is "do it well, or don't touch it" because the costs have steeply risen for doing partial work.

  • edited May 2018

    @Linc if this isn't something that can't be fixed then Vanilla isn't a viable solution for the type of forum I need that contains "hot" threads where the design allows others' comments to be completely missed. We're already seeing issues in our "slower" baseball threads.. Most other forum software that I'm aware of does not have this problem.

    If this is a "no plans to fix" issue I'd like to know about it sooner rather than later if possible so I can move on.

  • edited May 2018

    It's even messier than that. What if they were already going to be a new page anyway? Or, what if a whole additional page gets authored in the interim? What if they write their comment, then refresh the page after all that - redirect? What if someone splits or merges a discussion as you're commenting? If you're doing asynchronous new comments, what about asynchronously loading edits during the timeout window?

    How does other forum software handle it? In other softwares it appears a page refresh is done after clicking "Post Comment" button.

    I tinkered with R_J's plugin a bit to do this, using location.reload() javascript call. It seem to work okay except the notifications I received popped up with a bunch of junk in it after the page reloaded.

    Also the page reload can be selectively issued if detected new comments. Not sure which is better performance-wise, to just full page reload after every "Post Comment" click or to only reload selectively.

  • edited May 2018

    @R_J @Linc I was able to create a plugin (using R_J's discussionRefresh as a guide) that suites my needs and have uploaded it to the addons database ->

    With this addon enabled, clicking the "Post Comment" button will post the comment as usual, but will then check to see if there are any new additional comments in the thread from other users since the last time the page was loaded. If new comments are detected only then will the discussion page be reloaded to reveal the new comments from other users.

    I'm going to have it enabled on my site and will keep an eye on it to see how it performs. Initial testing has been promising. Open to any code review comments if you get bored :p

Sign In or Register to comment.