1

When using Lightning Web Security architecture it seems like objects retrieved from Apex methods cannot be modified anymore. It affects backward compatibility when enabling this feature.

Example: Lets say, we retrieved response from Apex method invocation by LWC:

{
  attribute1: 'Value One', 
  attribute2: 'Value Two', 
  success: true
}

Then we set additional parameter on this object by:

response.newAttribute = 'New attribute value';

Affter logging object, we can see new object state (depending on Web Security feature on or off)

CASE 1: Lightning Web Security not enabled:

{ 
  attribute1: 'Value One', 
  attribute2: 'Value Two', 
  success: true, 
  newAttribute: 'New attribute value'
}

CASE 2: With Lightning Web Security enabled - object remains the same:

{
  attribute1: 'Value One', 
  attribute2: 'Value Two', 
  success: true
}

But if we clone this same object, then new attribute is visible: JSON.parse(JSON.stringify(response)):

{ 
  attribute1: 'Value One', 
  attribute2: 'Value Two', 
  success: true, 
  newAttribute: 'New attribute value'
}

Looks like Lightning Web Security prevents those modifications, but this is issue for backward compatibility.

1 Answer 1

1

This is the correct behavior. Responses from Apex are supposed to be in a read-only membrane, meaning any modifications to the object should be rejected. This is desirable, because if you modify that object, it corrupts the data in the cache; any components using the same method and parameters will see the modifications to the original response. If it was working before, that was the bug. You will need to fix your code to always copy the object before attempting any modifications.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .