From c7a29ad00d84c46cb5a17cf236c2ed22261c5530 Mon Sep 17 00:00:00 2001 From: Ole Anti Date: Wed, 24 Jun 2026 13:37:28 +0200 Subject: [PATCH] Derive a stable, per-field wire:key from the state path. Using rand() produced a new key on every render, so a ->live() round-trip swapped the whole field node (defeating wire:ignore) and reset the tree --- src/SelectTree.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SelectTree.php b/src/SelectTree.php index ac4963f..d259284 100644 --- a/src/SelectTree.php +++ b/src/SelectTree.php @@ -168,7 +168,7 @@ protected function setUp(): void static fn (SelectTree $component): ?Action => $component->getCreateOptionAction(), ]); - $this->treeKey('treeKey-'.rand()); + $this->treeKey(fn (SelectTree $component): string => 'treeKey-'.$component->getStatePath()); } protected function buildTree(): Collection @@ -810,7 +810,7 @@ public function createOptionModalHeading(string|Closure|null $heading): static return $this; } - public function treeKey(string $treeKey): static + public function treeKey(Closure|string $treeKey): static { $this->treeKey = $treeKey;