pemedia / payload-visual-editor

Payload CMS plugin which provides a visual live editor directly in the Admin UI. Works for collections and globals. Compatible with any kind of JS/TS based frontend technology.
MIT License
208 stars 10 forks source link

Update generateDocument.ts #20

Closed TomDo1234 closed 1 year ago

TomDo1234 commented 1 year ago

Return an empty array when the field is NOT REQUIRED. blockValues can be null (Literally not set) when it is not required so you should check if it is NOT required.

Otherwise... You will get this bug in production when the collection has a NON REQUIRED blocks field, but no blocks.

image

jpeiniger commented 1 year ago

Could you have a look @dkirchhof?

TomDo1234 commented 1 year ago

Could you have a look @dkirchhof?

I hope when the bug gets fixed... Whether because of my commit or not, there is a hotfix released as a patch release

dkirchhof commented 1 year ago

Hey @TomDo1234,

thanks for your PR. I think we have to handle both cases, right? If it is required, we need an empty array as fallback, if it isn't, we can just return undefined.

if (field.required && !blockValues) {
    return [];
}

if (!field.required && !blockValues) {
    return undefined;
}

Would you like to test it and update your PR?

TomDo1234 commented 1 year ago

Hey @TomDo1234,

thanks for your PR. I think we have to handle both cases, right? If it is required, we need an empty array as fallback, if it isn't, we can just return undefined.

if (field.required && !blockValues) {
    return [];
}

if (!field.required && !blockValues) {
    return undefined;
}

Would you like to test it and update your PR?

I have made the changes, can YOU or @jpeiniger test this and then merge? I dont know how to test this

dkirchhof commented 1 year ago

Thanks again. Just released the patched version on npm :)