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

Use native connectedCallback/disconnectedCallback lifecycle hooks #3198

Closed
nolanlawson opened this issue Nov 23, 2022 · 1 comment · Fixed by #3904
Closed

Use native connectedCallback/disconnectedCallback lifecycle hooks #3198

nolanlawson opened this issue Nov 23, 2022 · 1 comment · Fixed by #3904
Labels

Comments

@nolanlawson
Copy link
Contributor

nolanlawson commented Nov 23, 2022

We use non-standard mechanisms to trigger connectedCallback/disconnectedCallback. We should just use the native mechanism instead.

// Monkey patching Node methods to be able to detect the insertions and removal of root elements
// created via createElement.
const { appendChild, insertBefore, removeChild, replaceChild } = _Node.prototype;
assign(_Node.prototype, {
appendChild(newChild) {
const appendedNode = appendChild.call(this, newChild);
return callNodeSlot(appendedNode, ConnectingSlot);
},
insertBefore(newChild, referenceNode) {
const insertedNode = insertBefore.call(this, newChild, referenceNode);
return callNodeSlot(insertedNode, ConnectingSlot);
},
removeChild(oldChild) {
const removedNode = removeChild.call(this, oldChild);
return callNodeSlot(removedNode, DisconnectingSlot);
},
replaceChild(newChild, oldChild) {
const replacedNode = replaceChild.call(this, newChild, oldChild);
callNodeSlot(replacedNode, DisconnectingSlot);
callNodeSlot(newChild, ConnectingSlot);
return replacedNode;
},
} as Pick<Node, 'appendChild' | 'insertBefore' | 'removeChild' | 'replaceChild'>);

This has implications for backwards compat, because the timing and other subtleties will be different.

Related: #2609, #1102, #2709

Also related: #2986 which added a flag, without making the flag true by default.

@git2gus
Copy link

git2gus bot commented Nov 23, 2022

This issue has been linked to a new work item: W-12114614

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