fix: prevent deepMerge from corrupting arrays by treating them as leaf values

P.isObject returns true for arrays, causing deepMerge to spread arrays
into plain objects with numeric keys and recursively merge entries.
This corrupted customModels arrays in ServerSettings whenever
updateSettings was called.

Add Array.isArray guards at both the top-level check and the per-key
recursive branch so arrays are replaced wholesale instead of merged.
This commit is contained in:
Cursor Agent committed 2026-03-26 00:07:31 +00:00
1 parent c91bd26b3c
commit 2388e7d43f
1 file changed
+10 -2
+10 -2
View File
@@ -1,7 +1,12 @@
import * as P from "effect/Predicate";
export function deepMerge<T>(current: T, patch: unknown): T {
if (!P.isObject(current) || !P.isObject(patch)) {
if (
!P.isObject(current) ||
!P.isObject(patch) ||
Array.isArray(current) ||
Array.isArray(patch)
) {
return patch as T;
}
@@ -10,7 +15,10 @@ export function deepMerge<T>(current: T, patch: unknown): T {
if (value === undefined) continue;
const existing = next[key];
next[key] = P.isObject(existing) && P.isObject(value) ? deepMerge(existing, value) : value;
next[key] =
P.isObject(existing) && P.isObject(value) && !Array.isArray(existing) && !Array.isArray(value)
? deepMerge(existing, value)
: value;
}
return next as T;