Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useDataSource merged params does not effect with undefined values #3891

Open
3 tasks done
doraemonxxx opened this issue Jun 4, 2024 · 0 comments
Open
3 tasks done

Comments

@doraemonxxx
Copy link
Contributor

doraemonxxx commented Jun 4, 2024

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • 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

59b309a

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant