From 83eb53fffb308f9ee859111ecd16e0363330d0f6 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Tue, 4 Aug 2026 18:43:46 +1000 Subject: [PATCH] fix: mount signers field array so setValue reconciles reordered arrays --- .../envelope-editor-recipient-form.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/remix/app/components/general/envelope-editor/envelope-editor-recipient-form.tsx b/apps/remix/app/components/general/envelope-editor/envelope-editor-recipient-form.tsx index 15193944e..1c88505a5 100644 --- a/apps/remix/app/components/general/envelope-editor/envelope-editor-recipient-form.tsx +++ b/apps/remix/app/components/general/envelope-editor/envelope-editor-recipient-form.tsx @@ -23,7 +23,7 @@ import { Trans } from '@lingui/react/macro'; import { DocumentSigningOrder, RecipientRole, SendStatus } from '@prisma/client'; import { HelpCircleIcon, PlusIcon, SparklesIcon } from 'lucide-react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { useWatch } from 'react-hook-form'; +import { useFieldArray, useWatch } from 'react-hook-form'; import { useRevalidator, useSearchParams } from 'react-router'; import { isDeepEqual } from 'remeda'; @@ -134,6 +134,15 @@ export const EnvelopeEditorRecipientForm = () => { return normalizeGroupedSigningOrders(signers, (signer) => canRecipientBeModified(signer.id)); }; + // Keep a mounted field array for `signers` so react-hook-form reconciles + // whole-array `setValue` calls atomically. Without it, reordering the array + // leaves stale partial entries in watched values (missing email/name/role), + // which breaks validation and the autosave sync. + useFieldArray({ + control, + name: 'signers', + }); + const stepCount = useMemo(() => groupRecipientsBySigningOrder(watchedSigners).steps.length, [watchedSigners]); const emptySignerIndex = watchedSigners.findIndex(