Re: [csswg-drafts] [css-view-transitions-2] Script event on new Document for cross-document ViewTransitions (#8805)

There are two occasions when this event would fire:
- at document initialization
- When reactivating from bfcache/prerender.

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`:

```html
<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>

```





-- 
GitHub Notification of comment by noamr
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8805#issuecomment-1562370122 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 25 May 2023 06:49:25 UTC