Closed khushalsagar closed 1 year ago
There are two occasions when this event would fire:
Let's assume for a sec that we have document.activeTransition
.
For the first one, I guess the developer can already put a script at the end of the <head>
to make all kind of checks and mark more resources as render-blocking etc, and use document.referrer
or whatever query variable to customize?
For the second one, pageshow
should be sufficient.
We can consider adding the reveal
event to HTML (see whatwg/html#9315) but I want to have the use cases spelled out to make the case for it.
If I look at the above example, the steps that should be done before first render are different from the steps to be done at reactivation. Perhaps we should keep that explicit rather than merge those into one event?
This is how the above example would look when only exposing document.activeTransition
:
<head>
<script>
const info = sessionStorage.getItem("pre-transition-info");
if (document.activeTransition)
markRenderBlockingResources(info);
function setupCustomAnimation() {
const transition = document.activeTransition;
if (!transition)
return;
transition.ready.then(() => {
document.documentElement.animate(...,
{
// Specify which pseudo-element to animate
pseudoElement: "::view-transition-new(root)",
}
);
// Remove viewTransitionNames tied to this transition.
thumbnail.style.viewTransitionName = "none";
});
// The `finished` promise resolves when all animations for the transition are
// finished or cancelled and the pseudo-elements have been removed.
transition.finished.then(() => { ... });
}
setupCustomAnimation();
window.addEventListener("pageshow", () => setupCustomAnimation());
</script>
</head>
For the purpose of the F2F, summarizing current thinking about this. The use-cases this comes to address are:
A design principle here is to keep consistency, both with view-transitions-1 and with other web features.
There are several alternative on how to achieve this:
inboundviewtransition
or crossdocumentviewtransition
.reveal
), and include an optional ViewTransition
object as a property of that event. This has the advantage of being compatible with css-view-transitions-1, and also the reveal
event might be useful for things other than view-transitions so why not.start
, ready
and finished
, without a ViewTransition
object. This is compatible with e.g. how mouse/touch events work, and avoids the need to add a listener only in order to register a promise, but it's not compatible with css-view-transitions-1 where the ViewTransition
object is promise-based.Note that as the OP states, updateCallbackDone
is irrelevant for cross-document view transitions. The current spec proposal is to simply have it as a resolved promise rather than have different IDL types and inheritance.
The current spec draft goes with option (2), as it seems to be the most compatible with VT-1.
The CSS Working Group just discussed [css-view-transitions-2] Script event on new Document for cross-document ViewTransitions
, and agreed to the following:
RESOLVED: Add a single event to carry the cross-document VT object. Work with HTML folks to define exact timing, and whether it's a VT-specific event or generic (always fired)
I'm pretty convinced that we should fire the reveal
event even when there is no view transition. The use case is that authors that do use view transitions, might want to do something specifically if the view transition is not present (e.g. the previous page hasn't opted in. e.g.:
document.addEventListener("reveal", event => {
if (event.viewTransition) {
event.viewTransition.ready.then(() => { animate... });
event.viewTransition.finished.then(() => { postTranisitonChanges(); });
} else {
postTranisitonChanges();
}
});
Is reveal
just pageshow
, but without the stupid thing where pageshow
initially fires after window onload?
Is
reveal
justpageshow
, but without the stupid thing wherepageshow
initially fires after window onload?
Yes exactly, plus includes a property that refs the ViewTransition
if it's there.
That thing with pageshow
is really strange IMO.
Is reveal just pageshow, but without the stupid thing where pageshow initially fires after window onload?
FWIW, based on the comments I've seen it looks like pageshow
/pagehide
were designed to be replacements for load
/unload
if some logic needed to be done for BFCache also. That's why the timing for pageshow
closely aligns with load
. Unfortunate naming but it was never meant to be about timing display of page content.
Closing this, as pagereveal
's monkey patch version is in the spec.
View Transition API needs to provide an event on the new Document to enable customization of the transition based on the URL for the old Document and its state when the transition was initiated. For example, the old Document could have changed from user interaction or the transition could depend on which click initiated the navigation.
The proposed IDL is as follows:
The ViewTransition interface is also split into a base IDL with functionality common to same-document and cross-document transitions.
The following is sample code using this event: