lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Use native connectedCallback/disconnectedCallback lifecycle hooks

Open nolanlawson opened this issue 1 year ago • 3 comments

Currently LWC does not use the native custom element lifecycle hooks. Instead, we do global DOM patching:

https://github.com/salesforce/lwc/blob/3cb07f92c7b97c348db799665fda3efe9408678a/packages/%40lwc/engine-dom/src/apis/create-element.ts#L40-L62

To better align with native browser behavior and to avoid global patching, we should use native lifecycle hooks. This would also resolve several bugs, e.g. https://github.com/salesforce/lwc/issues/2609, https://github.com/salesforce/lwc/issues/1102, https://github.com/salesforce/lwc/pull/2709

Probably this would need to be done with a feature flag, so that we don't break existing users who may have made assumptions about timing/ordering of certain callbacks.

nolanlawson avatar Aug 04 '22 23:08 nolanlawson

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

git2gus[bot] avatar Aug 04 '22 23:08 git2gus[bot]

This is supposed to be enabled by the #2724, which will allow us to eventually activate these one at a time.

caridy avatar Aug 05 '22 20:08 caridy

@caridy I thought the same thing, but ultimately it looks like it's orthogonal. We can solve one, the other, or both. In #2724 we are still using the synthetic connectedCallback/disconnectedCallback events. Unless I misunderstood something?

nolanlawson avatar Aug 05 '22 21:08 nolanlawson