mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
revert(mobile): keep the page transitions' timing and drop the unused route preload
The previous commit carried, by mistake, shorter page transitions and a route preloader that was never wired up. Both go back to how they were; the warm-up and day rail fixes stay.
This commit is contained in:
@@ -44,33 +44,9 @@ export function retryUrlFor(error: unknown): string | null {
|
||||
return busted.href;
|
||||
}
|
||||
|
||||
/** Every route loader, so the phone can fetch them ahead while idle (preloadLazyRoutes). */
|
||||
const loaders: (() => Promise<unknown>)[] = [];
|
||||
|
||||
/**
|
||||
* Fetches every lazily loaded page in the background, a few at a time, so
|
||||
* opening one later does not wait for the network. A loader that fails is
|
||||
* simply tried again when the page is opened. Skipped where the user asked to
|
||||
* save data.
|
||||
*/
|
||||
export function preloadLazyRoutes(): void {
|
||||
const connection = (navigator as { connection?: { saveData?: boolean } }).connection;
|
||||
if (connection?.saveData) return;
|
||||
const queue = [...loaders];
|
||||
const next = () => {
|
||||
const load = queue.shift();
|
||||
if (!load) return;
|
||||
void load()
|
||||
.catch(() => {})
|
||||
.then(next);
|
||||
};
|
||||
for (let i = 0; i < 3; i++) next();
|
||||
}
|
||||
|
||||
export function lazyWithRetry<T extends ComponentType<any>>(
|
||||
load: () => Promise<{ default: T }>
|
||||
): LazyExoticComponent<T> {
|
||||
loaders.push(load);
|
||||
return lazy(() =>
|
||||
load()
|
||||
.catch((error: unknown) => {
|
||||
|
||||
Reference in New Issue
Block a user