lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Move LWC Custom Element registration out of the global custom element registry

Open aputinski opened this issue 4 years ago • 5 comments

Description

When the engine inserts an element with a tag name that has already been registered in the customElements registry the following error is thrown: [object:vm Child (1)] cannot be recycled

Steps to Reproduce

https://playground.lwcjs.org/projects/cRmyBtcP8/1/edit

Expected Results

No error is thrown

Actual Results

[object:vm Child (1)] cannot be recycled

aputinski avatar Jan 15 '21 18:01 aputinski

The problem here is that the LWC component is registered as a web component, but used from a template. In that case, we have the protections for the construction, in the case of a registered web component, it simply ignores the upgrade callback because its super will take care of the createVM, after construction, we know whether or not it is associated to a vm, and do some LWC specific work. All that works fine, but problem is when inserting it.

When inserting it, insertNodeHook is invoked, which runs the DOM operation to connect the element, when that happens, for a registered web component, it will kick off the connectedCallback, as a result, it will update the state of the vm to connected. After that operation, we have no way to know that this has happened already, and we go into the process of carry on the same thing again, hitting the issue.

This issue is subject to disappear once we finish the work on node reactions: https://github.com/salesforce/lwc/pull/2032/files, at that point, we will never need to carry on this check, and the insert flow will be just to invoke the insertNodeHook and nothing else, because whether it is a registered or not, the callback will take care of it.

caridy avatar Jan 15 '21 23:01 caridy

Is this issue the same as W-9114253 ?

nolanlawson avatar Jun 24 '21 21:06 nolanlawson

Yes.

ravijayaramappa avatar Jun 25 '21 00:06 ravijayaramappa

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

uip-robot-zz avatar Jun 25 '21 16:06 uip-robot-zz

This should be solved by #2724

nolanlawson avatar Aug 08 '22 23:08 nolanlawson