From 71fbe7774d3ed63fcb84bc644da997921bc049b2 Mon Sep 17 00:00:00 2001 From: codex-bot Date: Mon, 2 Nov 2026 07:31:25 +0300 Subject: [PATCH] refactor: replace repeated lazy page wrappers with lazyPage helper (#131) (#132) --- src/app/routes/AppRoutes/AppRoutes.tsx | 122 ++++++------------------- 1 file changed, 28 insertions(+), 94 deletions(-) diff --git a/src/app/routes/AppRoutes/AppRoutes.tsx b/src/app/routes/AppRoutes/AppRoutes.tsx index fea6244..ec75090 100644 --- a/src/app/routes/AppRoutes/AppRoutes.tsx +++ b/src/app/routes/AppRoutes/AppRoutes.tsx @@ -1,4 +1,4 @@ -import type { FC } from "react"; +import type { ComponentType, FC } from "react"; import { lazy } from "react"; import { Navigate, Route, Routes } from "react-router"; @@ -6,101 +6,35 @@ import { Navigate, Route, Routes } from "react-router"; import { LazyPage } from "../RouteFallback"; import { Protected, Public } from "../RouteGuards"; -const CardPage = lazy(async () => { - const { CardPage } = await import("@/pages/card"); +// Pages use named exports; React.lazy needs a default export per dynamic import (one chunk each). +function lazyPage( + load: () => Promise>, + name: Name, +) { + return lazy(async () => { + const page = await load(); - return { default: CardPage }; -}); + // eslint-disable-next-line security/detect-object-injection -- `name` is a compile-time literal checked against the module's exports. + return { default: page[name] }; + }); +} -const CardsPage = lazy(async () => { - const { CardsPage } = await import("@/pages/cards"); - - return { default: CardsPage }; -}); - -const BondPage = lazy(async () => { - const { BondPage } = await import("@/pages/bond"); - - return { default: BondPage }; -}); - -const BondsPage = lazy(async () => { - const { BondsPage } = await import("@/pages/bonds"); - - return { default: BondsPage }; -}); - -const StockPage = lazy(async () => { - const { StockPage } = await import("@/pages/stock"); - - return { default: StockPage }; -}); - -const StocksPage = lazy(async () => { - const { StocksPage } = await import("@/pages/stocks"); - - return { default: StocksPage }; -}); - -const AccountPage = lazy(async () => { - const { AccountPage } = await import("@/pages/account"); - - return { default: AccountPage }; -}); - -const AccountEventsPage = lazy(async () => { - const { AccountEventsPage } = await import("@/pages/account-events"); - - return { default: AccountEventsPage }; -}); - -const AccountOperationsPage = lazy(async () => { - const { AccountOperationsPage } = await import("@/pages/account-operations"); - - return { default: AccountOperationsPage }; -}); - -const AccountIncomePage = lazy(async () => { - const { AccountIncomePage } = await import("@/pages/account-income"); - - return { default: AccountIncomePage }; -}); - -const AccountsPage = lazy(async () => { - const { AccountsPage } = await import("@/pages/accounts"); - - return { default: AccountsPage }; -}); - -const LoginPage = lazy(async () => { - const { LoginPage } = await import("@/pages/login"); - - return { default: LoginPage }; -}); - -const NotFoundPage = lazy(async () => { - const { NotFoundPage } = await import("@/pages/not-found"); - - return { default: NotFoundPage }; -}); - -const RegisterPage = lazy(async () => { - const { RegisterPage } = await import("@/pages/register"); - - return { default: RegisterPage }; -}); - -const SettingsPage = lazy(async () => { - const { SettingsPage } = await import("@/pages/settings"); - - return { default: SettingsPage }; -}); - -const ProtectedLayout = lazy(async () => { - const { ProtectedLayout } = await import("../ProtectedLayout"); - - return { default: ProtectedLayout }; -}); +const CardPage = lazyPage(async () => import("@/pages/card"), "CardPage"); +const CardsPage = lazyPage(async () => import("@/pages/cards"), "CardsPage"); +const BondPage = lazyPage(async () => import("@/pages/bond"), "BondPage"); +const BondsPage = lazyPage(async () => import("@/pages/bonds"), "BondsPage"); +const StockPage = lazyPage(async () => import("@/pages/stock"), "StockPage"); +const StocksPage = lazyPage(async () => import("@/pages/stocks"), "StocksPage"); +const AccountPage = lazyPage(async () => import("@/pages/account"), "AccountPage"); +const AccountEventsPage = lazyPage(async () => import("@/pages/account-events"), "AccountEventsPage"); +const AccountOperationsPage = lazyPage(async () => import("@/pages/account-operations"), "AccountOperationsPage"); +const AccountIncomePage = lazyPage(async () => import("@/pages/account-income"), "AccountIncomePage"); +const AccountsPage = lazyPage(async () => import("@/pages/accounts"), "AccountsPage"); +const LoginPage = lazyPage(async () => import("@/pages/login"), "LoginPage"); +const NotFoundPage = lazyPage(async () => import("@/pages/not-found"), "NotFoundPage"); +const RegisterPage = lazyPage(async () => import("@/pages/register"), "RegisterPage"); +const SettingsPage = lazyPage(async () => import("@/pages/settings"), "SettingsPage"); +const ProtectedLayout = lazyPage(async () => import("../ProtectedLayout"), "ProtectedLayout"); const AppRoutes: FC = () => (