<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>21149</bug_id>
          
          <creation_ts>2013-02-28 00:25:33 +0000</creation_ts>
          <short_desc>[Shadow]: Shadow DOM-based components could benefit from a way to detect when light DOM contents change</short_desc>
          <delta_ts>2015-05-27 03:23:35 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>28552</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Jan Miksovsky">jan</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>dominicc</cc>
    
    <cc>ericbidelman</cc>
    
    <cc>hayato</cc>
    
    <cc>sjmiles</cc>
    
    <cc>sorvell</cc>
    
    <cc>travil</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83815</commentid>
    <comment_count>0</comment_count>
    <who name="Jan Miksovsky">jan</who>
    <bug_when>2013-02-28 00:25:33 +0000</bug_when>
    <thetext>Currently, a Shadow DOM-based component has no easy way to know when its own light DOM contents change. This hampers the ability to handle a number of common UI component scenarios.

Background: in evaluating Shadow DOM and custom element support in the QuickUI framework (http://quickui.org), it was discovered that Shadow DOM-based components don&apos;t have an easy way to receive notification when their light DOM contents change. Using the large existing QuickUI component library as a reference point, the ability to detect content changes appears to be a common need. See http://blog.quickui.org/2012/04/27/how-quickui-controls-use-code-to-specialize-the-handling-of-their-content-in-ways-that-might-not-be-supported-by-web-components/ for a summary of these scenarios. In QuickUI&apos;s case, approximately 25% of the UI components require some notification when their contents change, suggesting that many other components will have this requirement as well.

While a component can work around this by wiring up a Mutation Observer to its own host element, that is fairly cumbersome. Moreover, such an observer would catch more changes than may be strictly be interesting to the component. E.g., if a component is grabbing a specific subset of the light DOM nodes, then it only needs to know when those specific nodes change. (Here, &quot;change&quot; could be: the set of nodes change, or the contents of those nodes change.)

It would be beneficial if Shadow DOM-based components could more easily ask for notification when their contents change. I&apos;m not sure what the best form for this would be. I&apos;m also not sure whether this is best handled as a general Shadow DOM feature, or as a helper only available to custom elements. Custom elements already have an attributeChanged lifecycle method; perhaps there could also be a contentChanged lifecycle method.

I&apos;ve discussed this idea with Dimitri Glazkov in email, who asked me to file a spec bug to track it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83840</commentid>
    <comment_count>1</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2013-02-28 21:36:42 +0000</bug_when>
    <thetext>I was thinking about this problem recently. I think Mutation Observers would work well for this, something like:

var host = ...;

// Create ShadowRoot
var shadow = host.createShadowRoot();

// Populate ShadowRoot
var template = ...;
shadow.appendChild(template.content);

// Observe light DOM changes
var observer = new MutationObserver(function (mutations) {
  // Distribution may have changed; do imperative updates
  [].forEach.call(shadow.querySelectorAll(&apos;content&apos;), function (content) {
    // Use content.getDistributedNodes()
  });
});
observer.observe(host, { subtree: true, attributes: true, childList: true });

(This over-observes to make this code succinct, but it is possible to use two observers to observe precisely what changes can affect distribution.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90853</commentid>
    <comment_count>2</comment_count>
    <who name="Jan Miksovsky">jan</who>
    <bug_when>2013-07-17 17:39:21 +0000</bug_when>
    <thetext>I&apos;m working around this problem using an observer, but still feel like this is a general need. I&apos;ve just posted a bit about this at https://groups.google.com/forum/#!topic/polymer-dev/Pq00wMmuPIw.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118103</commentid>
    <comment_count>3</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2015-02-24 00:54:00 +0000</bug_when>
    <thetext>I also agree that this is a general need.

The current use-cases are all dealing with the problem from externally to the component, or from a POV where the host environment has full control/access to the shadowroot. In a possible world of more controlled isolation, especially where a component may only have limited access to its host, some form of change notifications would be handy. I don&apos;t have an idea of what these might look like, but the custom element&apos;s lifecycle methods could be a starting point...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119845</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-04-23 19:13:08 +0000</bug_when>
    <thetext>*** Bug 24861 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120528</commentid>
    <comment_count>5</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2015-05-27 03:23:35 +0000</bug_when>
    <thetext>Moved to https://github.com/w3c/webcomponents/issues/62</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>