-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose all @wire configurations on the element instance in non-prod modes #1902
Comments
Thanks for raising this issue @kevinv11n. The main concern that I have with a symbol attached to the host element is that it leaks internal details of the component on the host element. The wired properties have nothing to do with the custom element but with the component (those are 2 distinct objects in LWC). As a side effect, the parent component might also be able to observe in dev mode the child component wired properties, but this is less of an issue. // From c-my-parent
this.querySelector('c-my-component')[Symbol.for('@wire')] That being said, I think we should start exposing more information via the devtool to help developers debug LWC components and wired properties/methods. A preferable approach IMHO would be to define new APIs that a dedicated browser extension to hook into to observe and report the component state. |
Good stuff! I'm very sympathetic with this. As for @pmdartus' concerns, I think we can mitigate that by not using As you can see, by creating a new symbol every time, per instance, per wire, it reads very nice, and it is very hard for anyone to attempt to use this information before they realized it is a dev-mode only thing. |
Btw, I believe this is an old issue for this somewhere. This was @philcalvin's first complain about LWC a long time ago... let's get this solved. |
The proposed facility is arguably a central component to the LWC development experience. |
Is your feature request related to a problem? Please describe.
@wire
'd properties are concise but don't provide insight into if and when a value is provisioned.A customer recently shared this perspective:
Consider this example LWC component:
If
this.wiredProperty.data
isn't rendered, what was the cause?Describe the solution you'd like
When in non-production mode, provide a developer with insight into:
This can be done by exposing the values on the element instance keyed from a known symbol. Continuing the example above, imagine running this code in the dev console after selecting the
c-my-component
element:With wire reform getting the resolved configuration values is simple.
Describe alternatives you've considered
#1. Lifecycle Hook
Comparable to
connectedCallback()
, if you implement a (static?) function it is invoked when wires update: config, provision of value/error.This approach was rejected because a single codebase is used for dev and prod mode, which means this debugging logic contaminates the codebase.
#2 Metaconfig for a wire
Add an additional parameter to @wire which is a meta-config object.
This approach was rejected because it restricts future evolution of
@wire
. It also suffers from placing the toggle for debug mode into the code whereas it is configured external to the component source code (eg on Lightning Platform it's via the Setup menu, in OSS it's a compiler/bundler flag).#3 Callback on
@wire
Add a third parameter arrow function to the
@wire
declaration that is invoked only in dev mode.This approach was rejected because it restricts future evolution of
@wire
. It also suffers from placing the toggle for debug mode into the code whereas it is configured external to the component source code (eg on Lightning Platform it's via the Setup menu, in OSS it's a compiler/bundler flag).The text was updated successfully, but these errors were encountered: