-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce moveBefore()
state-preserving atomic move API
#1307
base: main
Are you sure you want to change the base?
Conversation
moveBefore()\
state-preserving atomic move APImoveBefore()
state-preserving atomic move API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the mutation record needs some more design work. I would expect it to capture the information of a remove and an insert at the same time. Perhaps it needs to be a new object, though we could further overload the existing MutationRecord
as well I guess. At least I think you need:
- old target
- target
- moved node (I'm not sure you can ever move multiple at this point, but maybe we should allow for it in the mutation record design?)
- old previous sibling
- old next sibling
- previous sibling
- next sibling
Would be good to know what @smaug---- thinks and maybe @ajklein even wants to chime in.
Shouldn't the target node be all the time the same, it is just the siblings which change. If this is really just remove and add back elsewhere, we could just reuse the existing childList MutationRecords, one for remove, one for adding node back, and possibly just add a flag to MutationRecord that it was about move. (movedNodes is a bit confusing, since it seems to depend on the connectedness of the relevant nodes and it is apparently empty for the removal part. And it is unclear to me why we need the connectedness check. This is about basic DOM tree operations, and I'd assume those to work the same way whether or not the node is connected) |
Creating two separate mutation records that a consumer would have to merge to (fully) understand it's a move seems suboptimal? I agree that it should probably work for disconnected nodes as well, but I don't think we want to support a case where the shadow-including root changes. |
It's been a long time since I've thought about this stuff, but I'm inclined to agree with @smaug---- that creating a new type of |
This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92
This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935350 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1369303}
This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935350 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1369303} Co-authored-by: Dominic Farolino <[email protected]>
…-move validity checks, a=testonly Automatic update from web-platform-tests DOM: Make moveBefore() throw for all pre-move validity checks (#48642) This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935350 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1369303} Co-authored-by: Dominic Farolino <[email protected]> -- wpt-commits: 06b6ff6579327f235fff80b0f8bae8b0bbbc1069 wpt-pr: 48642
…-move validity checks, a=testonly Automatic update from web-platform-tests DOM: Make moveBefore() throw for all pre-move validity checks (#48642) This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935350 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1369303} Co-authored-by: Dominic Farolino <[email protected]> -- wpt-commits: 06b6ff6579327f235fff80b0f8bae8b0bbbc1069 wpt-pr: 48642
…-move validity checks, a=testonly Automatic update from web-platform-tests DOM: Make moveBefore() throw for all pre-move validity checks (#48642) This CL makes moveBefore() match the spec PR [1], with regard to the agreed-upon error-throwing behavior for all pre-moving validity and hierarchy conditions. This means throwing an exception for: - Disconnected parent destination or move target - Cross-document Nodes - Destination parent that is not an Element node - Move target that is not an Element or character data [1]: whatwg/dom#1307 [email protected] Bug: 40150299 Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935350 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1369303} Co-authored-by: Dominic Farolino <[email protected]> -- wpt-commits: 06b6ff6579327f235fff80b0f8bae8b0bbbc1069 wpt-pr: 48642
This CL enables moveBefore() inside connected ShadowRoot DocumentFragments, as the general only-Element-node target parent pre-condition was too strict, and disabled this case, despite it being a pretty valid one. This was discussed in whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440da
This CL enables moveBefore() inside connected ShadowRoot DocumentFragments, as the general only-Element-node target parent pre-condition was too strict, and disabled this case, despite it being a pretty valid one. This was discussed in whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440da Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6012161 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1381208}
This CL enables moveBefore() inside connected ShadowRoot DocumentFragments, as the general only-Element-node target parent pre-condition was too strict, and disabled this case, despite it being a pretty valid one. This was discussed in whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440da Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6012161 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1381208}
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). [email protected] Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). [email protected] Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). R=nrosenthalchromium.org Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <domchromium.org> Reviewed-by: Noam Rosenthal <nrosenthalchromium.org> Cr-Commit-Position: refs/heads/main{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603 UltraBlame original commit: d964e73cee7b89a9e21d8d4ccb3ffb0a8b5ac913
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). R=nrosenthalchromium.org Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <domchromium.org> Reviewed-by: Noam Rosenthal <nrosenthalchromium.org> Cr-Commit-Position: refs/heads/main{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603 UltraBlame original commit: d964e73cee7b89a9e21d8d4ccb3ffb0a8b5ac913
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). R=nrosenthalchromium.org Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <domchromium.org> Reviewed-by: Noam Rosenthal <nrosenthalchromium.org> Cr-Commit-Position: refs/heads/main{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603 UltraBlame original commit: d964e73cee7b89a9e21d8d4ccb3ffb0a8b5ac913
…s, a=testonly Automatic update from web-platform-tests moveBefore: fail when moving across roots This applies the recent spec conversation in whatwg/dom#1307 (comment) where the moved & parent node have to be in the same shadow-including root, not only in the same document. Bug: 40150299 Change-Id: Ic4daa6e863a8e96061ad9bebad2264202d87f722 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6088082 Commit-Queue: Noam Rosenthal <[email protected]> Reviewed-by: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1395407} -- wpt-commits: e26600a08505dbdf907bce572f97c2f560b3bc29 wpt-pr: 49653
…odes, a=testonly Automatic update from web-platform-tests DOM: Enable moveBefore() into Document nodes See whatwg/dom#1307 (review). [email protected] Bug: 40150299 Change-Id: I01b148f65c9e9c2545e7287ae38eb0e39f57d3d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081493 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1394297} -- wpt-commits: 64e219541d6cf8165e11c2625bba82381044075f wpt-pr: 49603
…s, a=testonly Automatic update from web-platform-tests moveBefore: fail when moving across roots This applies the recent spec conversation in whatwg/dom#1307 (comment) where the moved & parent node have to be in the same shadow-including root, not only in the same document. Bug: 40150299 Change-Id: Ic4daa6e863a8e96061ad9bebad2264202d87f722 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6088082 Commit-Queue: Noam Rosenthal <[email protected]> Reviewed-by: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1395407} -- wpt-commits: e26600a08505dbdf907bce572f97c2f560b3bc29 wpt-pr: 49653
Are there any tests for MutationObserver + moveBefore? |
I thought there were but I cannot find them, so I'll add some today. |
See whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: I9529941e05591620da5b3c11635693a15f0ce866 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6111212 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1399350}
See whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: I9529941e05591620da5b3c11635693a15f0ce866 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6111212 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1399350}
OK |
See whatwg/dom#1307 (comment). [email protected] Bug: 40150299 Change-Id: I9529941e05591620da5b3c11635693a15f0ce866 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6111212 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1399350}
This PR introduces a new DOM API on the
ParentNode
mixin:moveBefore()
. It mirrorsinsertBefore()
in shape, but defers to a new DOM manipulation primitive that this PR adds in service of this new API: the "move" primitive. The move primitive contains some of the DOM tree bookkeeping steps from the remove primitive, as well as the insert primitive, and does three more interesting things:connectedMoveCallback()
The power of the move primitive comes from the fact that the algorithm does not defer to the traditional insert and removal primitives, and therefore does not invoke the removing steps and insertion steps. This allows most state to be preserved by default (i.e., we don't tear down iframes, or close dialogs). Sometimes, the insertion/removing step overrides in other specifications have steps that do need to be performed during a move anyways. These specifications are expected to override the moving steps hook and perform the necessary work accordingly. See whatwg/html#10657 for HTML.
Closes #1255. Closes #1335.
Remaining tasks (some will be PRs in other standards):
focusin
event semantics[ ] Preserve text-selection. See set the selection range. Edit: Nothing needs to be done here. Selection metadata (i.e.,selectionStart
and kin) is preserved by default in browsers, consistent with HTML (no action is taken on removal). The UI behavior of the selection not being highlighted is a side-effect of the element losing focusselectionchange
event: We've decided to allowselectionchange
event to still fire, since it is queued in a task. No changes for this part are required.Node.prototype.moveBefore
) WebKit/standards-positions#375Node.prototype.moveBefore
) mozilla/standards-positions#1053moveBefore()
API mdn/mdn#613 & theimpacts-documentation
label(See WHATWG Working Mode: Changes for more details.)
Preview | Diff