From 8fee7f3ca3ff5a054595bbe9d3af97346b6593cf Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 13 Aug 2026 10:45:23 +0100 Subject: [PATCH] fix uri index for new entries in orderable collections `uri` was being updated before `collectionHandle` and `site` in `CollectionEntriesStore::storeIndexes()`. entries in orderable collections aren't written to the tree file, so `CollectionStructure::validateTree()` queries the collection's entries to reconcile it - and that query couldn't see the entry being saved, leaving `null` cached as its uri (and `1` as its order) until the entry was saved a second time. Co-Authored-By: Claude Opus 5 --- src/Stache/Stores/CollectionEntriesStore.php | 2 +- tests/Stache/OrderableEntryUriTest.php | 50 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/Stache/OrderableEntryUriTest.php diff --git a/src/Stache/Stores/CollectionEntriesStore.php b/src/Stache/Stores/CollectionEntriesStore.php index a56433f377f..6c139043d34 100644 --- a/src/Stache/Stores/CollectionEntriesStore.php +++ b/src/Stache/Stores/CollectionEntriesStore.php @@ -160,13 +160,13 @@ protected function storeIndexes() { $indexes = collect([ 'slug', - 'uri', 'collectionHandle', 'published', 'title', 'site' => Indexes\Site::class, 'origin' => Indexes\Origin::class, 'parent' => Indexes\Parents::class, + 'uri', ]); if (! $collection = Collection::findByHandle($this->childKey())) { diff --git a/tests/Stache/OrderableEntryUriTest.php b/tests/Stache/OrderableEntryUriTest.php new file mode 100644 index 00000000000..46115151b0d --- /dev/null +++ b/tests/Stache/OrderableEntryUriTest.php @@ -0,0 +1,50 @@ +routes('/vehicles/{slug}') + ->structureContents(['max_depth' => 1]); + $collection->save(); + } + + private function simulateNewRequest(): void + { + Blink::flush(); + Stache::stores()->each->resetMemoizedState(); + app('stache.indexes')->each->resetMemoizedState(); + } + + #[Test] + public function entries_have_uris_and_orders_after_being_saved() + { + Entry::make()->collection('vehicles')->slug('car')->data(['title' => 'Car'])->save(); + + $this->simulateNewRequest(); + + Entry::make()->collection('vehicles')->slug('bus')->data(['title' => 'Bus'])->save(); + + $this->simulateNewRequest(); + + $this->assertNotNull($car = Entry::findByUri('/vehicles/car')); + $this->assertNotNull($bus = Entry::findByUri('/vehicles/bus')); + $this->assertEquals(1, $car->order()); + $this->assertEquals(2, $bus->order()); + } +}