12

If you are looking at an answer with a code snippet in it, and the answerer updates the answer, you see An edit has been made (etc.). If you click that, the answer is refreshed, but the code snippet buttons (Run, Copy, and Expand) go missing.

The code snippet buttons are there again after reloading the entire page.

Answer has been edited:

image

After clicking to reload it:

image

Similarly, non-snippet code blocks do not receive syntax highlighting after an edit, as described here, which refers to here as a related or root cause.

(Browser: Chrome v77 - OS: Windows 10 Pro x64)

1

1 Answer 1

3

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.

You must log in to answer this question.

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