- From: Isiah Meadows <notifications@github.com>
- Date: Sun, 09 Aug 2020 03:16:55 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/880/671033686@github.com>
Question: would it be web-compatible to do this, or would this be too breaking? Add the following operation to [trees](https://dom.spec.whatwg.org/#trees): > To **move** a child within a tree to a given index is to move the child within the tree's children from its current position to before the item in the tree's children with the given index prior to moving, without adding or removing. If the index is the size of the tree's children, this moves it to the end of the tree instead. > > To **move** a child within a tree to the end is to move the child within the tree's children from its current position to after its last child, without adding or removing. > > > Note: moves can only be performed whenever the child is a child of that tree, and by extension, moves cannot be performed on trees with empty children. *This is just spec jargon for "don't do things that happen when you add or remove elements". In implementations, this would still necessitate removing and then re-adding, but only as an implementation detail.* Amend the [adopt](https://dom.spec.whatwg.org/#concept-node-adopt) algorithm to this: > To adopt a *node* into a *document* with a given *parent*, run these steps: > > 1. Let *oldDocument* be *node*'s node document. > 2. If *node*'s parent is not *parent*, then remove *node*. > 3. If *document* is not *oldDocument*, then: > [...] Amend step 4 of [`document.adoptNode(node)`](https://dom.spec.whatwg.org/#dom-document-adoptnode) likewise to pass a *parent* of null. Replace steps 7.2-7.3 of [insert](https://dom.spec.whatwg.org/#concept-node-insert) with the following: > 2. If *node*'s parent is *parent*, then: > 1. If *child* is non-null, then move *node* within *parent* to *child*'s index. > 2. Otherwise, move *node* within *parent* to the end. > 3. Otherwise, if *child* is null, then append *node* to *parent*'s children. > 4. Otherwise, insert *node* into *parent*'s children before *child*'s index. Amend step 11 of [replace](https://dom.spec.whatwg.org/#concept-node-replace) to be this: > 11. If *child*'s parent is not *parent*, then: > [...] Amend [replace all](https://dom.spec.whatwg.org/#concept-node-replace-all) to move children rather than removing them if their parents are *parent* (as defined in the algorithm), and update its callees like `.replaceChildren(...nodes)` and `.textContent` appropriately. > The precise update needed is omitted as it would be rather involved and would span multiple otherwise unrelated algorithms, but that's because the removal would need moved from `.replaceChildren(...)` to the core algorithm, and in order to do that, the algorithm itself would need to change from operating on a single node at a time to operating on a *list* of nodes (what it should've been using the whole time IMHO). ----- To assess risk, you would want to check for elements that 1. are being moved under the same parent, 2. have active transitions or animations, and 3. didn't have their styles synchronously calculated (for `.getBoundingClientRect()`, used with FLIP list transitions) within the current rendering frame. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/880#issuecomment-671033686
Received on Sunday, 9 August 2020 10:17:08 UTC