Skip to content

[6.x] Fix Stache index re-entrancy causing null URIs on cold stache#14109

Open
o1y wants to merge 1 commit intostatamic:6.xfrom
o1y:fix-stache-null-uris
Open

[6.x] Fix Stache index re-entrancy causing null URIs on cold stache#14109
o1y wants to merge 1 commit intostatamic:6.xfrom
o1y:fix-stache-null-uris

Conversation

@o1y
Copy link
Contributor

@o1y o1y commented Feb 28, 2026

Fixes statamic/seo-pro#508

Deep Stache internals ahead. Please try to break or optimize this.. I did my best 👀

On a cold stache, building an index calls getItem() for each entry, which hits getCachedItem(). That method then triggers ->resolveIndex('uri')->load() causing re-entrant index loading.

The issue: validateTree() sees incomplete indexes, removes all entries from the structure tree, and all URIs become null. The broken index gets cached, poisoning subsequent requests. That's why the sitemap.xml is empty or Entry::query()->whereNotNull('uri') returns null 🕳️

My introduced caching from #14031 also triggers this in single-site setups, since cached items cause getCachedItem() to be called during index builds.

The main change is about tracking nested index loads, instead of storing the currently loading index in a string. ☀️

-private static ?string $currentlyLoading = null;
+private static array $loadingStack = [];

It seems also possible to just remove the URI blink from getCachedItem() (or just use the base class function), but this would break the performance optimization which was introduced in #9844

-  if (! Index::isLoading() && $this->shouldBlinkEntryUris && ($uri = $this->resolveIndex('uri')->load()->get($entry->id()))) {           
-      Blink::store('entry-uris')->put($entry->id(), $uri);                                                                             
-  }

If possible, it might be worth backporting this to 5.x? 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sitemap.xml is empty after cache:clear in Multisite

1 participant