Skip to content

[RRFC] Reduce the need to understand and mitigate Lit's asynchronous update model. #27

@sorvell

Description

@sorvell
  • [X ] I searched for an existing RRFC which might be relevant to my RRFC

Motivation

Standard platform behavior for elements is that they update synchronously after being mutated. If an element's textContent is set in such a way that its height would change, checking offsetHeight on the element is synchronously valid.

For efficiency, Lit elements update asynchronously and do not have this guarantee. Instead, users must await element.updateComplete to ensure any pending work is completed.

This is often not a problem because all updates are complete at task timing and before painting via await new Promise(requestAnimationFrame). However, it comes up in some cases and can be hard to deal with. In addition, if updateComplete is awaited, this does not reflect the status of any nested Lit elements unless users explicitly implement the promise to do so.

To mitigate this behavior, a mixin can be provided which does 2 things:

  1. updating the element synchronously makes the element's entire shadow subtree update.
  2. any element properties will ensure any pending update is synchronously completed before returning their current value.

How

Here is a prototype implementing the two proposed behaviors via a ReactiveManager mixin.

  1. it tracks child elements updated as a result of an element itself updating, and ensure they also update before the element's update is finished.
  2. it customizes reactive property accessors so that gets call performUpdate before returning their value, being careful not to do so during actual rendering.

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