salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 393 forks source link

Remove misleading warning when using `@wire` on a getter or a setter #4428

Open wjhsf opened 3 months ago

wjhsf commented 3 months ago
class extends LightningElement {
  @wire(getData, {id: 1}) get dataProp() {}
  @wire(getData, {id: 2}) set otherProp(v) {}
}

~Currently, using @wire on a getter or a setter successfully compiles, but it fails at runtime with "Error: [LWC error]: Invalid @wire dataProp field. Found a duplicate accessor with the same name." To prevent deploying faulty code, this error should be caught at compile time.~

Currently, using @wire on a getter or a setter works, but it logs a misleading error at runtime, "Error: [LWC error]: Invalid @wire dataProp field. Found a duplicate accessor with the same name." This error should not be logged.

nolanlawson commented 3 months ago

This is actually subtle. You can use an @wire with a getter/setter in the following ways:

In all three cases, the wire works as expected but an error is logged:

Invalid @wire value field. Found a duplicate accessor with the same name.

Since this is behavior we support (and I don't see any reason not to support it – a getter/setter is roughly the same as a class property), I would propose we don't remove it and instead get rid of the error-logging.

Based on the tests for the error message BTW, it looks like the intention was to prevent truly egregious mistakes like this one:

https://github.com/salesforce/lwc/blob/9e4ea5985cf15b7eda2b5b4a66c8c780120bfbfc/packages/%40lwc/integration-karma/test/component/decorators/wire/index.spec.js#L27-L41