Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

perf(ui): lazy-load MobileScannerPage and optimize bundle splitting (#7122)

brios9aaf4173036f
diff --git a/frontend/editor/src/core/App.tsx b/frontend/editor/src/core/App.tsx
index 566e861520..6fd23e5510 100644
--- a/frontend/editor/src/core/App.tsx
+++ b/frontend/editor/src/core/App.tsx
@@ -1,4 +1,4 @@
-import { Suspense } from "react";
+import { Suspense, lazy } from "react";
import { Routes, Route } from "react-router-dom";
import { AppProviders } from "@app/components/AppProviders";
import { AppLayout } from "@app/components/AppLayout";
@@ -6,9 +6,10 @@ import { LoadingFallback } from "@app/components/shared/LoadingFallback";
import { ThemeProvider } from "@app/components/shared/ThemeProvider";
import { PreferencesProvider } from "@app/contexts/PreferencesContext";
import HomePage from "@app/pages/HomePage";
-import MobileScannerPage from "@app/pages/MobileScannerPage";
import Onboarding from "@app/components/onboarding/Onboarding";
+const MobileScannerPage = lazy(() => import("@app/pages/MobileScannerPage"));
+
// Import global styles
import "@app/styles/tailwind.css";
import "@app/styles/cookieconsent.css";
diff --git a/frontend/editor/src/proprietary/App.tsx b/frontend/editor/src/proprietary/App.tsx
index e98064ebc8..a2103bd60a 100644
--- a/frontend/editor/src/proprietary/App.tsx
+++ b/frontend/editor/src/proprietary/App.tsx
@@ -1,4 +1,4 @@
-import { Suspense } from "react";
+import { Suspense, lazy } from "react";
import { Routes, Route, useParams } from "react-router-dom";
import { AppProviders } from "@app/components/AppProviders";
import { AppLayout } from "@app/components/AppLayout";
@@ -12,9 +12,10 @@ import AuthCallback from "@app/routes/AuthCallback";
import InviteAccept from "@app/routes/InviteAccept";
import ShareLinkPage from "@app/routes/ShareLinkPage";
import ParticipantView from "@app/components/workflow/ParticipantView";
-import MobileScannerPage from "@app/pages/MobileScannerPage";
import Onboarding from "@app/components/onboarding/Onboarding";
import WatchedFoldersRegistration from "@app/components/watchedFolders/WatchedFoldersRegistration";
+
+const MobileScannerPage = lazy(() => import("@app/pages/MobileScannerPage"));
import { WATCHED_FOLDERS_ENABLED } from "@app/constants/featureFlags";
import { getAdminRouteExtensions } from "@app/routes/adminRouteExtensions";
import { LoginLandingRedirect } from "@app/components/LoginLandingRedirect";
diff --git a/frontend/editor/src/saas/App.tsx b/frontend/editor/src/saas/App.tsx
index 32af9a6782..9509f630b0 100644
--- a/frontend/editor/src/saas/App.tsx
+++ b/frontend/editor/src/saas/App.tsx
@@ -1,4 +1,4 @@
-import { Suspense, type ReactNode } from "react";
+import { Suspense, lazy, type ReactNode } from "react";
import { Routes, Route, useLocation } from "react-router-dom";
import { isAuthRoute } from "@app/utils/pathUtils";
import { AppProviders } from "@app/components/AppProviders";
@@ -16,13 +16,14 @@ import AuthCallback from "@app/routes/AuthCallback";
import ResetPassword from "@app/routes/ResetPassword";
import OAuthConsent from "@app/routes/OAuthConsent";
import ShareLinkPage from "@app/routes/ShareLinkPage";
-import MobileScannerPage from "@app/pages/MobileScannerPage";
import { getAdminRouteExtensions } from "@app/routes/adminRouteExtensions";
import OnboardingBootstrap from "@app/components/OnboardingBootstrap";
import SignupRequiredBootstrap from "@app/components/SignupRequiredBootstrap";
import UsageLimitModalHost from "@app/components/UsageLimitModalHost";
import { LoginLandingRedirect } from "@app/components/LoginLandingRedirect";
+const MobileScannerPage = lazy(() => import("@app/pages/MobileScannerPage"));
+
// Import global styles
import "@app/styles/tailwind.css";
import "@app/auth/ui/auth-theme.css";
diff --git a/frontend/editor/vite.config.ts b/frontend/editor/vite.config.ts
index 0d367d2465..2e72d1efec 100644
--- a/frontend/editor/vite.config.ts
+++ b/frontend/editor/vite.config.ts
@@ -358,9 +358,36 @@ export default defineConfig(async ({ mode, command }) => {
target: "esnext",
rollupOptions: {
output: {
- manualChunks: {
- "vendor-react": ["react", "react-dom"],
- "pdf-engine": ["@embedpdf/engines", "@embedpdf/pdfium"],
+ manualChunks(id) {
+ if (id.includes("material-symbols-icons.json"))
+ return "vendor-iconset";
+ if (id.includes("node_modules")) {
+ if (id.includes("pdfjs-dist")) return "vendor-pdfjs";
+ if (id.includes("@embedpdf")) return "vendor-embedpdf";
+ if (
+ id.includes("react") ||
+ id.includes("@mantine") ||
+ id.includes("@emotion") ||
+ id.includes("@mui") ||
+ id.includes("@iconify")
+ ) {
+ return "vendor-ui";
+ }
+ if (id.includes("@supabase")) return "vendor-supabase";
+ if (id.includes("posthog-js") || id.includes("@posthog"))
+ return "vendor-posthog";
+ if (id.includes("@cantoo/pdf-lib") || id.includes("pdf-lib"))
+ return "vendor-pdflib";
+ if (
+ id.includes("recharts") ||
+ id.includes("d3") ||
+ id.includes("decimal.js")
+ )
+ return "vendor-charts";
+ if (id.includes("jszip") || id.includes("pako"))
+ return "vendor-zip";
+ if (id.includes("i18next")) return "vendor-i18n";
+ }
},
},
},