spankalee a few seconds ago

This is going to be great for rendering libraries that do keyed loops and for some portal systems.

You'll be able to reorder items in a list while preserving focus, without reloading iframes, and keeping audio and video playing.

We have a draft PR for support in Lit, and will try to ship that as soon as possible.

klinch an hour ago

Honestly curious - Does anyone have a use case for this? I tried hard to figure out what this could be used for, but couldn't come up with anything.

  • AshleysBrain 14 minutes ago

    Previously if you moved an element anywhere else in the DOM for any reason - such as reordering elements, sorting a list, etc. - lots of kinds of elements would be reset: iframes reloaded, transitions/animations are cancelled, video playback is reset, focus is lost, even the scroll position is reset to the top. Some could be worked around (like saving the scroll position and restoring it), but others could not (like iframes being reloaded). Now with moveBefore() all these moves can be done while preserving the element state, which can dramatically simplify the usage of the DOM in some cases.

  • jitl 4 minutes ago

    This is exciting

    - move embedded iframe to lightbox for “full screen” and back

    - drag and drop of elements without resetting their state

    - I’m very curious if it works with contenteditable and/or input method editors

  • sublinear an hour ago

    I'm thinking about better responsive UI designs that don't frustrate the user. Everyone hates cumulative layout shift as things load in and window resizes also require layout changes which are often implemented poorly.

    I'm also thinking about situations where passing accessibility audits is nearly impossible and at odds with business and marketing insisting on complex designs that need to handle a lot of use cases on one page without making the user navigate to another page. Inevitably you find that there's a lot of display state in the DOM you can't serialize, and on the other end of the spectrum simple pages shouldn't need bloated JS web app frameworks just to maintain the state of a form.

    For new projects I can see this significantly reducing the JS and CSS needed. Layout change isn't triggered just by screen width but user input state. Right now I see a lot of web projects with ugly CSS (relative positioning or sometimes mind bending stuff with grid/flex) and ugly JS doing error prone element attribute accounting that ultimately wouldn't be necessary if you could just restructure the DOM on the fly.

    If you want an example for accessibility, since I think that's usually a big showstopper, many UI designs want z-indexy things such as context menus, tooltips, popups, notifications, modal forms, etc. that would not pass an audit because they're not properly contained within the structure of the page and technically live somewhere rattling around loosely in the <body> with a ton of CSS applied to complete the illusion.

  • spiderfarmer 34 minutes ago

    If Chrome takes the lead it's probably all about moving ads around on the page.

  • jsiepkes 42 minutes ago

    I assume this is big news for htmx (and the likes)?

    • beardyw a minute ago

      Htmx has experimental support.

egberts1 2 hours ago

[flagged]

  • lhnz 42 minutes ago

    If it weren't for JavaScript we'd still be downloading binaries and running them unsandboxed on our computers.

  • wslh an hour ago

    As a cybersecurity guy you should know that JavaScript is by far not the entire attack vector in the frontend landscape: the DOM, HTML, HTTP, CSS, browser implementations, etc are a most complete picture. JavaScript itself has evolved and is evolving from its basic roots.

  • quonn 2 hours ago

    Explain?

    • ramses0 2 hours ago

      Probably something like dom-swapping the google login page or whatever. If you can keep arbitrary CSS transitions running, I could imagine doing a bunch of weird stuff where you don't know exactly what box you're typing in to.

      https://developer.mozilla.org/en-US/docs/Web/Security/Attack...

      • weird-eye-issue an hour ago

        If you can run arbitrary JS on the Google login page then you could simply intercept the form submission and steal the credentials... Am I missing something?

      • jy14898 an hour ago

        > I could imagine doing a bunch of weird stuff where you don't know exactly what box you're typing in to.

        What stops malicious JavaScript that would have used moveBefore() to just add key event listeners?

      • AshleysBrain an hour ago

        Is the ability to move elements preserving DOM state really the key to such attacks? Previously you could do the same but the iframe would reload - but if it's a small simple page, it could load very quickly, in which case it doesn't seem all that different to moving the iframe with its existing content.