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

Support for Chrome's Document Transitions #5689

Closed
ramiroaisen opened this issue Jul 24, 2022 · 8 comments · Fixed by #9605
Closed

Support for Chrome's Document Transitions #5689

ramiroaisen opened this issue Jul 24, 2022 · 8 comments · Fixed by #9605
Labels
feature request New feature or request
Milestone

Comments

@ramiroaisen
Copy link

ramiroaisen commented Jul 24, 2022

Describe the problem

This issue is to track support for Chrome's Document Transitions API AKA Shared Element Transitions on navigations inside sveltekit

More info about Chrome's feature and status can be found here:

https://github.com/WICG/shared-element-transitions/blob/main/developer-guide.md
https://github.com/WICG/shared-element-transitions/blob/main/explainer.md
https://chromestatus.com/feature/5193009714954240

The only reason this is hard to implement in userland is because the time between beforeNavigate and afterNavigate could be considerable considering sveltekit may have to make an http request in the middle of it or importing other modules.

Describe the proposed solution

Provide hooks like afterNavigate and beforeNavigate but that triggers just before and after the dom updates.
That way the user can call document.createDocumentTransition on their own

Alternatives considered

Provide a property in the sveltekit.config.js file to optionally enable this feature.
This way is the simple one, sveltekit just have to call document.createDocumentTransition before new navigations updates the dom, update the dom and then resolve the promise.

Importance

nice to have

Additional Information

No response

@ramiroaisen ramiroaisen changed the title Support for Chrome document.createDocumentTransition Support for Chrome's document.createDocumentTransition' Jul 24, 2022
@ramiroaisen ramiroaisen changed the title Support for Chrome's document.createDocumentTransition' Support for Chrome's document.createDocumentTransition Jul 24, 2022
@ramiroaisen ramiroaisen changed the title Support for Chrome's document.createDocumentTransition Support for Chrome's Shared Element Transitions Jul 24, 2022
@ramiroaisen ramiroaisen changed the title Support for Chrome's Shared Element Transitions Support for Chrome's Document Transitions Jul 24, 2022
@dominikg
Copy link
Member

@Rich-Harris
Copy link
Member

I think we need to add a lifecycle function that runs immediately before the DOM updates that are followed by afterNavigate for the purposes of #5478 (comment); I think that would basically solve this issue at the same time. We just need to bikeshed naming

@geoffrich
Copy link
Member

May I suggest: beforeAfterNavigate? And then we could have a counterpart, afterBeforeNavigate (mostly kidding)

But yes, this would be super helpful for integrating with shared element transitions. My demo currently starts the transition in beforeNavigate, which has the downside of waiting for a network call to complete the transition. It would be better to start the transition after the network call but before the DOM is updated so the page can still be interactive while the network call happens -- once you call transition.start, the page is basically a static screenshot.

From the explainer:

The API supports asynchronous DOM updates, which are common in most frameworks. To make this work, callback should return a promise that resolves once the DOM update is complete. However, remember that the user is left with a non-interactive screenshot between callback being called and its promise resolving, so this should happen as fast as possible. Specifically, avoid things like network activity – do those before creating the transition, like this:

As for bikeshedding: if we're going after your previous comment, perhaps beforeNavigateCommit? Though that's a little obtuse. beforePageUpdate?

@ramiroaisen
Copy link
Author

Maybe beforeNavigationUpdate and afterNavigationUpdate

@tcc-sejohnson tcc-sejohnson added the feature request New feature or request label Jul 27, 2022
@benmccann benmccann added this to the whenever milestone Aug 19, 2022
@muellercornelius
Copy link

or beforeNavigationDomUpdate and afterNavigationDomUpdate to make i even more clear?

@muellercornelius
Copy link

any news on this one?

@dummdidumm
Copy link
Member

dummdidumm commented Nov 9, 2022

What news? This feature isn't even finalized from browsers yet, we won't add support before that happens.

@Rich-Harris
Copy link
Member

Revisiting this now that the View Transitions API (as it's now called) is in Chrome stable. Opened a PR, would be glad for feedback from anyone who has played around with this stuff: #9605

benmccann added a commit that referenced this issue Aug 17, 2023
dummdidumm added a commit that referenced this issue Aug 29, 2023
…#9605)

Fixes #5689. This adds an onNavigate lifecycle function.

---------

Co-authored-by: Rich Harris <git@rich-harris.dev>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Geoff Rich <4992896+geoffrich@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants