Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderedCallback invoked excessively for light DOM components #4013

Open
nolanlawson opened this issue Feb 22, 2024 · 1 comment
Open

renderedCallback invoked excessively for light DOM components #4013

nolanlawson opened this issue Feb 22, 2024 · 1 comment
Labels
bug Up for grabs Issues that are relatively small, self-contained, and ready for implementation

Comments

@nolanlawson
Copy link
Contributor

Description

Consider this tree (note these are slotted components, not child components):

<x-grandparent>
  <x-parent>
    <x-child></x-child>
  </x-parent>
</x-grandparent>

For native shadow with synthetic lifecycle, native shadow with native lifecycle, and synthetic shadow, the renderedCallbacks are invoked once per component. However, for light DOM, the renderedCallback for both the <x-grandparent> and <x-parent> components are invoked twice each.

Steps to Reproduce

See StackBlitz links above.

Expected Results

One renderedCallback per component.

Actual Results

Multiple per component.

Full results

Native shadow, synthetic lifecycle

Component Lifecycle hook
grandparent connectedCallback
parent connectedCallback
child connectedCallback
child renderedCallback
parent renderedCallback
grandparent renderedCallback
grandparent disconnectedCallback
parent disconnectedCallback
child disconnectedCallback

Native shadow, native lifecycle

Component Lifecycle hook
grandparent connectedCallback
grandparent renderedCallback
parent connectedCallback
parent renderedCallback
child connectedCallback
child renderedCallback
grandparent disconnectedCallback
parent disconnectedCallback
child disconnectedCallback

Synthetic shadow

Component Lifecycle hook
grandparent connectedCallback
grandparent renderedCallback
parent connectedCallback
parent renderedCallback
child connectedCallback
child renderedCallback
grandparent disconnectedCallback
parent disconnectedCallback
child disconnectedCallback

Light DOM

Component Lifecycle hook
grandparent connectedCallback
parent connectedCallback
child connectedCallback
child renderedCallback
parent renderedCallback
grandparent renderedCallback
parent renderedCallback
grandparent renderedCallback
grandparent disconnectedCallback
parent disconnectedCallback
child disconnectedCallback
@nolanlawson nolanlawson added bug Up for grabs Issues that are relatively small, self-contained, and ready for implementation labels Feb 23, 2024
@nolanlawson
Copy link
Contributor Author

Marking this as "up for grabs" even though it may be tricky to implement due to backwards compatibility concerns. (I.e. someone could be relying on renderedCallback being executed multiple times – we've definitely seen this kind of thing before.)

The proper solution should:

  1. Ensure that each component only executes its renderedCallback once
  2. Have a sensible ordering. Native shadow, native lifecycle and Synthetic shadow are identical, so I would align on that.
  3. Use api-versioning.ts so that this is only enabled for the most recent API version. Otherwise we run the risk of breaking existing consumers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Up for grabs Issues that are relatively small, self-contained, and ready for implementation
Projects
None yet
Development

No branches or pull requests

1 participant