Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portals should load and retain state even when they're not in the document #172

Open
jakearchibald opened this issue Jan 24, 2020 · 8 comments
Labels
design work needed An acknowledged gap in the proposal that needs design work to resolve

Comments

@jakearchibald
Copy link
Collaborator

Iframes reload if they're moved around the DOM, but I don't think the same should happen with portals.

Use-cases:


Imagine a list of article previews, where some/all contain portals to the article. On click, the portal animates to fill the viewport, then it's activated.

Doing this in-place is impossible if any ancestor element has overflow: hidden. This is likely since overflow: hidden is used for things like padding/float containment. This CSS will prevent the element filling the viewport.

The way this is typically achieved, is to move the element to <body>, and absolutely position it in its previous place, then it can be animated freely.

With an iframe, this would incur a reload, which is undesirable.


Imagine a list of article previews, where some/all contain portals to the article. On click, the portal activates. However, what if the user indicates they want the article to open in a new tab/window?

We already have window.open, but if the page is already loaded in a portal, we should avoid having to reload it. In this case the developer could open an about:blank window, move the portal to it, and activate it there.

Again, iframe-style reloading wouldn't work here.


Imagine a list of article previews, where the first is most-likely to be clicked, so should be preloaded.

Right now, the developer would have to add the portal to the page, position absolute, opacity 0, pointer-events none etc etc just so it actually loads. This feels like a hack.

The portal should load as soon as its src is set, so this sort of preloading doesn't require it being appended to the body.

@jeremyroman
Copy link
Collaborator

With the exception of the portalactivate event, the lifetime is currently confined to being browsing context connected (i.e., in the document). The reason here is that we need to know when we can actually destroy the portal. I feel pretty strongly that this should not be driven by GC.

That means that ownership has to be either rooted somewhere that's torn down when the document unloads (e.g. the document, but we could have some other collection that owned "background" portals if we feel that's a substantial ergonomic improvement over the strategy developers are used to) or bounded in time (e.g. lifetime extended until the end of some queued task).

@jakearchibald
Copy link
Collaborator Author

There's a third option: A detached portal could be treated like a bf cache page entry. As in, it goes through the whole unload, pageHide stuff. At this point, it can be discarded whenever. Once it's reattached, it will either pageShow or reload if it was discarded.

But, if we don't care too much about the third use-case, extending lifetime by a task would solve the first two use-cases.

@jeremyroman
Copy link
Collaborator

If I were an author, I would find that sometimes my portal reloads when I'm moving it around and sometimes it doesn't somewhat surprising.

@jakearchibald
Copy link
Collaborator Author

I mean we wouldn't discard it while it was still in reference, but we can discard it on GC. At that point you aren't exposing GC, because there aren't any events to fire.

I think the one-more-task solution is good enough though.

@jeremyroman
Copy link
Collaborator

You could observe whether it had run, which is itself an antipattern, by noticing whether state was preserved. (And in Chromium at least, there is the potential for implementation issues that may make this difficult to collect, because of the possibility of untraced owning references in both directions.)

But agreed that we can find some other solution here.

@jakearchibald
Copy link
Collaborator Author

You could observe whether it had run, which is itself an antipattern,

Sure, but it's how the bfcache works.

@domenic domenic added the design work needed An acknowledged gap in the proposal that needs design work to resolve label May 8, 2020
@jakearchibald
Copy link
Collaborator Author

My gut feeling is this would become a point of contention with other browser vendors (and probably implementers in Chrome too).

We could close this, and instead go for a general solution whatwg/html#5484.

We lose this use-case:

Imagine a list of article previews, where the first is most-likely to be clicked, so should be preloaded.

Right now, the developer would have to add the portal to the page, position absolute, opacity 0, pointer-events none etc etc just so it actually loads. This feels like a hack.

But it's the weakest of the use-cases, and easy to work around.

@jeremyroman
Copy link
Collaborator

Generally agreed, except that it's possible whatwg/html#5484 goes nowhere due to complexity around compat and iframe behavior that doesn't apply to portals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design work needed An acknowledged gap in the proposal that needs design work to resolve
Projects
None yet
Development

No branches or pull requests

3 participants