11import { afterNavigate , beforeNavigate } from '$app/navigation' ;
22import { getTransitionContext } from '$lib/utils/resource-context' ;
3- import { onDestroy } from 'svelte' ;
43
54// Call this hook on this first page before you start the page transition.
65// For Shared Element Transitions, you need to call the transition.start()
76// method before the next page begins to render, and you need to do the
87// Document Object Model (DOM) modification or setting of new shared
98// elements inside the callback so that this hook returns the promise and
109// defers to the callback resolve.
11- export const prepareTransitionFromPage = ( ) => {
10+ export const preparePageTransition = ( ) => {
1211 const transitionStore = getTransitionContext ( ) ;
12+ let unsub ;
1313
14+ // before navigating, start a new transition
1415 beforeNavigate ( ( { to } ) => {
16+ unsub ?. ( ) ;
17+
1518 // Feature detection
1619 if ( ! document . createDocumentTransition ) {
1720 return ;
@@ -32,16 +35,6 @@ export const prepareTransitionFromPage = () => {
3235 } ) ) ;
3336 } ) ;
3437 } ) ;
35- } ;
36-
37- // Call this hook on the second page. Inside the useEffect hook, you can
38- // refer to the actual DOM element and set them as shared elements with the
39- // transition.setElement() method. When the resolver function is called,
40- // the transition is initiated between the captured images and newly set
41- // shared elements.
42- export const prepareTransitionToPage = ( ) => {
43- const transitionStore = getTransitionContext ( ) ;
44- let unsub ;
4538
4639 afterNavigate ( ( { to } ) => {
4740 const transitionKey = to . pathname ;
@@ -54,8 +47,4 @@ export const prepareTransitionToPage = () => {
5447 resolver ( ) ;
5548 } ) ;
5649 } ) ;
57-
58- onDestroy ( ( ) => {
59- unsub ?. ( ) ;
60- } ) ;
6150} ;
0 commit comments