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

Synthetic lifecycle observable changes when slotted into native lifecycle #4249

Open
nolanlawson opened this issue Jun 2, 2024 · 0 comments
Labels

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented Jun 2, 2024

TL;DR: No matter what, there will be some observable difference if a synthetic-lifecycle component is slotted into a native-lifecycle component.

As demonstrated by #4248, we have some issues where we have incorrect behavior when a synthetic lifecycle component is slotted into a native lifecycle component. In particular, its disconnectedCallback may be invoked without a corresponding connectedCallback (for a true case of disconnect+reconnect).

We can fix these bugs, but I think there will still be cases where we can't perfectly emulate the old pure-synthetic-lifecycle behavior for synthetic-lifecycle components in a mixed context. For example:

<!-- slottable.html -->
<template lwc:if={foo}>
  <slot></slot>
</template>
// slottable.js
renderedCallback() {
  this.foo = true
}
<!-- container -->
<x-slottable> <!-- native lifecycle -->
  <x-slottee></x-slottee> <!-- synthetic lifecycle -->
</x-slottable>

In this case, a synthetic-lifecycle component is being slotted into a native-lifecycle component. However, the outer component is changing its state within its renderedCallback, which affects how the inner component is mounted/unmounted. (I used renderedCallback, but I could have also used disconnectedCallback/connectedCallback.)

The point is that the outer component has changed the timing of its state changes due to native lifecycle. Necessarily, the inner component will be unmounted/mounted based on the native timing, not the synthetic timing it expects. For example, the outer component could be inside of a list which is re-sorted, triggering a disconnect+reconnect, which the inner component may not be expecting.

So no matter what, there will be some observable difference if a synthetic-lifecycle component is slotted into a native-lifecycle component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant