Skip to content

[6.x] Fix cache invalidation when using custom fields in URI route#14564

Merged
jasonvarga merged 2 commits into6.xfrom
structured-entry-uris
Apr 28, 2026
Merged

[6.x] Fix cache invalidation when using custom fields in URI route#14564
jasonvarga merged 2 commits into6.xfrom
structured-entry-uris

Conversation

@duncanmcclean
Copy link
Copy Markdown
Member

This pull request fixes an issue where structured entries using custom fields in their route (e.g. {test}) would have stale URIs after saving.

This was happening because CollectionStructure::entryUri() retrieves a Page from cached flattenedPages, and that Page caches its routeData on the instance. When the entry is saved with updated field values, the same Page object is reused with stale route data, causing the URI to reflect the old field value instead of the new one.

This PR fixes it by:

  • Calling $page->setEntry($entry) in CollectionStructure::entryUri() to ensure the page uses the fresh entry being saved
  • Resetting the cached routeData and structure-uris blink in Page::setEntry() so stale values are discarded
  • Replacing the makeItemFromFile() call in CollectionEntriesStore::writeItemToDisk() with a direct YAML ID parse, avoiding a side effect that put stale entries into the structure-entries blink store
  • Fixing empty($ids) checks in updateEntriesWithinIndex() and updateEntriesWithinStore() to use collect($ids)->isEmpty(), since empty() always returns false for Collection objects

Fixes #14145

@jasonvarga
Copy link
Copy Markdown
Member

Heads up on one bundled-but-unrelated change: switching empty($ids)collect($ids)->isEmpty() in updateEntriesWithinIndex/Store is correct (since empty() always returns false for Collection objects), but it does change behavior for one case:

  • Before: passing an empty Collection was a silent no-op — neither branch ran.
  • After: an empty Collection is treated the same as null/[] and triggers a full $index->update() rebuild.

No current caller hits this — updateChildPageUris() and UpdateStructuredEntryUris::handle() both guard with their own isEmpty() early return — so this is safe today. Just worth being aware of in case a future caller passes an empty Collection expecting the old no-op semantics.

@jasonvarga jasonvarga merged commit 01a3af6 into 6.x Apr 28, 2026
17 checks passed
@jasonvarga jasonvarga deleted the structured-entry-uris branch April 28, 2026 13:41
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.

Cache invalidation issue when using custom fields in URI

2 participants