[SalesForce] Spring 20 LWC Cannot add a property x, object not extensible

After spring 20 release update in my sandbox i'm finding that non-cached apex response object cannot be extended and the lwc controller is throwing exception "Cannot add a property x, object not extensible".

I believe after spring 20, the controller runs in strict mode where you can't extend the response object. I can get away from this by cloning the object. eg. let data = { …result}. Not sure if this is going to break in future.

Again, this cloning gets applied only to the top level object, if there are object inside an object, this doesn't work. In that case stringifying the response will fix, but again this is not mentioned in anywhere.

We have lwc code deployed to production with object extensions and will break once this update gets into production.

Does anyone face the same issue? Any suggestions

UPDATE: I find this is inconsistent behavior, some of the existing components with api version 46 works with object extension. I guess this is a bug.


Just to clarify on apex controller, i'm not using any cachable methods but an @AuraEnabled method. I believe this is not cached and hence the response should be editable.

As i said, this was working before spring 20 and but now it has put more restriction on the client side controller irrespective of the api version, which is quiet annoying.

Best Answer

My team has faced the issue as you with multiple LWC components on Spring '20 preview org.

We found a post from Salesforce employee on Salesforce Partners forum which states that the problem has been acknowledged and the fix should be deployed this week.

The change is made by design and is about a unifying response from LDS, which in other areas (@wire) is immutable. Although the update broke many components, so Salesforce team decided to revert it. However, as I understand - it can come back in one of the next few releases, so we should make components future proof with object cloning.

Related Topic