Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
annevk merged 2 commits intomainfromatomic-move-patches
Mar 7, 2025
Merged

Conversation

domfarolino
Copy link
Member

@domfarolinodomfarolino commentedSep 29, 2024
edited by pr-previewbot
Loading

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.

(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 )

@domfarolinodomfarolino marked this pull request as ready for reviewNovember 20, 2024 21:52
@domfarolinodomfarolino added impacts documentationUsed by documentation communities, such as MDN, to track changes that impact documentation addition/proposalNew features or enhancements labelsNov 20, 2024
Copy link
Member

@annevkannevk left a 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).

noamr reacted with thumbs up emoji
@noamr
Copy link
Collaborator

noamr commentedDec 3, 2024
edited
Loading

I don't think you mentioned connectedMoveCallback everywhere connectedCallback is mentioned (and it's relevant).

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

  • It could do with some examples as well.

Added non-normative note and an example

@domenic
Copy link
Member

Seems like#10828 should be addressed here too?

@domfarolino
Copy link
MemberAuthor

Seems like#10828 should be addressed here too?

I think it needs to be done separately; I've uploaded#10840.

aarongable pushed a commit to chromium/chromium that referenced this pull requestDec 27, 2024
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}
@mfreed7
Copy link
Contributor

Just noting#10954 (comment), which will require a small change to this PR if/when that one lands.

@theengineear
Copy link

First off, I want to say thatmoveBefore is going to be a major win in terms of functionality — so, thanks so much for working on it!

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 aconnectedMoveCallback method on a custom element changes the behavior ofmoveBefore. I think it will lead to custom element authors needing to write emptyconnectedMoveCallback() {/* do nothing, just here to prevent disconnectedCallback */} methods — and that feels like an anti-pattern. It will also lead to integration uncertainty for folks trying to leveragemoveBefore.

By way of counter point, I don’tthink the presence of anadoptedCallback lifecycle method changes howadoptNode works, just like the presence ofconnectedMoveCallback won’t change how the currentinsertBefore works.

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?

@noamr
Copy link
Collaborator

First off, I want to say thatmoveBefore is going to be a major win in terms of functionality — so, thanks so much for working on it!

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 aconnectedMoveCallback method on a custom element changes the behavior ofmoveBefore. I think it will lead to custom element authors needing to write emptyconnectedMoveCallback() {/* do nothing, just here to prevent disconnectedCallback */} methods — and that feels like an anti-pattern. It will also lead to integration uncertainty for folks trying to leveragemoveBefore.

This is by design. By adding this empty callback you signal that your component is capable of handling moves.

By way of counter point, I don’tthink the presence of anadoptedCallback lifecycle method changes howadoptNode works, just like the presence ofconnectedMoveCallback won’t change how the currentinsertBefore works.

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.

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?

It's late at this point.

To explain the rationale:
This is to avoid breaking existing components that might assume that an element cannot be moved, as custom elements predate moving. For example, a custom element might check the tag name of Its parent in its ’connectedCallback’. Before moving this was guaranteed to not change until the next ’disconnectedCallback’, so by calling both callbacks by default we simulate the old behavior to ensure components that rely on it, and by providing the new callback the component can open out from that.

annevk added a commit to whatwg/dom that referenced this pull requestMar 7, 2025
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>
@annevkannevk merged commit432e8fb intomainMar 7, 2025
2 checks passed
@annevkannevk deleted the atomic-move-patches branchMarch 7, 2025 14:24
@theengineear
Copy link

The presence of the callback doesn't change how ’moveBefore’ works, only which custom element callbacks are called.

@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 todisconnectedCallback andmoveBefore.

I had previously thought that part of thepoint of usingmoveBefore was toprevent disconnection. I.e., I usemoveBefore on some set of elements to ensure that theydon’t disconnect — why is it the case that usingmoveBefore doesn’t guarantee thatdisconnectedCallback is skipped? Perhaps I just need to fix my mental model to think about these lifecycle methods asmaybeDisconnectedCallback andmaybeConnectedCallback.

Either way, I’ll just bakeconnectedMoveCallback into a base element and I’m excited to see this stuff landing ❤️

noamr reacted with thumbs up emoji

@noamr
Copy link
Collaborator

The presence of the callback doesn't change how ’moveBefore’ works, only which custom element callbacks are called.

@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 todisconnectedCallback andmoveBefore.

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.

I had previously thought that part of thepoint of usingmoveBefore was toprevent disconnection. I.e., I usemoveBefore on some set of elements to ensure that theydon’t disconnect — why is it the case that usingmoveBefore doesn’t guarantee thatdisconnectedCallback is skipped? Perhaps I just need to fix my mental model to think about these lifecycle methods asmaybeDisconnectedCallback andmaybeConnectedCallback.

Either way, I’ll just bakeconnectedMoveCallback into a base element and I’m excited to see this stuff landing ❤️

@domenic
Copy link
Member

In case it helps, a possible mental model might be that it disconnects and reconnects the vast majority of elements (e.g.<p>,<div>,<strong>, custom elements by default, ...). But for certain special elements it performs a move (e.g.<img>,<iframe>,<select>,<audio>,<video>, certain custom elements, ...).

theengineear reacted with heart emoji

@theengineear
Copy link

@domenic — That is actually super helpful! Makesmuch more sense to me that this works the way it does 🤘

noamr reacted with thumbs up emoji

@noamr
Copy link
Collaborator

@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.

theengineear reacted with heart emoji

sangshanrupesh

This comment was marked as spam.

domenic pushed a commit that referenced this pull requestMar 19, 2025
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.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@noamrnoamrnoamr left review comments

@keithamuskeithamuskeithamus left review comments

@sangshanrupeshsangshanrupeshsangshanrupesh left review comments

@annevkannevkannevk approved these changes

@smaug----smaug----smaug---- approved these changes

Assignees
No one assigned
Labels
addition/proposalNew features or enhancementsimpacts documentationUsed by documentation communities, such as MDN, to track changes that impact documentation
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

9 participants
@domfarolino@noamr@domenic@mfreed7@theengineear@keithamus@annevk@smaug----@sangshanrupesh

[8]ページ先頭

©2009-2025 Movatter.jp