Skip to content

render() not called after property changes during render() #800

@simonfuhrmann

Description

@simonfuhrmann

Description

I am experiencing that a property change is not reflected (e.g., render() is not called after the property changed) if the property change is the result of an action that happens during render(). See Live Demo below.

Basically, during render() certain side-effects will happen, e.g., new elements get attached to or removed from the DOM. When elements get attached to the DOM, connectedCallback() of child elements gets executed. Which in turn can emit events to notify the parent about state. Which in turn can be responsible for changing properties in the parent component. These property changes are not reflected.

I am not sure if this is an intentional design decision to prevent infinite render() recursion, but I found this very surprising, dispatching events in connectedCallback() seems a reasonable thing to do. If dispatching these events in firstUpdated(), the property change is reflected as expected. However, this can also cause potential infinite loops.

Live Demo

I hope the following example will illustrate the issue:
https://stackblitz.com/edit/u25pbw (open the console!)

Browsers Affected

  • All

Versions

  • lit-element: v2.2.1
  • webcomponents: v2.2.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions