W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2015

oldNode.replaceWith(...collection) edge case

From: Glen Huang <curvedmark@gmail.com>
Date: Fri, 16 Jan 2015 13:37:55 +0800
Message-Id: <BC932932-F251-4989-94FB-D1D843D36C16@gmail.com>
To: public-webapps@w3.org
Currently, for `oldNode.replaceWith(…collection)`, if `collection` is array of multiple nodes, and `oldNode` is in `collection`, after the mutation method macro,  `oldNode` lives in a doc frag. So in the replace algorithm, `parent` is the doc frag, `node` is also the doc frag, an `HierarchyRequestError` is thrown.

I wonder if an error really should be thrown in this case? Intuitively, `collection` should be inserted before `oldNode`’s original next sibling.

For example:

```
<div id="d1"></div>
<div id="d2"></div>
<div id="d3"></div>
<div id="d4"></div>
```

Imagine `oldNode` is #d2, `collection` is [#d1,#d2,#d4], executing `oldNode.replaceWith(…collection)` should give

```
<div id="d1"></div>
<div id="d2"></div>
<div id="d4"></div>
<div id="d3"></div>
```

Instead of throwing an error.

To make it this work, before executing the mutation method macro, `oldNode`’s parent should be saved. It’s next sibling should also be saved, but the next sibling need to be found recursively if it happens to be in `collection` too.

So, If I’m not wrong, this edge case could work in principle. I’m not sure if there is any interest to allow this?
Received on Friday, 16 January 2015 05:38:27 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:25 UTC