Skip to content

Commit 6f6d305

Browse files
authored
fix(ui): prevent error if rows is undefined in mergeServerFormState (#12962)
### What? Adds optional chaining when accessing `rows` in `mergeServerFormState` to prevent error crashing the UI. ### Why? When an array field is populated in a `beforeChange` hook and was previously empty, it crashes `mergeServerFormState.ts` on this line because no `rows` exist: ```ts const indexInCurrentState = currentState[path].rows.findIndex ``` The line after this checks `if (indexInCurrentState > -1)` so returning undefined here will not affect the subsequent code. ### How? Added optional chaining to the access of `rows`, which prevents the error being thrown. Fixes #12944
1 parent c902f14 commit 6f6d305

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/ui/src/forms/Form/mergeServerFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const mergeServerFormState = ({
5050
newState[path].rows = [...(currentState[path]?.rows || [])] // shallow copy to avoid mutating the original array
5151

5252
incomingField.rows.forEach((row) => {
53-
const indexInCurrentState = currentState[path].rows.findIndex(
53+
const indexInCurrentState = currentState[path].rows?.findIndex(
5454
(existingRow) => existingRow.id === row.id,
5555
)
5656

0 commit comments

Comments
 (0)