Hugo live reload constantly keeps reloading

Hugo live reload constantly keeps reloading

Table of Contents

Introduction

One of the nice features of Hugo is the live reload feature. When running Hugo locally, this automatically reloads the page when you make changes to the content or the theme. It means I get instant feedback for the changes I’m making. However, I have run into an issue from time to time where Hugo’s live reload feature keeps reloading the page:

Change detected, rebuilding site (#92).
2024-05-18 13:18:44.070 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 3073 ms

Change detected, rebuilding site (#93).
2024-05-18 13:18:52.924 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2820 ms

Change detected, rebuilding site (#94).
2024-05-18 13:18:58.492 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2724 ms

Change detected, rebuilding site (#95).
2024-05-18 13:19:04.148 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2869 ms

Change detected, rebuilding site (#96).
2024-05-18 13:19:07.019 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 3050 ms

Change detected, rebuilding site (#97).
2024-05-18 13:19:15.904 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2549 ms

Change detected, rebuilding site (#98).
2024-05-18 13:19:21.160 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2584 ms

Change detected, rebuilding site (#99).
2024-05-18 13:19:26.461 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 2528 ms

Change detected, rebuilding site (#100).
2024-05-18 13:19:31.753 +0100
Asset changed /watching/hugo_stats.json
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)

100 reloads! You can see from the timings that it is pretty much constantly reloading. This isn’t ideal as it is constantly refreshing the page. There are some discussions on it online, and I couldn’t quite put my finger on what was causing it. With a bit of deducing, it was quite obvious in the end!

Read the message

The first thing of note is the message Asset changed /watching/hugo_stats.json. Opening the file, I could see that it was updating right in front of my eyes. At one moment it read (first 8 lines for brevity):

{
  "htmlElements": {
    "tags": [
      "a",
      "article",
      "b",
      "blockquote",
      "body",

And the next it read:

{
  "htmlElements": {
    "tags": [
      "a",
      "article",
      "artifactreference",
      "b",
      "blockquote",

Note that the artifactreference tag has been added. I can at least confirm that the file is indeed being updated, but it’s not being done by me! After realising the cause, this is a real give away in hindsight.

Multiple Hugo instances running

Killing vscode fixed the issue, not really a fix is it? But on reopening vscode, I realised my mistake since it reopened all my windows and I realised that I had at some point managed to fire up hugo twice in two command line sessions in separate windows. This results in the hugo stats file being refreshed by the first sesson, which is then detected by the second session, causing a reload, which then rebuilds the file causing the first session to detect a change, and so on ad infinitum.

a gif showing the constant reload of hugo

Conclusion

So simple in the end, there are a few discussions about possibile issues in the online help but none of them consider pebkac! I hope this helps someone else out there.

#mtfbwy



Recent Posts