whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.05k stars 2.64k forks source link

An iframe whose history can be transferred across parent navigations #8538

Open jakearchibald opened 1 year ago

jakearchibald commented 1 year ago

Jotting down an idea that's been bouncing around my head:

The problem

There are cases where you have an embedded piece of content that ideally should not lose state across navigations, such as:

In the case of a chat widget, you can reload state from the server and continue where you left off – it's just not as fast as it could be.

With the media player, you're always going to get a break in playback.

The current solution is to turn your site into an SPA, to avoid cross-document navigations. This is a big undertaking, and usually leads to a loss of performance in other areas.

A solution?

A special type of iframe that:

As in, if you're navigating from A to B (same-origin and same-isolation), and both contain <magiciframe name="foo" src="page">, rather than reload page from scratch, B will adopt the traversable from A. If B doesn't contain a home for the iframe, it's either bfcached with A or unloaded.

This is building on iframe history reparenting, which browsers already do.

jakearchibald commented 1 year ago

There's some cross-over with portals here, although I think portals only go from embedded to top-level, and vice versa, rather than embedded to embedded.

robertknight commented 1 year ago

Can move around the DOM without reloading (solving some of https://github.com/whatwg/html/issues/5484).

How are the technical issues raised by WebKit devs in eg. https://github.com/whatwg/html/issues/5484 solved here? By guaranteeing that synchronous communication with other frames will never happen?

I work on a widget that gets loaded into existing third-party web pages and we sometimes run into the issue that some other script on the page will move DOM elements around and inadvertently reload our iframe and sever its MessageChannel-based connections to the main frame. So a way to prevent that reload happening would be great.

jakearchibald commented 1 year ago

The details of the potential security issues for webkit are a little light on detail, so I'm not sure.

Boldewyn commented 1 year ago

You know, we wouldn’t have these problems, if someone had actually fixed URLs for <frameset>s in the late 90s (and, admittedly, the tons of other issues with <frameset>, but I digress...). 😁

jakearchibald commented 1 year ago

@Boldewyn the same thought crossed my mind. However, this proposal would also allow the iframe to be popped out to a new window.

noamr commented 1 year ago

Love this! I think it addresses one of the main reasons people have to resort to SPAs (aside from the elusive "DX"). Losing state when navigating across documents, whether it be iframe state or form state, makes MPAs a lot less attractive.

I wonder if it can be an iframe attribute rather than a new type of element?

jakearchibald commented 1 year ago

I wonder if it can be an iframe attribute rather than a new type of element?

I think this will come down to how it works with other iframe attributes. Eg, does it make sense with a srcdoc? Maybe it does.

noamr commented 1 year ago

I wonder if it can be an iframe attribute rather than a new type of element?

I think this will come down to how it works with other iframe attributes. Eg, does it make sense with a srcdoc? Maybe it does.

SG. Hope we find a way to pick this up.