Skip to content

Commit 0f0a66f

Browse files
committed
refactor: adds guards for fields with null values
1 parent dc072dd commit 0f0a66f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/runtime/src/cross/mutator.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function doApplyMutation(
151151
logging
152152
);
153153

154-
if (r) {
154+
if (r && typeof r === 'object') {
155155
if (!arrayCloned) {
156156
resultData = [...resultData];
157157
arrayCloned = true;
@@ -160,9 +160,12 @@ async function doApplyMutation(
160160
updated = true;
161161
}
162162
}
163-
} else {
163+
} else if (resultData !== null && typeof resultData === 'object') {
164+
// Clone resultData to prevent mutations affecting the loop
165+
const currentData = { ...resultData };
166+
164167
// iterate over each field and apply mutation to nested data models
165-
for (const [key, value] of Object.entries(resultData)) {
168+
for (const [key, value] of Object.entries(currentData)) {
166169
const fieldInfo = modelFields[key];
167170
if (!fieldInfo?.isDataModel) {
168171
continue;
@@ -178,7 +181,7 @@ async function doApplyMutation(
178181
logging
179182
);
180183

181-
if (r) {
184+
if (r && typeof r === 'object') {
182185
resultData = { ...resultData, [key]: r };
183186
updated = true;
184187
}

0 commit comments

Comments
 (0)