diff --git a/src/components/input/SelectInput.tsx b/src/components/input/SelectInput.tsx index 32f8dbcd..c1736fc5 100644 --- a/src/components/input/SelectInput.tsx +++ b/src/components/input/SelectInput.tsx @@ -566,23 +566,31 @@ const useSelect = ( setSize(size + 1); }; - let formattedSuccessRawData: SuccessApiResponse | undefined = undefined; - let formattedErrorRawData: ErrorApiResponse | undefined = undefined; - const latestPagesIndex = pages?.length ? pages.length - 1 : 0; - if (isResponseSuccess(pages?.[latestPagesIndex])) { - formattedSuccessRawData = { - ...pages?.[latestPagesIndex], - data: - pages?.flatMap((page) => (isResponseSuccess(page) ? page.data : [])) ?? - [], - }; - } + const { formattedSuccessRawData, formattedErrorRawData } = useMemo(() => { + let successData: SuccessApiResponse | undefined = undefined; + let errorData: ErrorApiResponse | undefined = undefined; - if (isResponseError(pages?.[latestPagesIndex])) { - formattedErrorRawData = pages?.[latestPagesIndex]; - } + if (isResponseSuccess(pages?.[latestPagesIndex])) { + successData = { + ...pages![latestPagesIndex], + data: + pages?.flatMap((page) => + isResponseSuccess(page) ? page.data : [] + ) ?? [], + }; + } + + if (isResponseError(pages?.[latestPagesIndex])) { + errorData = pages![latestPagesIndex]; + } + + return { + formattedSuccessRawData: successData, + formattedErrorRawData: errorData, + }; + }, [pages, latestPagesIndex]); return { inputValue, diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 846c6d7a..680be036 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -974,9 +974,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { return; } - if (next[item.id] !== item) { - next[item.id] = item; - changed = true; + const existing = next[item.id]; + if (existing !== item) { + // Check deep equality to avoid triggering state changes + // when identical data comes from different sources (e.g. initialValues vs SWR) + if ( + !existing || + JSON.stringify(existing) !== JSON.stringify(item) + ) { + next[item.id] = item; + changed = true; + } } });