Shortcode rendering `.Content` not updating on page change

In our project we have a cs-modules.html shortcode which does the following:

{{ $modules := where site.Pages "Type" "module" }}

{{ range $modules.ByWeight }}
{{ .Content }}
{{ end }}

However, whenever we add/change a page with type: module in the frontmatter, hugo serve --disableFastRender successfully detects the change and refreshes, but without the edited content being rendered in place of the shortcode (it’s stuck on whatever the content was at startup).

Restarting the hugo server fixes it, though this is not great for productivity. It’s very possible we’re doing something weird with shortcodes - is there a “proper” way to achieve the effect? We’re trying to avoid manually specifying each and every module by hand, but presumably that would work.

Run hugo a bit more verbose with the following CLI parameters:

hugo server \
    --gc \
    --disableFastRender \
    --i18n-warnings \
    --templateMetrics \
    --templateMetricsHints \
    --path-warnings \
    --buildDrafts --buildExpired --buildFuture \
    --watch \
    --enableGitInfo \
    --log true --logFile hugo.log \
    --verbose \
    --verboseLog \
    --debug

Start the server and read through the CLI output to see if anything weird comes up. Check if the directory that you create the content in is in the list of watched directories. If not - more info :wink:

Then create content and look again at the output… sometimes there are issues with file system links and file system ownership. Sometimes a “third actor” (antivirus, your editor,…) locks the file.

One last point to look for: Your system time, your timestamp in the frontmatter. What’s in the future can’t be published yet. (that’s why we have --buildDrafts --buildExpired --buildFuture in the command above.

Thanks for the reply.

The write is detected and appears to be rendering the pages, but the output from the shortcode specifically is not reflected in the build.

We’re not using timestamps on the content, so it shouldn’t have an effect on the rendering. What’s particularly troubling is that it renders the content correctly after a restart of the hugo server.

Of particular note is that this shortcode is the only content affected: the remainder of the site builds properly and without issue.

In any case, I’ve included the command output here (capturing the rebuild):

Change detected, rebuilding site.
2021-12-30 09:25:57.857 -0700
DEBUG 2021/12/30 09:25:57 Rebuild for events ["\"D:\\\\Workspaces\\\\matrix-misc\\\\matrix-doc\\\\content\\\\client-server-api\\\\modules\\\\spaces.md\": WRITE"]
Source changed "D:\\Workspaces\\matrix-misc\\matrix-doc\\content\\client-server-api\\modules\\spaces.md": WRITE
DEBUG 2021/12/30 09:25:58 Render page Appendices to "\\appendices\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Application Service API to "\\application-service-api\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Changelog to "\\changelog\\index.html"
WARN 2021/12/30 09:25:58 The google_news internal template will be removed in a future release. Please remove calls to this template. See https://github.com/gohugoio/hugo/issues/9172 for additional information.
DEBUG 2021/12/30 09:25:58 Render page Identity Service API to "\\identity-service-api\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Spec Change Proposals to "\\proposals\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Push Gateway API to "\\push-gateway-api\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Server-Server API to "\\server-server-api\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\account_data\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\admin\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\content_repo\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\device_management\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\dm\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\end_to_end_encryption\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\event_context\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\guest_access\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\history_visibility\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\ignore_users\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\instant_messaging\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\moderation_policies\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\mentions\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\openid\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\presence\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\push\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\read_markers\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\receipts\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\report_content\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\room_previews\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\room_upgrades\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\search\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\secrets\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\send_to_device\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\server_acls\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\server_notices\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\spaces\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\sso_login\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\third_party_invites\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\stickers\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\tags\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\third_party_networks\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\typing_notifications\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\client-server-api\\modules\\voip_events\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v1-auth-rules\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v1-canonical-json\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v1-redactions\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v2-state-res\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v3-auth-rules\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v3-handling-redactions\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v4-event-format\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v5-signing-requirements\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v4-event-ids\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v6-canonical-json\\index.html"
DEBUG 2021/12/30 09:25:58 Render page  to "\\rooms\\fragments\\v6-redactions\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 1 to "\\rooms\\v1\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 2 to "\\rooms\\v2\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 3 to "\\rooms\\v3\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 4 to "\\rooms\\v4\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 5 to "\\rooms\\v5\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 7 to "\\rooms\\v7\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Matrix Specification to "\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Version 6 to "\\rooms\\v6\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Client-Server API to "\\client-server-api\\index.html"
DEBUG 2021/12/30 09:25:58 Render page Room Versions to "\\rooms\\index.html"
DEBUG 2021/12/30 09:25:58 Render XML for "sitemap" to "\\sitemap.xml"
DEBUG 2021/12/30 09:25:58 Render 404 page to "\\404.html"
DEBUG 2021/12/30 09:25:58 Render page Matrix Specification to "\\index.xml"
DEBUG 2021/12/30 09:25:58 Render page Room Versions to "\\rooms\\index.xml"
DEBUG 2021/12/30 09:25:58 Render page Client-Server API to "\\client-server-api\\index.xml"
DEBUG 2021/12/30 09:25:58 Render Robots Txt to "robots.txt"

Template Metrics:

      cache     cumulative       average       maximum
  potential       duration      duration      duration  count  template
      -----     ----------      --------      --------  -----  --------
          0    291.2288ms    6.471751ms     85.7708ms     45  _default/single.html
         10    195.5022ms    3.103209ms     85.2577ms     63  partials/head.html
          0     87.9014ms    6.278671ms      9.5406ms     14  docs/single.html
          0     77.6406ms     38.8203ms     73.0008ms      2  shortcodes/event.html
        100     77.1063ms    1.223909ms      7.0017ms     63  partials/navbar.html
          1     64.2869ms     164.838µs      2.9981ms    390  partials/json-schema/resolve-refs.html
         90     30.0607ms    1.768276ms      3.9997ms     17  partials/sidebar.html
         90     19.0915ms    1.123029ms      2.0045ms     17  partials/sidebar-tree.html
          0     16.9996ms    5.666533ms      6.0032ms      3  docs/list.html
        100      6.0029ms     285.852µs      1.0061ms     21  partials/scripts.html
          0      3.9991ms      3.9991ms      3.9991ms      1  shortcodes/boxes/warning.html
         53      3.5812ms      1.7906ms      1.9716ms      2  partials/events/render-event.html
        100      3.5248ms      55.949µs         999µs     63  partials/hooks/head-end.html
        100      3.5173ms       55.83µs      1.0061ms     63  partials/footer.html
          0      2.6372ms     879.066µs      2.1146ms      3  _default/list.rss.xml
        100      2.5449ms      40.395µs       1.001ms     63  partials/outputformat.html
         12      2.0022ms      64.587µs      1.0011ms     31  partials/json-schema/resolve-allof.html
         67      1.9986ms     117.564µs      1.0002ms     17  partials/breadcrumb.html
          0      1.5922ms      1.5922ms      1.5922ms      1  _internal/_default/sitemap.xml
          0      1.0061ms      71.864µs      1.0061ms     14  _default/content.html
         42      1.0012ms     143.028µs      1.0012ms      7  partials/get-additional-objects
         77      1.0012ms     111.244µs      1.0012ms      9  partials/json-schema/resolve-additional-types.html
         54      1.0003ms      500.15µs      1.0003ms      2  partials/openapi/render-object-table.html
        100      1.0002ms      12.502µs      1.0002ms     80  partials/search-input.html
        100      1.0002ms      47.628µs      1.0002ms     21  partials/hooks/body-end.html
        100       999.3µs      58.782µs       999.3µs     17  partials/version-banner.html
          0       529.7µs       529.7µs       529.7µs      1  404.html
        100            0s            0s            0s      1  partials/favicons.html
        100            0s            0s            0s     63  partials/version-string
          0            0s            0s            0s      1  _internal/_default/robots.txt
          0            0s            0s            0s      1  shortcodes/added-in.html
          0            0s            0s            0s      2  shortcodes/boxes/note.html
        100            0s            0s            0s      3  partials/head-css.html
         39            0s            0s            0s      3  partials/alert.html
         50            0s            0s            0s      2  partials/clean-object

Total in 534 ms

spaces.md is a file that existed prior to the command being run, and was edited after the server was started. The change made to the file is not reflected in the render.

I did notice that including/changing some of our other shortcodes in the content did cause the content to re-render - is it possible that hugo is overzealously caching the output of cs-modules.html? If so, can we disable it for that particular shortcode?

There are several open issues related to unexpected output when running hugo server. For example:

One or more of these may apply to your scenario.

Over time I have become accustomed to restarting the server when I don’t see what I expect, to the point where I type Ctrl+C hs without even thinking about it (where hs is an alias to hugo server).

Thanks. I’ve proposed that we just don’t use this shortcode in our project anymore.

Edit: PR link

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.