This feature adds a new DOM primitive (Node.prototype.moveBefore()) that allows moving connected elements around a DOM tree (same-Document), without resetting various pieces of element state. See this spec issue: https://github.com/whatwg/dom/issues/1255. The following state is ordinarily reset when an element moves in the DOM, but is preserved when the `moveBefore()` API is used:
None
Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?
None to speak of
None
See https://wpt.fyi/results/dom/nodes/moveBefore/tentative?label=experimental&label=master&aligned
This is a web platform API that should be made fully available in the milestone it is shipping with. The API is flagged, so we can kill it with Finch if needed.
Shipping on desktop | 133 |
Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).
Contact emailsd...@chromium.org, nrosenthal@chromium.org
ExplainerExplainer
Specificationhttps://github.com/whatwg/dom/pull/1307
SummaryThis feature adds a new DOM primitive (Node.prototype.moveBefore()) that allows moving connected elements around a DOM tree (same-Document), without resetting various pieces of element state. See this spec issue: https://github.com/whatwg/dom/issues/1255. The following state is ordinarily reset when an element moves in the DOM, but is preserved when the `moveBefore()` API is used:
- Iframe documents (including unload events & document reloading)
- Focus
- Popovers
- Modal dialogs
- Fullscreen
- CSS transitions & animations
- Pointer events
See https://github.com/whatwg/dom/issues/1270 for more.
Blink componentBlink>DOM
TAG review status"Satisfied with concerns". TAG issue is resolved.
Risks
Interoperability and CompatibilityNone
Gecko: Positive (https://github.com/mozilla/standards-positions/issues/1053)
WebKit: Support (https://github.com/WebKit/standards-positions/issues/375)
Web developers: Positive (https://github.com/whatwg/dom/issues/1255) See comments from HTMX (docs) & React, as well as Angular.
Other signals: N/A
WebView application risksDoes this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?
None to speak of
DebuggabilityNone
Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, ChromeOS, Android, and Android WebView)?Yes
Is this feature fully tested by web-platform-tests?YesSee https://wpt.fyi/results/dom/nodes/moveBefore/tentative?label=experimental&label=master&aligned
Flag name on about://flagsAtomicMoveAPI
Finch feature nameNone
Non-finch justificationThis is a web platform API that should be made fully available in the milestone it is shipping with. The API is flagged, so we can kill it with Finch if needed.
Requires code in //chrome?No
MeasurementA WebDX use-counter named "MoveBeforeAPI" has been added, and is referenced in the IDL for `moveBefore()`.
Adoption expectationThis feature will largely be used by framework authors when moving nodes around the DOM tree, and to a lesser extent, individual web developers specifically interested in this state preservation.
Adoption planAdoption is relatively easy. Developers can start using `Node#moveBefore()` in place of `Node#insertBefore()`, while accounting for the extra scenarios that `moveBefore()` will throw an exception in. In the error case, developers can consider delegating to `insertBefore()` instead. Furthermore, adoption is made easy by the fact that all cases under which `moveBefore()` would throw are web-observable & testable by developers.
Estimated milestonesShipping on desktop133
Anticipated spec changesOpen questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).
During the spec review process, we decided (along with other browsers) to not preserve DOM live Range state, which includes text selection (see this spec review thread). The idea is that we'd revisit adding this if it becomes a serious developer want, but until then, the API will not preserve this state. We are hopeful that if we decide to add this preservation later, we can change the API to preserve this kind of state by default and still be web-compatible. However, the alternative would be to specify some options for the API to enable future kinds of preservation like Range/selection.
Link to entry on the Chrome Platform Statushttps://chromestatus.com/feature/5135990159835136?gate=5177450351558656
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/d4ad2c0c-05a4-4d40-8d91-aebc043d4489n%40chromium.org.
The TAG feedback was a request to see if we could make this change to the other methods by default, instead of adding a parallel set. If that's web-compatible, we might not have to think about the larger package.
On Wed, Nov 20, 2024 at 8:32 AM Alex Russell <sligh...@chromium.org> wrote:This is very exciting, and I'm eager for this capability to ship, but I'm also worried that we're only doing one of the many append/insert API variants here. Is this the start of a larger package of additions? Or the only planned version?
What's preventing the PR from landing?
There was a lengthy discussion about this at WHATWG before and as a result of the TAG feedback. The conclusion is that it's not feasible to change the behavior of all the existing methods, and changing the behavior of only some of them would be inconsistent and confusing.
What's preventing the PR from landing?Just the fact that it hasn't been fully reviewed yet. We've received initial comments, but are waiting for a full round and LGTMs, and are confident they'll come soon.There was a lengthy discussion about this at WHATWG before and as a result of the TAG feedback. The conclusion is that it's not feasible to change the behavior of all the existing methods, and changing the behavior of only some of them would be inconsistent and confusing.To add to Noam's comments, a big deciding factor for the current direction was philosophical, and unrelated to web compatibility. Current editors (Anne and Domenic weighed in heavily during the TPAC 2024 discussion) felt strongly that the concept of "move" was conceptually a very distinct primitive from the existing "insert" and "remove" primitives. Therefore, usages of the existing primitives—through existing APIs—shouldn't suddenly mix the move behavior in with the current behavior, even if it were web compatible. The processing model of move compared to insert+removal is different enough that blending them is not what editors would have done even if "move" were conceived of from the beginning—this is the main feedback we got.
The remaining arguments seem to be about 1) whether it makes sense for the movement APIs to have noticeably different side-effects when moving a node across documents
2) whether the methods that reparent lists of elements can reasonably remove+insert some while atomically-moving others.
The remaining arguments seem to be about 1) whether it makes sense for the movement APIs to have noticeably different side-effects when moving a node across documentsJust to be super clear, we're not at all considering cross-document moves; our proposal is scoped to same-document only. Now, so I understand where you're coming from, you're saying that (1) above is about whether the side effects of (a) attempting a cross-document move (always an error) should or should not match the side effects of (b) moving a node that cannot be moved in a state-preserving way? I don't think whether these two "failure" cases have matching side effects is all that important, I just think that the side effects should make sense/be logical for each case.
2) whether the methods that reparent lists of elements can reasonably remove+insert some while atomically-moving others.I honestly don't know if this is the most interesting part about changing the behavior of all DOM mutation APIs. Exactly what `append()` should do if some of its nodes can be atomically moved while others must be fully inserted is interesting, but I think the way more interesting question is should `append()` ever try and atomically move even just a single element that can be atomically moved? First, there is the web compatibility concern. But second, and more interesting to me, is predictability. It feels strange if sometimes `append()` has big side effects (script execution—which may attempt nested `append()` calls, iframes initializing, styles being applied, etc.), and other times no side effects at all. If you want to know whether `append()` will have side effects, then you have to find the spec'd conditions under which an atomic move will be performed and check these before `append()`. It's this predictability concern that I think motivated TPAC folks to lean towards `moveBefore()` throwing an error when an atomic move could not be performed.
Doesn't `append(elem)` already sometimes have big side-effects (when `elem` is a <script> or <iframe>) and other times have no side-effects (when `elem` is a <b>)? It doesn't seem like reducing the number of side-effects is going to introduce a consistency problem here. I think the more important question is whether authors ever _want_ those side-effects. If they do, it's going to be web-incompatible to change the existing methods. If authors never want the side-effects, we should remove them whenever we can.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/c31ab674-d794-4146-8ab2-fcaadb0536d7n%40chromium.org.
LGTM3 to ship once the spec PR has landed.
Also, I'm really happy to see this new API coming to the web platform! Thanks to all that has made it happen!
/Daniel
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.