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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>63621</bug_id>
          
          <creation_ts>2011-06-29 05:28:39 -0700</creation_ts>
          <short_desc>REGRESSION: DOMNodeRemoved doesn&apos;t fire when removing text node in contenteditable</short_desc>
          <delta_ts>2012-06-03 00:22:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>HTML Editing</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>OS X 10.6</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Regression</keywords>
          <priority>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Erik Hesselink">hesselink</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>darin</cc>
    
    <cc>mjs</cc>
    
    <cc>ojan</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>429535</commentid>
    <comment_count>0</comment_count>
      <attachid>99076</attachid>
    <who name="Erik Hesselink">hesselink</who>
    <bug_when>2011-06-29 05:28:39 -0700</bug_when>
    <thetext>Created attachment 99076
Testcase showing the bug

In the attached test case:

  * Select the text &apos;foo&apos; by double clicking.
  * Press delete.

In the console you can now see that the text node containing &apos;foo&apos; has been removed, but no DOMNodeRemoved event has been fired (only DOMCharacterDataModified).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>429705</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-06-29 10:23:48 -0700</bug_when>
    <thetext>I can reproduce with ToT, but not with Safari/WebKit 5.0.5.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>429709</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2011-06-29 10:31:11 -0700</bug_when>
    <thetext>This is a behavioral change since http://trac.webkit.org/changeset/73690, and it&apos;s intentional.  The DOMNodeRemoved is fired for the node AFTER the node is removed from the document.  However, because the node does not have a parent after the removal, it appears as if the event was never fired if you just attach an event handler on some ancestor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>430301</commentid>
    <comment_count>3</comment_count>
    <who name="Erik Hesselink">hesselink</who>
    <bug_when>2011-06-30 03:06:12 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; This is a behavioral change since http://trac.webkit.org/changeset/73690, and it&apos;s intentional.  The DOMNodeRemoved is fired for the node AFTER the node is removed from the document.  However, because the node does not have a parent after the removal, it appears as if the event was never fired if you just attach an event handler on some ancestor.

I don&apos;t really understand what that changeset does exactly (an explanation would be appreciated), but the current behavior is undesirable for several reasons:

  * It violates the specification. Even though it is deprecated, this is the specification that has been implemented, and such small deviations are confusing and a recipe for bugs.
  * It is inconsistent. Most DOMNodeRemoved events still fire before removal.
  * It is hard to use. Monitoring a section of HTML (say, a contenteditable area) can now only be done by attaching event listeners to every node, which is a kind of web development antipattern.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>430417</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2011-06-30 08:05:13 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt;   * It violates the specification. Even though it is deprecated, this is the specification that has been implemented, and such small deviations are confusing and a recipe for bugs.

This is a willful violation of the spec.  We&apos;ve had many crashes and security vulnerabilities due to mutation events.

&gt;   * It is inconsistent. Most DOMNodeRemoved events still fire before removal.

Right.  We&apos;ll eventually do that to doo DOMNodeRemoved.  For example, adoptNode does the same.

&gt;   * It is hard to use. Monitoring a section of HTML (say, a contenteditable area) can now only be done by attaching event listeners to every node, which is a kind of web development antipattern.

On WebKit, you can use input event to monitor a contenteditable area. It&apos;s fired every time DOM is about to modify in the element.

Ultimately, we&apos;d like to get rid of mutation events. See &quot;Mutation events replacement&quot; on public-webapps.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>431131</commentid>
    <comment_count>5</comment_count>
    <who name="Erik Hesselink">hesselink</who>
    <bug_when>2011-07-01 06:57:06 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt;   * It is hard to use. Monitoring a section of HTML (say, a contenteditable area) can now only be done by attaching event listeners to every node, which is a kind of web development antipattern.
&gt; 
&gt; On WebKit, you can use input event to monitor a contenteditable area. It&apos;s fired every time DOM is about to modify in the element.
&gt; 
&gt; Ultimately, we&apos;d like to get rid of mutation events. See &quot;Mutation events replacement&quot; on public-webapps.

I&apos;ll give a little bit of background about what we are using DOM mutation events for. We are developing a web application which includes an html editor based on contenteditable. In this contenteditable we have user actions like typing, calls to execCommand and custom actions that modify the DOM directly.

We use DOM mutation events to basically keep a shadow DOM, which we use to have &apos;live&apos; computations on the DOM that automatically update on DOM changes in a performant way (i.e. without rescanning the entire document). This keeps our UI state correct, among other things.

We also have an automatic undo stack based on DOM mutation events. Each action on the DOM is wrapped in markers, and between these markers we track the events. We can then undo the individual events to undo the full action.

For both these applications (we have a few more, but these are the largest) we need the information and guarantees DOM mutation events give us. The &apos;input&apos; event doesn&apos;t give nearly enough information. The new spec probably also doesn&apos;t (I&apos;ll send an email to public-webapps soon), and also isn&apos;t available yet.

My worry is that these changes, which make it easier for you to fix bugs, keep breaking our application in unexpected ways. Do you have any high level overview of what you are planning to change, and when? This would really help us in ensuring our application will keep working on Safari and Chrome.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>431189</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2011-07-01 08:56:53 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; We use DOM mutation events to basically keep a shadow DOM, which we use to have &apos;live&apos; computations on the DOM that automatically update on DOM changes in a performant way (i.e. without rescanning the entire document). This keeps our UI state correct, among other things.
&gt; 
&gt; We also have an automatic undo stack based on DOM mutation events. Each action on the DOM is wrapped in markers, and between these markers we track the events. We can then undo the individual events to undo the full action.

One thing you can do is to attach DOMNodeRemoved event listener inside DONNodeInserted for each node.  That way, you&apos;ll know when a node is removed.

&gt; For both these applications (we have a few more, but these are the largest) we need the information and guarantees DOM mutation events give us. The &apos;input&apos; event doesn&apos;t give nearly enough information. The new spec probably also doesn&apos;t (I&apos;ll send an email to public-webapps soon), and also isn&apos;t available yet.

What I&apos;d like to do in the replacement for DOM mutation events is to send a list of DOM mutations such that you can construct undo and redo.  In fact, I&apos;ve been working on a brand new design/spec for UndoMananger and Transaction that help address your use case that I&apos;m planning to send out next week or so.

&gt; My worry is that these changes, which make it easier for you to fix bugs, keep breaking our application in unexpected ways. Do you have any high level overview of what you are planning to change, and when? This would really help us in ensuring our application will keep working on Safari and Chrome.

See discussions on https://bugs.webkit.org/show_bug.cgi?id=55666</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>640155</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-06-03 00:22:41 -0700</bug_when>
    <thetext>Given that we&apos;ve added mutation observers API, I don&apos;t think we&apos;ll ever fix this bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>99076</attachid>
            <date>2011-06-29 05:28:39 -0700</date>
            <delta_ts>2011-06-29 05:28:39 -0700</delta_ts>
            <desc>Testcase showing the bug</desc>
            <filename>ce.html</filename>
            <type>text/html</type>
            <size>1061</size>
            <attacher name="Erik Hesselink">hesselink</attacher>
            
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