Skip to content

Commit 1ee8c41

Browse files
committed
fix: intermittent blank white screen bug.
1 parent 92478c7 commit 1ee8c41

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

apps/web/src/App.tsx

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { lazy } from "react";
1+
import React from "react";
22
import {
33
RouteObject,
44
RouterProvider,
@@ -7,40 +7,51 @@ import {
77
import { Web } from "@litespace/utils/routes";
88
import * as Sentry from "@sentry/react";
99
import Splash from "@/pages/Splash";
10+
import { lazyWithRetry } from "@/lib/lazy";
1011

11-
const Root = lazy(() => import("@/pages/Root"));
12-
const Login = lazy(() => import("@/pages/Login"));
13-
const Register = lazy(() => import("@/pages/Register"));
14-
const Crash = lazy(() => import("@/pages/Crash"));
15-
const TutorProfile = lazy(() => import("@/pages/TutorProfile"));
16-
const CompleteProfile = lazy(() => import("@/pages/CompleteProfile"));
17-
const StudentDashboard = lazy(() => import("@/pages/StudentDashboard"));
18-
const LessonsSchedule = lazy(() => import("@/pages/LessonsSchedule"));
19-
const StudentSettings = lazy(() => import("@/pages/StudentSettings"));
20-
const Payments = lazy(() => import("@/pages/Payments"));
21-
const Tutors = lazy(() => import("@/pages/Tutors"));
22-
const Chat = lazy(() => import("@/pages/Chat"));
23-
const Lessons = lazy(() => import("@/pages/Lessons"));
24-
const Plans = lazy(() => import("@/pages/Plans"));
25-
const Lesson = lazy(() => import("@/pages/Lesson"));
26-
const TutorAccountSettings = lazy(() => import("@/pages/TutorAccountSettings"));
27-
const TutorProfileSettings = lazy(() => import("@/pages/TutorProfileSettings"));
28-
const ScheduleManagement = lazy(() => import("@/pages/ScheduleManagement"));
29-
const TutorDashboard = lazy(() => import("@/pages/TutorDashboard"));
30-
const Invoices = lazy(() => import("@/pages/Invoices"));
31-
const CardAdded = lazy(() => import("@/pages/CardAdded"));
32-
const Checkout = lazy(() => import("@/pages/Checkout"));
33-
const CompleteTutorProfile = lazy(() => import("@/pages/CompleteTutorProfile"));
34-
const TutorOnboarding = lazy(() => import("@/pages/TutorOnboarding"));
35-
const Interview = lazy(() => import("@/pages/Interview"));
36-
const DemoSession = lazy(() => import("@/pages/DemoSession"));
12+
const Root = lazyWithRetry(() => import("@/pages/Root"));
13+
const Login = lazyWithRetry(() => import("@/pages/Login"));
14+
const Register = lazyWithRetry(() => import("@/pages/Register"));
15+
const TutorProfile = lazyWithRetry(() => import("@/pages/TutorProfile"));
16+
const CompleteProfile = lazyWithRetry(() => import("@/pages/CompleteProfile"));
17+
const StudentDashboard = lazyWithRetry(
18+
() => import("@/pages/StudentDashboard")
19+
);
20+
const LessonsSchedule = lazyWithRetry(() => import("@/pages/LessonsSchedule"));
21+
const StudentSettings = lazyWithRetry(() => import("@/pages/StudentSettings"));
22+
const Payments = lazyWithRetry(() => import("@/pages/Payments"));
23+
const Tutors = lazyWithRetry(() => import("@/pages/Tutors"));
24+
const Chat = lazyWithRetry(() => import("@/pages/Chat"));
25+
const Lessons = lazyWithRetry(() => import("@/pages/Lessons"));
26+
const Plans = lazyWithRetry(() => import("@/pages/Plans"));
27+
const Lesson = lazyWithRetry(() => import("@/pages/Lesson"));
28+
const TutorAccountSettings = lazyWithRetry(
29+
() => import("@/pages/TutorAccountSettings")
30+
);
31+
const TutorProfileSettings = lazyWithRetry(
32+
() => import("@/pages/TutorProfileSettings")
33+
);
34+
const ScheduleManagement = lazyWithRetry(
35+
() => import("@/pages/ScheduleManagement")
36+
);
37+
const TutorDashboard = lazyWithRetry(() => import("@/pages/TutorDashboard"));
38+
const Invoices = lazyWithRetry(() => import("@/pages/Invoices"));
39+
const CardAdded = lazyWithRetry(() => import("@/pages/CardAdded"));
40+
const Checkout = lazyWithRetry(() => import("@/pages/Checkout"));
41+
const CompleteTutorProfile = lazyWithRetry(
42+
() => import("@/pages/CompleteTutorProfile")
43+
);
44+
const TutorOnboarding = lazyWithRetry(() => import("@/pages/TutorOnboarding"));
45+
const Interview = lazyWithRetry(() => import("@/pages/Interview"));
46+
const DemoSession = lazyWithRetry(() => import("@/pages/DemoSession"));
47+
const Crash = lazyWithRetry(() => import("@/pages/Crash"));
3748

3849
const createRouter = Sentry.wrapCreateBrowserRouterV6(createBrowserRouter);
3950

4051
function withCrash(routes: RouteObject[]): RouteObject[] {
4152
return routes.map((route) => ({
4253
...route,
43-
element: <Splash children={route.element} position="top" />,
54+
element: route.element,
4455
errorElement: <Splash children={<Crash />} position="top" />,
4556
}));
4657
}
@@ -80,7 +91,11 @@ const router = createRouter([
8091
]);
8192

8293
function App(): React.JSX.Element {
83-
return <RouterProvider router={router} />;
94+
return (
95+
<Splash position="top">
96+
<RouterProvider router={router} />;
97+
</Splash>
98+
);
8499
}
85100

86101
export default App;

apps/web/src/lib/lazy.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { lazy } from "react";
2+
3+
export function lazyWithRetry<T extends React.ComponentType>(
4+
importer: () => Promise<{ default: T }>
5+
): React.LazyExoticComponent<T> {
6+
return lazy(() =>
7+
importer().catch((error) => {
8+
console.error("Chunk load failed:", error);
9+
return new Promise<{ default: T }>((resolve) => {
10+
setTimeout(() => resolve(importer()), 1000);
11+
});
12+
})
13+
);
14+
}

apps/web/src/pages/Root.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
useNavigate,
3030
useSearchParams,
3131
} from "react-router-dom";
32+
import Splash from "@/pages/Splash";
3233

3334
const publicRoutes: Web[] = [
3435
Web.Login,
@@ -236,7 +237,9 @@ const Root: React.FC = () => {
236237

237238
{showNavigation ? <Navbar /> : null}
238239

239-
<Outlet />
240+
<Splash position="top">
241+
<Outlet />
242+
</Splash>
240243

241244
<FloatingButtons />
242245
</div>

apps/web/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default defineConfig({
3535
sourcemap: true,
3636
rollupOptions: {
3737
output: {
38+
entryFileNames: `[name]-[hash].js`,
39+
chunkFileNames: `[name]-[hash].js`,
3840
manualChunks: {
3941
lodash: ["lodash"],
4042
motion: ["framer-motion"],

0 commit comments

Comments
 (0)