salesforce / lwc

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

lwc:external Expressions inside lit-element render() is not rendered. #4478

Closed tsaranya88 closed 1 month ago

tsaranya88 commented 1 month ago

I am trying to integrate a LIT web-component inside salesforce LWC component using lwc:external. The LIT web component renders fine on its own but when trying to integrate with salesforce using lwc:external it doesn't render any of the expressions inside the HTML

When I put console log in connectedCallback all the properties and state values are printing properly in the console. But it never gets rendered in the HTML.

import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { state } from 'lit-element';

@customElement('example-component')
export class ExampleComponent extends LitElement {
        static shadowRootOptions = {...LitElement.shadowRootOptions, mode: <ShadowRootMode>'closed'};

       @property({ attribute: 'title', reflect: true }) title;

       dateVal;

      constructor() {
        super();
        console.log('constructor');
        this.title = 'Setting a Title';
      }

      connectedCallback() {
        super.connectedCallback();
        console.log('connected callback');
        console.log('appTitle: ' + this.title);
        console.log('Date: ' + this.getCurrentDateLabel());
      }

    render() {
        console.log('In render ' + this.title);
        return html`
            <div style="text-align: center; background: black; padding: 25px; color: white">
              <h1 class="app-title">${this.title}</h1>
              <h1>${this.getCurrentDateLabel()} </h1>
              <h1>${this.dateVal}</h1>
              <p>Edit the code and save to reload.</p>
              <a
                class="app-link"
                href="https://lit.dev/docs/"
                target="_blank"
                rel="noopener noreferrer">
                Lit Documentation
              </a>
            </div>
          </main>
        `;
      }

      private getCurrentDateLabel() {
        const now = new Date();
        this.dateVal = now;
        return now;
  }
}

Could someone please help me what I could be missing here?

nolanlawson commented 1 month ago

During internal testing of Lit, we found that there are incompatibilities between how Lit renders and how Lightning Web Security works. Currently our plan is to GA third-party web components (i.e. lwc:external) in Spring '25, which should include support for Lit components.

I'm sorry for the inconvenience.