W3C home > Mailing lists > Public > www-svg@w3.org > January 2010

Re: removeChild and <use> question

From: Jeff Schiller <codedread@gmail.com>
Date: Tue, 12 Jan 2010 15:08:29 -0600
Message-ID: <da131fde1001121308w79e5d3d5qdb45b7f872cee48c@mail.gmail.com>
To: Patrick Dengler <patd@microsoft.com>
Cc: "www-svg@w3.org" <www-svg@w3.org>
I am not a member of the SVG WG, so I apologize if this is out of line.

Personally I find it surprising that Firefox and Opera do this.
removeChild() is a DOM Level 2 method and it seems like there
shouldn't be any side-effects for removing a child other than...
removing the child :)

It seems like in Opera/Firefox, the following code:

    var someUsePointingToFoo = ...;
    g.removeChild(foo);

would result in someUsePointingToFoo still holding a reference to a
<use> element, but it is now detached from the DOM, which developers
might not expect.

On the other hand, this is annoying for developers to then find all
the <use> elements that were referencing that element and then either
remove them or point them to some other element. I also can see why
UAs decided to do this, since otherwise it would leave the document in
some sort of error state.

Then I went digging and found this:
http://www.w3.org/TR/2005/WD-SVGMobile12-20050413/svgudom.html#dom::Node_removeChild
(which is an old draft of SVGT 1.2 that talks about this very issue
and goes a different way).

Seems like this problem is unique to SVG since HTML doesn't have such concepts.

So in short, I am curious to hear what the decision will be :)

Regards,
Jeff Schiller

On Tue, Jan 12, 2010 at 1:59 PM, Patrick Dengler <patd@microsoft.com> wrote:
> We've looked at the <use> and removeChild() together.  Specifically, what is supposed to happen to a 'use' instance when removeChild() is called on the parent of the element that's being use'd?
>
> We see different behaviors across browsers. We think that both the original element and the 'use' instance should be removed. This is what Firefox and Opera do. Is this the correct behavior?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Full//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat.dtd">
> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.1" baseProfile="full" id="svg-root" width="100%" height="100%" viewBox="0 -10 480 360" contentScriptType="text/javascript" onload="foo()">
>    <script>
>        function foo()
>        {
>            var gElem = document.getElementById("gElem");
>            var rectElem = document.getElementById("rectElem");
>            var useElem = document.getElementById("useElem");
>            gElem.removeChild(rectElem);
>        }
>
>
>    </script>
> <g id="gElem">
>    <rect x="96px" y="96px" width="96px" height="96px" fill="green" id="rectElem" />
> </g>
> <use xlink:href="#gElem" x="96px" y="96px" width="96px" height="96px" id="useElem" />
> </svg>
>
> Thanks in advance.
>
> Patrick Dengler
> Senior Program Manager, Microsoft
> Internet Explorer
>
>
Received on Tuesday, 12 January 2010 21:09:02 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:44 GMT