You need to sign in to do that
Don't have an account?
lwc preview locally not loading with styling hooks
I have an LWC using a custom css class to color a lighting-icon.
<lightning-icon icon-name="utility:file" class="required-icon"></lightning-icon>
.required-icon {
--slds-c-icon-color-foreground-default: rgba(182,24,26,1);
--slds-c-icon-color-foreground: rgba(182,24,26,1);
--slds-c-icon-color-background: white;
}
When I view the component directly within salesforce login, it renders without error. When I try to view the component through VS Code > Preview Component Locally on either desktop or an android emulator, I get the following error:
CssSyntaxError: LWC1009: postcss-plugin-lwc: 8:2: Invalid definition of custom property "--slds-c-icon-color-foreground-default".
Error: There were errors while compiling component c/mycomponent at Preview.loadHostedComponent (http://localhost:3333/webruntime/component/9dfc3a8207/dev/en-US/localdevserver/preview:2109:21)
Am I doing something wrong or is this just an issue with the local prview since it's still in beta?
You can try using a different custom property, or you can also try using a stylesheet scoped to the LWC component.
The above code will apply the color to the lightning-icon component, and the stylesheet will only be scoped to your LWC component.
Note that the "Preview Component Locally" feature is still in beta, and you may encounter issues with it. In case the issue persists, you can try viewing the component within a Salesforce org or test it in a Sandbox environment.
This works for aura, but not for LWC. I have to use the styling hooks on utility icons in LWC for it to take effect.
But yes, I agree that I can just view it directly in salesforce. Was hoping to take advantage of the new feature out there, but sounds like this is a bug in the beta currently.