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

test: add tests for new behavior with native lifecycle invocations #4248

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

jmsjtu
Copy link
Member

@jmsjtu jmsjtu commented May 31, 2024

Details

With the introduction of native lifecycle, we're observing new behavior when an element is moved inside the DOM.

This PR adds some tests to verify the current behavior.

Does this pull request introduce a breaking change?

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

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

@jmsjtu jmsjtu requested a review from a team as a code owner May 31, 2024 21:39
Comment on lines +37 to +48
elm.toggleSpans();
await Promise.resolve();
assertSlottedChildrenLength(elm, 1);
expect(window.timingBuffer.length).toBe(6);
expect(window.timingBuffer[3]).toBe(
'x-use-api-version-61-sloter: disconnectedCallback'
);
// Notice x-use-api-version-60-slotee disconnectedCallback is fired but not its connectedCallback
expect(window.timingBuffer[4]).toBe(
'x-use-api-version-60-slotee: disconnectedCallback'
);
expect(window.timingBuffer[5]).toBe('x-use-api-version-61-sloter: connectedCallback');
Copy link
Member Author

@jmsjtu jmsjtu May 31, 2024

Choose a reason for hiding this comment

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

When the sloter is moved, the browser will fire the native disconnectedCallback which will disconnect the entire subtree.

The browser will then call native connectedCallback which runs through rehydration > VDOM diffing to determine if it should unmount/mount/patch any of the elements.

Since the sloter's subtree structure hasn't changed (slotee hasn't changed), the engine determines there's no need to do anything and moves on.

The browser will then call the slotee's native connectedCallback but since it's using synthetic lifecycle (apiVersion = 60 ) it will skip invoking.

We're left with the subtree having disconnectedCallback invoked but not a follow up connectedCallback.

We're observing 2 issues with this:

  1. Customer rely on these lifecycle methods to set state in their component which are being invoked differently from before.
  2. We're seeing wire adapters disconnecting and not being reconnected.

@nolanlawson
Copy link
Collaborator

Because of #4249 I doubt we will keep trying to do native custom element lifecycle via API versioning. But it is good to know what the current behavior is.

@jmsjtu jmsjtu merged commit dcba971 into master Jun 3, 2024
10 checks passed
@jmsjtu jmsjtu deleted the jtu/native-lifecycle-tests branch June 3, 2024 18:42
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.

None yet

2 participants