@@ -50,7 +50,7 @@ function updateTitle(nextPage: { id: string; display?: string }): void {
5050 }
5151}
5252
53- async function showLoading ( {
53+ async function showSyncLoading ( {
5454 loadingOptions,
5555 totalDuration,
5656 easingMethod,
@@ -97,7 +97,7 @@ async function showLoading({
9797 void PageLoading . updateBar ( 100 , 125 ) ;
9898 PageLoading . updateText ( "Done" ) ;
9999 } else {
100- await options . waitFor ( ) ;
100+ await options . loadingPromise ( ) ;
101101 }
102102 }
103103
@@ -123,7 +123,7 @@ async function getLoadingPromiseWithBarKeyframes(
123123 fillOffset : number
124124) : Promise < void > {
125125 let aborted = false ;
126- let loadingPromise = loadingOptions . waitFor ( ) ;
126+ let loadingPromise = loadingOptions . loadingPromise ( ) ;
127127
128128 // Animate bar keyframes, but allow aborting if loading.promise finishes first
129129 const keyframePromise = ( async ( ) => {
@@ -214,28 +214,25 @@ export async function change(
214214 previousPage . element . addClass ( "hidden" ) ;
215215 await previousPage ?. afterHide ( ) ;
216216
217+ // we need to evaluate and store next page loading mode in case options.loadingOptions.loadingMode is sync
218+ const nextPageLoadingMode = nextPage . loadingOptions ?. loadingMode ( ) ;
219+
217220 //show loading page if needed
218221 try {
219- let loadingOptions : LoadingOptions [ ] = [ ] ;
220- if ( options . loadingOptions ) {
221- loadingOptions . push ( options . loadingOptions ) ;
222+ let syncLoadingOptions : LoadingOptions [ ] = [ ] ;
223+ if ( options . loadingOptions ?. loadingMode ( ) === "sync" ) {
224+ syncLoadingOptions . push ( options . loadingOptions ) ;
222225 }
223- if ( nextPage . loadingOptions ) {
224- loadingOptions . push ( nextPage . loadingOptions ) ;
226+ if ( nextPage . loadingOptions ?. loadingMode ( ) === "sync" ) {
227+ syncLoadingOptions . push ( nextPage . loadingOptions ) ;
225228 }
226229
227- if ( loadingOptions . length > 0 ) {
228- const shouldShowLoading =
229- options . loadingOptions ?. shouldLoad ( ) ||
230- nextPage . loadingOptions ?. shouldLoad ( ) ;
231-
232- if ( shouldShowLoading === true ) {
233- await showLoading ( {
234- loadingOptions,
235- totalDuration,
236- easingMethod,
237- } ) ;
238- }
230+ if ( syncLoadingOptions . length > 0 ) {
231+ await showSyncLoading ( {
232+ loadingOptions : syncLoadingOptions ,
233+ totalDuration,
234+ easingMethod,
235+ } ) ;
239236 }
240237 } catch ( error ) {
241238 pages . loading . element . addClass ( "active" ) ;
@@ -263,6 +260,17 @@ export async function change(
263260 // @ts -expect-error for the future (i think)
264261 data : options . data ,
265262 } ) ;
263+
264+ if (
265+ typeof nextPageLoadingMode === "object" &&
266+ nextPageLoadingMode . mode === "async"
267+ ) {
268+ nextPageLoadingMode . beforeLoading ( ) ;
269+ void nextPage ?. loadingOptions ?. loadingPromise ( ) . then ( ( ) => {
270+ nextPageLoadingMode . afterLoading ( ) ;
271+ } ) ;
272+ }
273+
266274 nextPage . element . removeClass ( "hidden" ) . css ( "opacity" , 0 ) ;
267275 await Misc . promiseAnimation (
268276 nextPage . element ,
0 commit comments