htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.4k stars 246 forks source link

Problem with Complex. #1234

Open prosvitco-artur opened 5 months ago

prosvitco-artur commented 5 months ago

I have found an issue. When adding new Groups, their IDs are generated using this function.

const ALPHABET = "Uint8ArdomValuesObj012345679BCDEFGHIJKLMNPQRSTWXYZ_cfghkpqvwxyz";
export default function uniqueId() {
    return "cf-${generate(ALPHABET, 21)}";
}

As we can see, the string uses the character '_'. There is a small probability that this character will appear twice (but the probability exists, and it has happened to me three times in one day, you could say I won the lottery).

What’s the problem, you ask? The problem is that in this function:

handleGroupFieldChange = (fieldId, fieldValue) => {
    const {
        id,
        value,
        onChange
    } = this.props;

    onChange(id, produce(value, (draft) => {
        const path = fieldId.split('__');
        const fieldName = path.pop();
        const group = find(draft, ['_id', path.pop()]);

        set(group, fieldName, fieldValue);
    }));
}

the string is split using '_', and in my case, these fields are not being saved. Therefore, please remove the '' from the ID generation string in one of the upcoming updates!