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

fix: fix light dom slot forwarding bug #4452

Merged
merged 11 commits into from
Aug 21, 2024
Merged

Conversation

nolanlawson
Copy link
Collaborator

@nolanlawson nolanlawson commented Aug 8, 2024

Details

Fixes #4446, partially reverts #4258.

The main thing this PR does is revert us from the 252 behavior to the 250 behavior, while also adding additional code to ensure that disconnectedCallback fires correctly. The bulk of what you need to know is in the code comments.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🔬 Yes, it does include an observable change.

The ordering of disconnectedCallbacks firing in light DOM may change when using slot forwarding.

@nolanlawson nolanlawson marked this pull request as ready for review August 9, 2024 19:01
@nolanlawson nolanlawson requested a review from a team as a code owner August 9, 2024 19:01
// tree causes the slotter to unmount, then the slottable will also unmount. So using the
// current VM works either way.
if (isVCustomElement(vnode)) {
addVNodeToChildLWC(clonedVNode as VCustomElement);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change.

Copy link
Collaborator Author

@nolanlawson nolanlawson Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the order of disconnectedCallbacks firing has changed, when light DOM slot forwarding is enabled. I could not manage to get it to fire in exactly the same order as it did before.

I think this not a super-serious observable change – most of the time, disconnectedCallback ordering doesn't matter as much as connectedCallback ordering. This is because dC is mostly used for simple teardowns, whereas cC may be used to fire events that should be caught by the container. (dC cannot fire events because the element is disconnected from the DOM.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, the original issue with cloning vnodes was disconnectedCallback not firing, so I think it should be fine as long as it's being called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is why I added a test – should invoke connectedCallback/disconnectedCallback at all. It's more important that disconnectedCallback actually fires than that it fires in a particular order.

'12:connectedCallback',
'4:disconnectedCallback',
]
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a bugfix – we are now correctly firing the expected disconnectedCallbacks in synthetic lifecycle mode.

'9:disconnectedCallback',
'4:disconnectedCallback',
]);
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't strictly need to add any remove entire element tests here, but I wanted to cover all my bases.

@jmsjtu
Copy link
Member

jmsjtu commented Aug 9, 2024

I think this should also resolve #3731

@nolanlawson
Copy link
Collaborator Author

nolanlawson commented Aug 9, 2024

I think this should also resolve #3731

Unfortunately I tested it out, and it looks like #3731 is still not resolved by this PR. 😞

Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞

@nolanlawson nolanlawson merged commit bafc2ad into master Aug 21, 2024
11 checks passed
@nolanlawson nolanlawson deleted the nolan/light-dom-slot-bug-fix branch August 21, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Light DOM slot forwarding fails to render for duplicated slot names
3 participants