This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24570 - [Custom]: Callback for cloneNode/importNode
Summary: [Custom]: Callback for cloneNode/importNode
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
: 27420 (view as bug list)
Depends on:
Blocks: 14968
  Show dependency treegraph
 
Reported: 2014-02-06 22:51 UTC by Erik Arvidsson
Modified: 2015-07-06 08:13 UTC (History)
6 users (show)

See Also:


Attachments

Description Erik Arvidsson 2014-02-06 22:51:41 UTC
Built in elements like inputs have hooks for cloning data that is not represented as children or attributes.

Strawman:

Add a cloneNodeCallback, which gets called after the element has been called, with a the original element as the context object and the new node as the only argument.

Then HTMLInputElement could be implemented as:

document.registerElemetn('input', {
  prototype: {
    __proto__: HTMLElement.prototype,
    cloneNodeCallback: function(newNode) {
      newNode.value = this.value;
    }
  }
});
Comment 1 Anne 2014-02-07 13:59:04 UTC
Are you also suggesting that browsers refactor their current implementation of <input> to do this copying at the point this callback would normally happen? As currently it happens synchronously.

The difference would be observable if you have a mixture of custom and normal elements. A similar question applies to base URL changes in 24577. (I'm assuming when adopting we'll just change the node document of a custom element ourselves.)
Comment 2 Anne 2014-02-10 11:15:26 UTC
Note that this callback should be modeled after http://dom.spec.whatwg.org/#concept-node-clone-ext and take the same arguments. If that is not feasible for some reason I'd like to know why. We should try to refactor that callback to run just before the method call that caused the cloning to return so custom and normal elements have the same processing.
Comment 3 Anne 2014-02-10 11:27:25 UTC
Hmm, HTML's cloning steps for <script> cannot be done from a callback I think. Insertion has already happened at the point the callback is supposed to run and insertion triggers "prepare a script" which checks "already started" which is part of what is to be cloned.

So these hooks would not be good for <script>...
Comment 4 Erik Arvidsson 2014-02-10 15:31:15 UTC
I was in a rush when filing this. Conceptually I think we need to be able to explain how the built ins work in this area but I didn't think much about it at the time.

I agree that http://dom.spec.whatwg.org/#concept-node-clone-ext is the concept we want to achieve.

I'm not sure why you think "insertion has already happened". I think the order would be something more aligned to.

New Node - Created Callback
Old Node - Cloning Step Callback
...
New Node - Attached Callback (if ever inserted into a document)

I think the above would work for script. The cloning step would copy the "already started" flag and the attached callback would check if it set.

The semantics of this callback would be to call it as a last step of http://dom.spec.whatwg.org/#concept-node-clone and call the callbacks in document order in the cloned tree, passing the old node as the context object and the new node as the only argument (the document can be reached through ownerDocument if needed).
Comment 5 Anne 2014-02-10 15:45:41 UTC
You're right. I was confusing this with adoption.

It seems I can get rid of /document/. /clone children flag/ seems to be used by <template>.

The callbacks needs to be queued as cloning is also used by range operations and we do not want to run script during those operations I think (but rather just before they return). Queuing them at the current point seems to take care of the recursion automatically.
Comment 6 Erik Arvidsson 2014-02-10 16:27:46 UTC
(In reply to Anne from comment #5)
Queuing them at the current point seems to take
> care of the recursion automatically.

Yup, I believe we can use the same timing as we have for createElement/createdCallback.
Comment 7 Jelte Liebrand 2014-08-04 23:10:01 UTC
Hey guys,

Just wondering if this is still on the cards? I'm just running in to similar issues of not being able to hook in to the cloneNode, so curious to see if this will get resolved in the near future or if I should continue to jump through some hacky loops?

/Cheers,
Jelte
Comment 8 Anne 2014-08-05 08:08:24 UTC
Well, we'll need to sort this out one way or another if we want "Blink-in-JS" and custom elements in general to succeed. So yes.
Comment 9 Adam Klein 2014-11-24 18:26:12 UTC
*** Bug 27420 has been marked as a duplicate of this bug. ***
Comment 10 Hayato Ito 2015-07-06 08:13:28 UTC
Moved to https://github.com/w3c/webcomponents/issues/176