magento / magento2-page-builder

Magento2 PageBuilder
Other
81 stars 63 forks source link

Validator rule required-entry crashes when value is null #797

Open amenk opened 2 years ago

amenk commented 2 years ago

Summary (*)

We upgraded to Magento 2.4.3 and cannot load the product editor anymore in the backend.

There is a javascript error raised:

Uncaught TypeError: Cannot read properties of null (reading 'padding')
    at Object.eval [as handler] (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:19:182)
    at validate (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:5:61)
    at eval (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:8:217)
    at Function._.every._.all (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:16:571)
    at validator (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:8:112)
    at UiClass.validate (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:9:678)
    at setNested (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:5:50)
    at Object.nested (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:11:127)
    at UiClass.set (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:12:318)
    at updateValue (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:11:80)

We tracked that down to the following code

https://github.com/magento/magento2-page-builder/blob/8ed420dd9b8f79472e8266d46611a93e40cb7fe0/app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/validator-rules-mixin.js#L237

It seems to be a valid case, that value is null. In this case, the script still tried to read .padding.

Is that intended?

Also I do not understand why the validator required-entry is registered - isn't that already a commonly used validator which also should work on null values?

Proposed solution

if (typeof value === 'object' && value !== null && !!(value.padding || value.margin)) {
m2-assistant[bot] commented 2 years ago

Hi @amenk. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


MrBlueEyez commented 1 year ago

Facing this issue on Magento 2.4.5-p1 as well, the value is somehow null, and null is an object according to javascript. As suggested by @amenk, adding a value !== null inside the if would solve the issue on hand.

However the issue is not always occuring, but I still believe that a fix would help here.

Might also be related to #36863

TheBadong commented 1 year ago

If it may help, I found the field that caused the problem by placing a breakpoint here: image Just unwrap the this UiClass and all the useful data will be there. In my case it was due to a third party module that since got updated.

hemendrametawolf commented 4 months ago

I am getting this issue when I open the attribute tab on product edit page in admin and trying to make changes and save the product. getting below error in console and unable to save the product validator-rules-mixin.js:237 Uncaught TypeError: Cannot read properties of null (reading 'padding') at Object.handler (validator-rules-mixin.js:237:59) at validate (validator.js:44:24) at validator.js:84:30 at Function.every (underscore.js:1408:18) at validator (validator.js:82:15) at UiClass.validate (abstract.js:407:26) at setNested (objects.js:44:25) at Object.nested (objects.js:118:20) at UiClass.set (element.js:305:19) at updateValue (links.js:80:19)

I am using magento 2.4.4-p1 Any one having update to resolve this.

amenk commented 4 months ago

@hemendrametawolf are you able to reproduce this on a clean instance reliably?

hemendrametawolf commented 4 months ago

@hemendrametawolf are you able to reproduce this on a clean instance reliably?

No let me check that.

hemendrametawolf commented 4 months ago

@magento give me 2.4.4-p1 instance

magento-deployment-service[bot] commented 4 months ago

Hi @hemendrametawolf. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 4 months ago

Hi @hemendrametawolf, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

hemendrametawolf commented 4 months ago

@magento give me 2.4.4 instance

magento-deployment-service[bot] commented 4 months ago

Hi @hemendrametawolf. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 4 months ago

Hi @hemendrametawolf, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

NitrogenUA commented 4 months ago

This issue has been addressed in the latest release.