Skip to content

Commit 2388e7d

Browse files
committed
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.
1 parent c91bd26 commit 2388e7d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/shared/src/Struct.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import * as P from "effect/Predicate";
22

33
export function deepMerge<T>(current: T, patch: unknown): T {
4-
if (!P.isObject(current) || !P.isObject(patch)) {
4+
if (
5+
!P.isObject(current) ||
6+
!P.isObject(patch) ||
7+
Array.isArray(current) ||
8+
Array.isArray(patch)
9+
) {
510
return patch as T;
611
}
712

@@ -10,7 +15,10 @@ export function deepMerge<T>(current: T, patch: unknown): T {
1015
if (value === undefined) continue;
1116

1217
const existing = next[key];
13-
next[key] = P.isObject(existing) && P.isObject(value) ? deepMerge(existing, value) : value;
18+
next[key] =
19+
P.isObject(existing) && P.isObject(value) && !Array.isArray(existing) && !Array.isArray(value)
20+
? deepMerge(existing, value)
21+
: value;
1422
}
1523

1624
return next as T;

0 commit comments

Comments
 (0)