From 2dcce00a988945616e73790f4473760087bdd430 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 19 Jul 2026 20:13:12 +0200 Subject: [PATCH] perf: lazy-load auth, settings, inbox and explore route subtrees --- src/app/pages/Router.tsx | 128 ++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 23 deletions(-) diff --git a/src/app/pages/Router.tsx b/src/app/pages/Router.tsx index 4686929ca..1114d842e 100644 --- a/src/app/pages/Router.tsx +++ b/src/app/pages/Router.tsx @@ -1,3 +1,4 @@ +import { lazy, Suspense } from 'react'; import { Outlet, Route, @@ -10,16 +11,12 @@ import * as Sentry from '@sentry/react'; import type { ClientConfig } from '$hooks/useClientConfig'; import { ErrorPage } from '$components/DefaultErrorPage'; -import { SettingsRoute } from '$features/settings'; -import { SettingsShallowRouteRenderer } from '$features/settings/SettingsShallowRouteRenderer'; import { Room } from '$features/room'; import { Lobby } from '$features/lobby'; import { PageRoot } from '$components/page'; import { ScreenSize } from '$hooks/useScreenSize'; import { ReceiveSelfDeviceVerification } from '$components/DeviceVerification'; import { AutoRestoreBackupOnVerification } from '$components/BackupRestore'; -import { RoomSettingsRenderer } from '$features/room-settings'; -import { SpaceSettingsRenderer } from '$features/space-settings'; import { UserRoomProfileRenderer } from '$components/UserRoomProfileRenderer'; import { CreateRoomModalRenderer } from '$features/create-room'; import { CreateSpaceModalRenderer } from '$features/create-space'; @@ -31,7 +28,7 @@ import { NotificationJumper } from '$hooks/useNotificationJumper'; import { SearchModalRenderer } from '$features/navigate'; import { GlobalKeyboardShortcuts } from '$components/GlobalKeyboardShortcuts'; import { CallEmbedProvider } from '$components/CallEmbedProvider'; -import { AuthLayout, Login, Register, ResetPassword } from './auth'; +import { SplashScreen } from '$components/splash-screen'; import { DIRECT_PATH, EXPLORE_PATH, @@ -71,8 +68,39 @@ import { HandleNotificationClick, ClientNonUIFeatures } from './client/ClientNon import { Home, HomeRouteRoomProvider, HomeSearch } from './client/home'; import { Direct, DirectCreate, DirectRouteRoomProvider } from './client/direct'; import { RouteSpaceProvider, Space, SpaceRouteRoomProvider, SpaceSearch } from './client/space'; -import { Explore, FeaturedRooms, PublicRooms } from './client/explore'; -import { Notifications, Inbox, Invites, Bookmarks } from './client/inbox'; +// Lazy-loaded: auth subtree, settings, inbox/bookmarks, explore +const AuthLayout = lazy(() => import('./auth').then((m) => ({ default: m.AuthLayout }))); +const Login = lazy(() => import('./auth').then((m) => ({ default: m.Login }))); +const Register = lazy(() => import('./auth').then((m) => ({ default: m.Register }))); +const ResetPassword = lazy(() => import('./auth').then((m) => ({ default: m.ResetPassword }))); + +const SettingsRoute = lazy(() => import('$features/settings').then((m) => ({ default: m.SettingsRoute }))); +const SettingsShallowRouteRenderer = lazy(() => + import('$features/settings/SettingsShallowRouteRenderer').then((m) => ({ + default: m.SettingsShallowRouteRenderer, + })) +); +const RoomSettingsRenderer = lazy(() => + import('$features/room-settings').then((m) => ({ default: m.RoomSettingsRenderer })) +); +const SpaceSettingsRenderer = lazy(() => + import('$features/space-settings').then((m) => ({ default: m.SpaceSettingsRenderer })) +); + +const Notifications = lazy(() => + import('./client/inbox').then((m) => ({ default: m.Notifications })) +); +const Inbox = lazy(() => import('./client/inbox').then((m) => ({ default: m.Inbox }))); +const Invites = lazy(() => import('./client/inbox').then((m) => ({ default: m.Invites }))); +const Bookmarks = lazy(() => import('./client/inbox').then((m) => ({ default: m.Bookmarks }))); + +const Explore = lazy(() => import('./client/explore').then((m) => ({ default: m.Explore }))); +const FeaturedRooms = lazy(() => + import('./client/explore').then((m) => ({ default: m.FeaturedRooms })) +); +const PublicRooms = lazy(() => + import('./client/explore').then((m) => ({ default: m.PublicRooms })) +); import { setAfterLoginRedirectPath } from './afterLoginRedirectPath'; import { WelcomePage } from './client/WelcomePage'; import { SidebarNav } from './client/SidebarNav'; @@ -148,11 +176,13 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) )} beforeCapture={(scope) => scope.setTag('section', 'auth')} > - <> - - - - + {null}}> + <> + + + + + } > @@ -215,9 +245,15 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) - - - + + + + + + + + + {/* Screen reader live region — populated by announce() in utils/announce.ts */}
} nav={ - + {null}}> + + } > @@ -368,20 +406,43 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) element={} /> )} - } /> - } /> + {null}}> + + + } + /> + {null}}> + + + } + /> } /> } /> } /> - } /> + {null}}> + + + } + /> - + {null}}> + + } > @@ -396,9 +457,30 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) element={} /> )} - } /> - } /> - } /> + {null}}> + + + } + /> + {null}}> + + + } + /> + {null}}> + + + } + /> } />