27

Yes the title isn't very clear but here is the steps to reproduce the issue:

  1. You are in a question page where a post (either the question or an answer) contain a snippet
  2. An edit is made to the post and you get the notification on the top to refresh the post
  3. If you click you get the edited post and the button to run the snippet disappear. You are obliged to refresh the page which is annoying if you are writing an answer.

Here is a screenshot of a recent post after I refreshed the post:

enter image description here

another one on a question

enter image description here

There is no error in the console and I am running Chrome (Version 76.0.3809.100 (64 bits)) on windows 8.1. I have the same issue using last version of Firefox.

The same is also happening on meta. Use the below answer to test.

Apart from snippets, a similar problem is that code syntax highlighting doesn't work when refreshing an edit either, as described here.

3
  • 3
    Oh damn it! I thought it was only an issue on my end. I've had some issues with various websites on my machine due to some combination of addons, settings, firewall, and network stuff. Wo when I saw this happening recently, I didn't actually verify if it was me or SO. Moreover, I had seen that happen before - I saw it for the first time few weeks back but it went away quickly.
    – VLAZ
    Commented Aug 15, 2019 at 6:27
  • The first few times this happened to me, I assumed the edit had turned the snippet back into an ordinary code block, but the edit history showed this wasn't the case.
    – Barmar
    Commented Sep 6, 2019 at 10:07
  • 1
    Meta SE post Commented Oct 8, 2019 at 1:42

2 Answers 2

6

As posted on MSE:

The Problem

In full.en.js, the function that adds syntax highlighting and snippet controls to posts (which is called styleCode, located on window) does not get called after an edit finishes. So, when the post is refreshed, the post body HTML gets replaced, but the snippet buttons are not re-created, and non-snippet code blocks do not receive syntax highlighting either.

The Solution

Stack Exchange can fix this by editing realtime-se.js so that the postEdit function calls styleCode after calling reloadPosts: Change

reloadPosts([post.id]);

to

reloadPosts([post.id]).then(styleCode);

(or do something else that eventually calls styleCode)

In the meantime, if you find it annoying, us users can fix it with this userscript that manually calls styleCode when a post is refreshed.

2

This a test answer to reproduce the issue. Keep this tab open, then ask someone else to edit this post. When the edit notification appears, click on it, and you'll see that the snippet buttons don't appear.

(Editing the answer yourself in a different tab / browser won't reproduce the issue, because Stack Exchange will not show the option to reload the post if you were the one that made the edit - see if (payload.acctid == StackExchange.options.user.accountId) return; in full.en.js)

Snippet example:

body {
 background: red; /* <-- let's change the color */
}

Non-snippet syntax highlighting example:

const foo = function() {
  console.log('bar');
};
2
  • 1
    Thanks for that edit, I was trying out a fix and it worked Commented Dec 22, 2019 at 0:16
  • 1
    @CertainPerformance I suppose a userscript is coming shortly? :) Commented Dec 22, 2019 at 0:31

You must log in to answer this question.

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