useDataSource merged params does not effect with undefined values
doraemonxxx opened this issue · comments
- Read the docs.
- Make sure the code is up to date. (Some bugs have been fixed in the latest code)
- This is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Describe the bug
In let params
all parameters for fetching data will merge recursively using lodash merge. The issue is when you have an object that has a key with a value of undefined, that undefined will not merge.
When dynamically overriding the searchInfo
with opt?.searchInfo
, the searchInfo
object's key with a defined value and opt?.searchInfo
with a key value is undefined, resulting in unexpected behavior. This scenario is utilized in business logic where occasionally setting the searchInfo
key to undefined is necessary to meet requirements.
Reference
Reproduction and Expected Output
const customizer = (objValue: any, srcValue: any, key: any, obj: any): void => {
// Check if the values are different and if the source value is undefined
if (objValue !== srcValue && (typeof srcValue === 'undefined' || srcValue === undefined)) {
// Set the object's key to the source value
obj[key] = srcValue;
}
};
// Original object with searchInfo
let obj1 = {
level1: {
level2: {
value1: 1,
value2: 'hello',
value3: {
test1: 'hello world',
test2: 'hello world test2 obj1',
},
},
},
anotherKey: 'value',
};
// Object with opt?.searchInfo
let obj2 = {
level1: {
level2: {
value1: undefined,
value2: 'world',
value3: {
test1: 'hello world obj2',
test2: undefined,
},
},
},
anotherKey: undefined,
};
console.log('params test', mergeWith({}, obj1, obj2, customizer));
{
"level1": {
"level2": {
"value1": undefined,
"value2": "world",
"value3": {
"test1": "hello world obj2",
"test2": undefined
}
}
},
"anotherKey": undefined
}
System Info
- Operating System: 11
- Node version: 20.11.0
- pnpm version: 9.0.6