Skip to content

LitTemplate restrictions on render() not documented, prevents use of several LitElement features #17455

Open

Description

@jflamy-dev

Description of the bug

The render() function in a LitElement template can apparently only contain a html template.
This effectively prevents using the LitElement styleMap and classMap features.

Expected behavior

It should be possible to write code like the following, where the call to render re-evaluates what styles and classes are to be applied.

 render() {  
    const athleteTimerStyles = { 
      display:  this.currentAthleteMode && !this.decisionVisible ? "grid" : "none",
    }
    return html`
      <div>
        test
      </div>
      <div class="timer athleteTimer" style="${styleMap(athleteTimerStyles)}">
        <timer-element id="athleteTimer"></timer-element>
      </div>
      `;
  }

Please document this restriction clearly -- no variables can be computed in render().
For example this restriction prevents constructing a LitElement template in JavaScript by assembling subpieces
https://lit.dev/docs/templates/expressions/#templates
Maybe the restriction could be on the elements that need to be visible with @id that need to be at top level so JSoup can see them.

Minimal reproducible example

See above. Add variables before the html backtick.

Versions

Vaadin: 24.1.4
Flow: 24.1.5
Java: JetBrains s.r.o. 17.0.6
OS: amd64 Windows 11 10.0
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203

Activity

  1. changed the title [-]LitTemplate restrictions on render() not documented, prevent use of styleMap and classMap built-ins.[/-] [+]LitTemplate restrictions on render() not documented, prevents use of several LitElement features[/+] on Aug 15, 2023
  2. caalador commented on Aug 16, 2023

    @caalador
    Contributor

    The variables issue is just that it was an use case that was not known at the time and no one has used that so far.
    Added a fix pr to support those.
    On the templates usage it should be fine as long as the @Id elements are in the main render html.

  3. moved this to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenanceon Sep 20, 2023
  4. moved this to 🅿️Parking lot - under consideration in Vaadin Flow | Hilla | Kits ongoing workon Sep 28, 2023
  5. added theissue type on Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions