https://developer.salesforce.com/docs/component-library/tools/playground/IaX_i6WN/3/edit
export default class Child extends LightningElement {
@api
objects = [];
connectedCallback() {
this.objects.push('child mutated label');
}
}
Actual Result:
_Error: Invalid mutation: Cannot set "0" on "". "" is read-only._
Expected:
_Error: Invalid operation. The 'objects' property is read-only._
This issue has been linked to a new work item: W-7262124
@apapko The error message can't contain the mutate object name since the object name is bound to the current context scope. This information is not available from the ReadOnly proxy.
The best thing we can do here is to print the original target type instead of coercing the original target name to string.
Error: Invalid mutation: Cannot set "0" on a read-only object.
@pmdartus i find the Cannot set "0" part to be very confusing as it may not be obvious to a novice user that such message is related to array.push operation. What if we use:
_"Invalid operation. @api properties are read-only and cannot be mutated."_
We will need to open a new API on the ReadOnlyProxy to parametrize the error message.
I might be able to help here, we do similar stuff in the membrane for locker. Let's chat about it.
Most helpful comment
@pmdartus i find the
Cannot set "0"part to be very confusing as it may not be obvious to a novice user that such message is related to array.push operation. What if we use:_"Invalid operation. @api properties are read-only and cannot be mutated."_