Page Store not reset when editing template in live server?

I have a shortcode that uses a page store… here is a simple example:

{{- $prev := .Page.Store.Get "count" | default 0 }}
{{- $next := $prev | add 1 }}
{{- .Page.Store.Set "count" $next }}
{{ $next }}

It works fine.

But… If I am using the live server (e.g. hugo server), if I edit the shortcode template, the page gets rebuilt - without resetting the page store (so the page starts with the ending value from the last build).

If I edit the page, everything is fine (the page store does get reset).

This makes debugging a little tricky. Is there a way to force the page store to be reset every time the page is rebuilt? (even if it is rebuilt because a shortcode changed)

Thank you.

In v0.138.0, we updated Page.Scratch to behave identically to Page.Store, meaning data now persists across rebuilds. Previously, in v0.137.1 and earlier, Page.Scratch data was not persistent. While this change might not suit every workflow, it resolved a significant amount of user frustration documented in this forum. We made this change to reduce the need to constantly advise users to use Page.Store instead of Page.Scratch.

I’m inclined to leave this alone, but you’re welcome to create a GitHub issue.

Thank you!

It’s good to know that this is intentional.

I suspect that my use case is weird. So, I would not want to suggest that the system be changed.

But is there some way to “reset” the store (or, at least the counters that I want to start at zero on each page).

Also, it seems that the store does get reset on a new invocation of hugo. If I stop the live server, and re-start it, it seems like the counters get reset. Am I misinterpreting something, or am I seeing something weird.

Or, maybe put differently…
Is there a way to make a counter that (reliably) can be used by many different shortcodes on a page, that starts at zero/one at the top of the page?

(like the example above does if I do a total rebuild)

Hugo has no way of storing data between calls to its executable. The data is stored while Hugo is running (either hugo or hugo server), and then evaporates.

Your remaining questions are all related to the change in v0.138.0; the values are persistent between rebuilds.

Thank you.

To be clear when you say “between rebuilds” - you mean “rebuilds within the same invocation of the hugo executable” (such as a live reload when using hugo server - I am not aware of any other case).

If so, this is a good thing, since the “problem” I have is just a minor annoyance when debugging on a local server. (at least for now)

Thanks for the advice!

Yes, that’s what I mean.