-
Notifications
You must be signed in to change notification settings - Fork 689
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
[css-view-transitions-2] Script event on old Document for cross-document ViewTransitions #8785
Comments
See #8683 (comment) |
@noamr IIRC, the conclusion for this was authors relying on existing events (like @jakearchibald for an opinion too. |
Having the URL after redirects seems like the most important thing. |
What's the scenario you have in mind? My thinking is that if you're in a same origin environment you shouldn't be surprised by redirects and that setting up the transition based on where you intend to go should be sufficient, but I could have a blind spot. |
Developers want to write transitions from one page type to another, so knowing the page they're going to seems like a thing that should be reliable. Eg, navigating to |
Traditionally apps would have either a |
Ok, two tabs logged out. In one tab you hit the login button and log in. What happens when you hit the login button on the other tab? But, regardless of this, you shouldn't be betting an API design, that ideally will live for decades, will ideally outlive various frontend and backend patterns, on "well redirects probably won't happen often". Instead, don't cut corners, design the API without easily foreseeable footguns. |
Perhaps in this case the whole transition would be unexpected. I would expect it to be skipped. I wonder if it could be a "skip on redirect" boolean-ish though it doesn't feel complete.
Sure, just looking to work with valid use cases and make them simple enough. We have to start with the simple common use-cases What I'm struggling with here is the feasibility of making the final URL observable when we enable cross-origin same-site, and if we want to enable something that's incompatible with that. |
I don't think that's a good idea, considering how common it is to redirect from eg |
Redirects are also common on form submissions. I don't think this feature should pretend they aren't part of the platform, or hope that part of the platform isn't used. |
That's a good use-case, e.g. submitting to The concept is not to pretend that redirects don't exist, but to find a solution for this that's forward-compatible with same-site, and explore if the complexity it adds is useful enough. Having something that affects the style/transition names but is not observable by the old document might be a feasible direction (e.g. the media query proposed in #8925 applies the final URL to the style but there's no JS event). |
I don't know, but that's only one case. It's also common for
I'd avoid limiting same-origin use-cases due to cross-origin limitations. |
It's a valid opinion but would not be a light decision and requires further thinking. same-site has been a big request so far. |
I want us to consider how this could create a gotcha with BFCache. document.addEventListener("viewtransitionbeforecapture", (event) => {
// Cancel the transition (based on new URL) if needed.
/* ... */
// Set up names on elements based on the new URL.
if (shouldTagThumbnail(event.toURL)) {
thumbnail.style.viewTransitionName = "full-embed";
}
}); If after doing this the document is saved to BFCache and then restored, it would be restored with `thumbnail.style.viewTransitionName === "full-embed". Not sure if there is a way around this or if this should stop us from doing this, but wanted it to be documented. |
What does the event give us that we don't get from URL matching in @view-transition {
navigation: auto;
to: url('destination.html');
type: addFullEmbedName;
}
@view-transition {
navigation: none;
to: url('notransition.html');
}
:root:active-view-transition(addFullEmbedName) #thumbnail {
view-transition-name: full-embed;
} The example also allows adding opaque context (as mentioned in #9526) this can be achieved in other ways, e.g. session storage. If the page really wants to run some JS before the transition capture, couldn't they do so by listening to navigations from the navigation API? |
There's 2 modes with which authors can add names and both work with BFCache.
|
We haven't yet decided whether the URL matching for
The |
Yes, I know this is possible, I meant that it creates a "gotcha" because you have to remember to clear names you set on this event. |
Agreed. That's why developers should use types instead. It avoids having to manually track transition lifetime for updating styles. |
Actually you'd have the same gotcha with the Also if it's in the navigation API people won't be tempted to use a VT just to get the redirect info. |
I think the gotcha of remembering to reset names is always going to happen if you're using inline styles. Irrespective of whether we have a script event with post redirect info. Since capturing will always be async, it'll run at the next rendering loop after this event.
That's a good question. I was wondering whether VT-specific is nicer from a performance standpoint. We don't have to delay the navigation on dispatch of this event unless there is a transition. In the transition case we have to go back to the page to capture old snapshots anyway so the additional event has no perf impact. But you can do the above with a generic event as well. The browser can track whether an event handler is registered or allow making the event passive so event dispatch doesn't block the navigation from being committed. Given that, navigation API seems like a better spot for it. |
As long as this is constrained to same-origin redirects, aren't the performance characteristics of this event the same as |
Is that a spec requirement or an implementation detail. I could see a browser implementation switching to the new Document before dispatching events like |
Spec requirement,. See https://html.spec.whatwg.org/#unload-a-document step 4. |
Ah. In that case, don't see any perf reason to have another navigation event later in the navigation's lifecycle. While we're thinking about this, we likely don't need this event to be cancellable like |
Handled by pageconceal in progress. |
View Transition API needs to provide an event on the old Document to enable customization of the transition based on the URL for the new Document and the current Document state. For example, the Document could have changed from user interaction after its first load.
The proposed IDL is as follows:
The following is sample code using this event:
The text was updated successfully, but these errors were encountered: