From 7c44778f25db23f17aa8bc79ebc06da188b3da84 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 9 Feb 2026 16:47:54 +0100 Subject: [PATCH] fix(edit-pages): resolve custom field display race condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The init watcher destructured currentType/currentStructure before setting selectedTypeId, so the values were stale (null). This caused refreshCustomFieldInputs to receive null structure → empty definitions, permanently wiping custom field display on piece and component edit pages. Read selectedType.value / selectedTypeStructure.value after setting the ID so the computed is already updated. Also remove the guard on the piece selectedType watcher that prevented recovery. Co-Authored-By: Claude Opus 4.6 --- app/pages/component/[id]/edit.vue | 4 +++- app/pages/pieces/[id]/edit.vue | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/pages/component/[id]/edit.vue b/app/pages/component/[id]/edit.vue index 310530e..4d9271c 100644 --- a/app/pages/component/[id]/edit.vue +++ b/app/pages/component/[id]/edit.vue @@ -803,7 +803,9 @@ watch( void ensureConstructeurs(editionForm.constructeurIds) } - refreshCustomFieldInputs(currentStructure, currentComponent.customFieldValues) + // After setting selectedTypeId, read selectedTypeStructure.value (now updated) instead of + // the stale destructured currentStructure which was captured before the ID change. + refreshCustomFieldInputs(selectedTypeStructure.value ?? currentStructure, currentComponent.customFieldValues) initialized = true }, diff --git a/app/pages/pieces/[id]/edit.vue b/app/pages/pieces/[id]/edit.vue index b9a357d..b82804a 100644 --- a/app/pages/pieces/[id]/edit.vue +++ b/app/pages/pieces/[id]/edit.vue @@ -837,7 +837,10 @@ watch( pendingProductIds = [] } - refreshCustomFieldInputs(currentType?.structure ?? null, currentPiece.customFieldValues) + // After setting selectedTypeId, read selectedType.value (now updated) instead of + // the stale destructured currentType which was captured before the ID change. + const resolvedType = selectedType.value ?? pieceTypeDetails.value ?? null + refreshCustomFieldInputs(resolvedType?.structure ?? null, currentPiece.customFieldValues) initialized = true }, @@ -848,9 +851,7 @@ watch(selectedType, (currentType) => { if (!piece.value || !currentType) { return } - if (!pieceTypeDetails.value) { - refreshCustomFieldInputs(currentType.structure, piece.value.customFieldValues) - } + refreshCustomFieldInputs(currentType.structure, piece.value.customFieldValues) }) watch(resolvedStructure, (currentStructure) => {