- Notifications
You must be signed in to change notification settings - Fork2.9k
State-preserving atomic move integration#10657
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
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.
I don't think you mentioned connectedMoveCallback everywhere connectedCallback is mentioned (and it's relevant).
- https://html.spec.whatwg.org/#custom-element-reactions
- https://html.spec.whatwg.org/#element-definition (this one seems especially important)
- It could do with some examples as well.
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.
noamr commentedDec 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This was there already, seehttps://whatpr.org/html/10657/custom-elements.html#custom-element-reactions ("When it is moved"). Not sure what's missing?
Done
Added non-normative note and an example |
Seems like#10828 should be addressed here too? |
05e204b
to9ee1673
CompareUh 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 ships the `ParentNode#moveBefore` API to Chrome stable,targeting M133. See: -https://chromestatus.com/feature/5135990159835136 -https://groups.google.com/a/chromium.org/g/blink-dev/c/YE_xLH6MkRs -https://issues.chromium.org/issues/40150299 -whatwg/dom#1255 -whatwg/dom#1307 -whatwg/html#10657R=chrishtr, masonf, nrosenthalBug: 40150299Change-Id: I005f1db250d731d6845b5238048bbd0b90b20c81Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/6112499Reviewed-by: Noam Rosenthal <nrosenthal@chromium.org>Reviewed-by: Mason Freed <masonf@chromium.org>Reviewed-by: Chris Harrelson <chrishtr@chromium.org>Commit-Queue: Chris Harrelson <chrishtr@chromium.org>Cr-Commit-Position: refs/heads/main@{#1400559}
Just noting#10954 (comment), which will require a small change to this PR if/when that one lands. |
Uh oh!
There was an error while loading.Please reload this page.
theengineear commentedMar 6, 2025
First off, I want to say that That said, I wanted to raise a concern about the following part of the specification: <p>To opt in to a state-preserving behavior while<spandata-x="concept-node-move-ext">moving</span>, the author can implement a "<codedata-x="">connectedMoveCallback</code>". The existence of this callback, even if empty, would supercede the default behavior of calling "<codedata-x="">disconnectedCallback</code>" and "<codedata-x="">connectedCallback</code>". "<codedata-x="">connectedMoveCallback</code>" can also be an appropriate place to execute logic that depends on the element's ancestors. For example:</p> I find it confusing that the existence of a By way of counter point, I don’tthink the presence of an Is there any flexibility in the specification at this point to change that? Or, would it be possible to understand the rationale on this decision in a little more detail? |
This is by design. By adding this empty callback you signal that your component is capable of handling moves.
I don't think this analogy is valid. The presence of the callback doesn't change how ’moveBefore’ works, only which custom element callbacks are called.
It's late at this point. To explain the rationale: |
This introduces a new API on the ParentNode mixin: moveBefore(). It mirrors insertBefore() in shape, but uses a new manipulation primitive that is also added here: "move". The move primitive contains some of the node tree bookkeeping steps from the remove primitive, as well as the insert primitive, and does three more interesting things:1. Calls the moving steps hook with the moved node and the old parent (possibly null, just like the removing steps).2. Queues a custom element callback reaction for the connectedMoveCallback().3. Queues two back-to-back mutation record tasks: one for removal from the old parent; one for insertion into the new one.The power of the move primitive comes from the fact that the algorithm does not defer to the traditional insert and remove 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.Corresponding HTML PR:whatwg/html#10657.Tests:https://github.com/web-platform-tests/wpt/tree/master/dom/nodes/moveBefore (the tentative directory will be flattened).Closes#1255.Closes#1335.Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
432e8fb
intomainUh oh!
There was an error while loading.Please reload this page.
theengineear commentedMar 7, 2025
@noamr — Thanks for the thoughtful response. I get your point from a “don’t break the web perspective”, but I am struggling to understand the mental model related to I had previously thought that part of thepoint of using Either way, I’ll just bake |
It also fires the connectedCallback straight after. The mental model is that if your existing component is not prepared for a move, it should fall back to disconnecting and reconnecting, like a "restart" to make sure it didn't go into some funky state.
|
In case it helps, a possible mental model might be that it disconnects and reconnects the vast majority of elements (e.g. |
theengineear commentedMar 8, 2025
@domenic — That is actually super helpful! Makesmuch more sense to me that this works the way it does 🤘 |
Thanks for asking for clarifications, I will make sure this is reflected in documentation. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
As discovered in#10657, no browser's removing or moving steps rely on the 'next sibling' pointer associated with the old element's position. After writing a test, we also discovered that the same goes for the insertion steps. In all cases, when the parent (old parent, for removing/moving steps) is a <picture> element, a relevant mutation is triggered for all <img> children of the parent. Update the spec to reflect this.Closes#11113.
Uh oh!
There was an error while loading.Please reload this page.
This PR is a supplementary PR towhatwg/dom#1307. It provides the HTML-overrides for the DOM Standard's "moving steps" extension, to allow pieces of the HTML Standard to react to atomic DOM moves without the use of the "insertion steps" or "removing steps", which by default, intentionally fail to preserve most state. The changes in this PR are inspired by the audit carried out inhttps://docs.google.com/document/d/1qfYyvdK4zhzloABKeh0K1lHPm-SpnEcsWEE9UdDuoMk/edit.
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.)
/custom-elements.html (diff )
/embedded-content.html (diff )
/form-control-infrastructure.html (diff )
/form-elements.html (diff )
/images.html (diff )
/index.html (diff )
/infrastructure.html (diff )
/media.html (diff )