Skip to content

Commit

Permalink
fixup! fix: don't try to deepMerge read-only properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Jan 20, 2025
1 parent 3b16e7c commit 3c3c4ff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions res/controllers/common-controller-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,21 @@ const deepMerge = function(target, source) {
target.push(...Object.values(objTarget));
} else if (isSimpleObject(target) && isSimpleObject(source)) {
Object.keys(source).forEach(key => {
// ensure the property is not read-only, if so skip it.
if (!Object.getOwnPropertyDescriptor(source, key).writable) {
return;
}
if (
Array.isArray(target[key]) && Array.isArray(source[key]) ||
isSimpleObject(target[key]) && isSimpleObject(source[key])
) {
deepMerge(target[key], source[key]);
} else if (source[key] !== undefined && source[key] !== null) {
Object.assign(target, {[key]: source[key]});
try {
Object.assign(target, {[key]: source[key]});
} catch (e) {
if (e instanceof TypeError) {
console.warn(e.message);
} else {
throw e;
}
}
}
});
}
Expand Down

0 comments on commit 3c3c4ff

Please sign in to comment.