31

For some reason, when I click on either an answer, or any comment under an answer, the answer disappears briefly (on mouse up) (actually it looks like it reloads the answer). This seems relatively new. For example (the yellow circle indicates a mouse click):

The answer text and the avatar/username disappear when clicking on it or a comment

It also happens with questions.

As a side note: When a post is in this state, it is no longer possible to use the "share" link, as it disappears as soon as you click it to copy the link. It also messes up the "close" dialog on questions.

This is on Chrome 52.0.2743.116, Windows 7.

14

The below suggested changes are now live, the bug is fixed


The bug, as expected, is in stackoverflow\content\js\realtime-se.js (included in the full.en.js bundle). Specifically, the problem is in the function postEdit(), which is called when a realtime WebSocket post-edit event is received:

function postEdit(post) {
    var div = $('.question[data-questionid=' + post.id + '], .answer[data-answerid=' + post.id + ']');
    var notificationDiv = $('<div class="new-post-activity" data-postid="' + post.id + '>').append($('<a href="#">').text("an edit has been made to this post; click to load"));

    if (div.find('.new-post-activity[data-postid=' + post.id + ']').length > 0) return;
    var func = function () {
        $('.new-post-activity[data-postid=' + post.id + ']').remove();
        if ($('#review-content').length == 0) {
            $.get("/posts/ajax-load-realtime/{postIdsSemiColonDelimited}?title=true".formatUnicorn({ postIdsSemiColonDelimited: post.id }), refreshPost(div.find('.postcell, .answercell'), post));
        }
        $(document).trigger('refreshEdit', post.id);
    };
    div.click(func);
    div.prepend(notificationDiv.find('a').click(function (e) {
        e.stopPropagation();
        func();
        return false;
    }));
}

The line div.click(func); sets up a click handler on the entire post div that reloads the post content using $.get(). Now, one might naïvely expect that reloading the entire post would also wipe out the click handler as a side effect, but this doesn't happen, because the callback function returned by refreshPost() doesn't actually replace the entire post div with the Ajax result, but rather just cherry-picks specific elements from the Ajax result to replace.

Earlier, where the click handler was only set on the "click to load" banner itself, the line:

$('.new-post-activity[data-postid=' + post.id + ']').remove();

inside the func callback worked fine to remove the entire banner. Now that the click handler is also added to the entire post div, however, that's not sufficient. A simple fix would be to add the following line just after the previously quoted one:

div.off('click', func);

This should take care of removing the click handler once it's no longer needed.


Ps. That same function contains a number of other bugs, too:

  • The notificationDiv creation fails, because the HTML is missing a double quote: the expression post.id + '>' should read post.id + '">'. Thus, the notification about new edits is never actually shown to the user.

  • Fixing the previous bug would reveal a new one — the notification box is not correctly prepended to the post, causing it to be mis-styled and not to get removed when clicked. To fix this, the expression:

    div.prepend(notificationDiv.find('a').click(function (e) { ... }));
    

    at the end of the code should be replaced with:

    notificationDiv.prependTo(div).find('a').click(function (e) { ... });
    

It might also be desirable to only remove the notification and the click handler when the Ajax call completes successfully, rather than when it's started. Doing this would require slightly more extensive changes to the code, though.

  • 7
    Pps. If this is not fixed by SE soon, expect an unofficial fix in the next release of SOUP. It's really pretty trivial, once you know the cause. – Ilmari Karonen Sep 2 '16 at 17:04
  • 2
    Thank you very much! I made these changes (they are live now). I think removing the notification on start is OK since that's when the reloading starts. – Michael Stum Sep 2 '16 at 19:38
  • 2
    @MichaelStum now give Ilmari a diamond and access to SE code base. ;) – Shadow Wizard Sep 2 '16 at 20:08
  • @ShadowWizard stackoverflow.com/company/work-here :) – Michael Stum Sep 2 '16 at 20:09
  • @MichaelStum so basically, "blame Marc" :) – Marc Gravell Sep 2 '16 at 21:06
  • 1
    @MichaelStum: Could you also take a look at the patch I posted for this related bug? – Ilmari Karonen Oct 3 '16 at 19:51
11

Happens to me as well. JB Nizet reported it on MSO and it happens with questions, too. Apparently rene figured out how to replicate it and posted the steps in a comment:

  • Load any question page, for example: https://meta.stackoverflow.com/a/332200
  • Let someone else do an edit on that post
  • Once the websocket message action: "552-question-331817", data: "{"a":"post-edit","id":332200,"acctid":927180}"} is received by you, the post will flicker when clicked.

That continues until you reload the page.

Looks like JB's post is getting more attention than this one, let's nag over there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .