- Notifications
You must be signed in to change notification settings - Fork313
IntroducemoveBefore()
state-preserving atomic move API#1307
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
moveBefore()\
state-preserving atomic move APImoveBefore()
state-preserving atomic move APIThere 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 existingMutationRecord
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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. |
ajklein commentedSep 4, 2024
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 theagreed-upon error-throwing behavior for all pre-moving validity andhierarchy 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#1307R=nrosenthal@chromium.orgBug: 40150299Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92
This CL makes moveBefore() match the spec PR [1], with regard to theagreed-upon error-throwing behavior for all pre-moving validity andhierarchy 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#1307R=nrosenthal@chromium.orgBug: 40150299Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5935350Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Commit-Queue: Dominic Farolino <dom@chromium.org>Cr-Commit-Position: refs/heads/main@{#1369303}
This CL makes moveBefore() match the spec PR [1], with regard to theagreed-upon error-throwing behavior for all pre-moving validity andhierarchy 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#1307R=nrosenthal@chromium.orgBug: 40150299Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5935350Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Commit-Queue: Dominic Farolino <dom@chromium.org>Cr-Commit-Position: refs/heads/main@{#1369303}Co-authored-by: Dominic Farolino <dom@chromium.org>
…-move validity checks, a=testonlyAutomatic update from web-platform-testsDOM: Make moveBefore() throw for all pre-move validity checks (#48642)This CL makes moveBefore() match the spec PR [1], with regard to theagreed-upon error-throwing behavior for all pre-moving validity andhierarchy 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#1307R=nrosenthal@chromium.orgBug: 40150299Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5935350Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Commit-Queue: Dominic Farolino <dom@chromium.org>Cr-Commit-Position: refs/heads/main@{#1369303}Co-authored-by: Dominic Farolino <dom@chromium.org>--wpt-commits: 06b6ff6579327f235fff80b0f8bae8b0bbbc1069wpt-pr: 48642
…-move validity checks, a=testonlyAutomatic update from web-platform-testsDOM: Make moveBefore() throw for all pre-move validity checks (#48642)This CL makes moveBefore() match the spec PR [1], with regard to theagreed-upon error-throwing behavior for all pre-moving validity andhierarchy 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#1307R=nrosenthal@chromium.orgBug: 40150299Change-Id: Iaf5243fb2762e21ede068a222600bd158859fe92Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5935350Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Commit-Queue: Dominic Farolino <dom@chromium.org>Cr-Commit-Position: refs/heads/main@{#1369303}Co-authored-by: Dominic Farolino <dom@chromium.org>--wpt-commits: 06b6ff6579327f235fff80b0f8bae8b0bbbc1069wpt-pr: 48642
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This CL enables moveBefore() inside connected ShadowRootDocumentFragments, as the general only-Element-node target parentpre-condition was too strict, and disabled this case, despite it beinga pretty valid one.This was discussed inwhatwg/dom#1307 (comment).R=nrosenthal@chromium.orgBug: 40150299Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440da
This CL enables moveBefore() inside connected ShadowRootDocumentFragments, as the general only-Element-node target parentpre-condition was too strict, and disabled this case, despite it beinga pretty valid one.This was discussed inwhatwg/dom#1307 (comment).R=nrosenthal@chromium.orgBug: 40150299Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440daReviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6012161Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1381208}
This CL enables moveBefore() inside connected ShadowRootDocumentFragments, as the general only-Element-node target parentpre-condition was too strict, and disabled this case, despite it beinga pretty valid one.This was discussed inwhatwg/dom#1307 (comment).R=nrosenthal@chromium.orgBug: 40150299Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440daReviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6012161Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1381208}
This CL enables moveBefore() inside connected ShadowRootDocumentFragments, as the general only-Element-node target parentpre-condition was too strict, and disabled this case, despite it beinga pretty valid one.This was discussed inwhatwg/dom#1307 (comment).R=nrosenthal@chromium.orgBug: 40150299Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440daReviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6012161Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1381208}
43ba844
to9270da7
CompareThis CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3
This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}
This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}
This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
@smaug---- can you double check as well? Is Monday a reasonable merge day? I feel like everyone else already got sufficient time in the last couple of rounds.
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <domchromium.org>Reviewed-by: Noam Rosenthal <nrosenthalchromium.org>Cr-Commit-Position: refs/heads/main{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945UltraBlame original commit: 4a6a1072a3e50a2172f5d712305e8a77f170e452
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <domchromium.org>Reviewed-by: Noam Rosenthal <nrosenthalchromium.org>Cr-Commit-Position: refs/heads/main{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945UltraBlame original commit: 4a6a1072a3e50a2172f5d712305e8a77f170e452
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <domchromium.org>Reviewed-by: Noam Rosenthal <nrosenthalchromium.org>Cr-Commit-Position: refs/heads/main{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945UltraBlame original commit: 4a6a1072a3e50a2172f5d712305e8a77f170e452
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945
I think this is fine. https://issues.chromium.org/issues/400758510 is interesting. That was filed immediately when someone tried to use the API. That is more for the HTML part of the feature though. But I think opt-in behavior of the new callback is reasonable (though the callback should likely get old parent as a param, but that can be a followup) |
eaf2ac7
intomainUh oh!
There was an error while loading.Please reload this page.
This complementswhatwg/dom#1307. It integrates "moving steps", which allow HTML elements to react to atomic node moves without the use of the "insertion steps" or "removing steps". Those intentionally fail to preserve most state and are therefore not always suitable for a node "move". The changes in this PR are inspired by the audit carried out inhttps://docs.google.com/document/d/1qfYyvdK4zhzloABKeh0K1lHPm-SpnEcsWEE9UdDuoMk/edit.
This complementswhatwg/dom#1307. It integrates "moving steps", which allow HTML elements to react to atomic node moves without the use of the "insertion steps" or "removing steps". Those intentionally fail to preserve most state and are therefore not always suitable for a node "move". The changes in this PR are inspired by the audit carried out inhttps://docs.google.com/document/d/1qfYyvdK4zhzloABKeh0K1lHPm-SpnEcsWEE9UdDuoMk/edit.
…), a=testonlyAutomatic update from web-platform-testsDOM: Add slotchange test for moveBefore()This CL adds a test to ensure that the 'slotchange' event is fired whenslots themselves are moved in and out of a custom element, and theirassigned nodes change.This addresseswhatwg/dom#1307 (comment).R=nrosenthalBug: 40150299Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6298941Commit-Queue: Dominic Farolino <dom@chromium.org>Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Cr-Commit-Position: refs/heads/main@{#1424746}--wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6fwpt-pr: 50945
Uh oh!
There was an error while loading.Please reload this page.
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 theremoving steps andinsertion 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. Seewhatwg/html#10657 for HTML.
Closes#1255.Closes#1335.
Remaining tasks (some will be PRs in other standards):
focusin
event semantics[ ] Preserve text-selection. Seeset 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(SeeWHATWG Working Mode: Changes for more details.)
Preview |Diff