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 23839 - [Custom]: Template document should not share registry with its document
Summary: [Custom]: Template document should not share registry with its document
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14968
  Show dependency treegraph
 
Reported: 2013-11-15 19:59 UTC by Dimitri Glazkov
Modified: 2014-05-09 19:44 UTC (History)
4 users (show)

See Also:


Attachments

Description Dimitri Glazkov 2013-11-15 19:59:46 UTC
This was brought up by the Polymer team. In their custom elements, they have to special-case custom element being in a template and short-circuit their "created" callbacks to provide impression of "inertness".

Also brought up here: http://techblog.ironfroggy.com/2013/11/5-reasons-web-components-arent-ready.html (see missing item 3).

This seems like a common pattern, and it's easily rectified by removing the line in spec where we share the registry with the template document.
Comment 1 Dimitri Glazkov 2013-11-15 20:01:08 UTC
The effect of this change would be that the elements are never upgraded or have their callbacks fired while in templates.
Comment 2 Dominic Cooney 2013-11-18 23:54:10 UTC
Two questions:

1. The link mentions in Comment 1 mentions initializers running in templates; this proposal is to not share a registration context at all and hence not run any callbacks. Is not doing any prototype swizzling/callbacks just the logical consequence of not running the initializer?

2. If the registration context is not shared, does the template document get a blank registration context ('register' will work when used on a template document) or not? ('register' will throw when used on a template document.)
Comment 3 Dimitri Glazkov 2013-11-18 23:59:56 UTC
(In reply to Dominic Cooney from comment #2)
> Two questions:
> 
> 1. The link mentions in Comment 1 mentions initializers running in
> templates; this proposal is to not share a registration context at all and
> hence not run any callbacks. Is not doing any prototype swizzling/callbacks
> just the logical consequence of not running the initializer?

Right.

> 2. If the registration context is not shared, does the template document get
> a blank registration context ('register' will work when used on a template
> document) or not? ('register' will throw when used on a template document.)

Just a blank registration context. Technically, it's not blank. When we spec the Registry object API, we'll say that at the time of creating a template document, we pour all of the built-in HTML element definitions into this context (just like with a Document created with XHR). The authors should be able to do the same type of sharing with their elements using that API.
Comment 5 Adam Klein 2013-11-20 22:50:34 UTC
As currently specced in HTML, <template> doesn't always create a new Document for its content fragment; if its ownerDocument lacks a defaultView, it assumes it's fine to re-use that one. This handles the case:

<template>
  <template>
    ...

so that each <template> doesn't cause the creation of a new Document. However, with this spec change, it's now possible to see different Custom Element behavior in a <template> that happens to be in a Document created via document.implementation.createHTMLDocument(), since:

doc = document.implementation.createHTMLDocument('title')
template = doc.createElement('template')
template.ownerDocument === template.content.ownerDocument

In such documents, custom elements inside templates will be "alive". The right fix is likely to tighten <template>'s requirements for when it will re-use its ownerDocument, i.e., only re-use ownerDocument if it's actually the content owner document of another <template>. This requires tagging template content documents upon creation.

I intend to file the above against the HTML spec, but I wanted to have an explanation written down here, too, since it was this bug report that requires the change to <template>'s behavior.
Comment 6 Dominic Cooney 2014-02-20 23:30:29 UTC
I think that change might have gone too far, now template documents don't have a registry at all. I think they should have a registry, but it should not be shared with the main document.
Comment 7 Dimitri Glazkov 2014-05-08 21:02:32 UTC
(In reply to Dominic Cooney from comment #6)
> I think that change might have gone too far, now template documents don't
> have a registry at all. I think they should have a registry, but it should
> not be shared with the main document.

PTAL? https://github.com/dglazkov/webcomponents/pull/1