From 63550a42b464dfdc4ff29db5764dace344de340f Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Mon, 11 Aug 2025 12:21:18 -0500 Subject: [PATCH] Implement lazy loading for 3D viewers to optimize bundle size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use React.lazy() and Suspense for BabylonViewer and BabylonTimelineViewer - Reduce main bundle size from 7.4MB to 336KB (95% reduction) - Split Babylon.js into separate chunk loaded only when 3D views are selected - Add ThreeDViewerLoading component with spinner for better UX - Babylon.js libraries now load on-demand when user clicks 3D view toggles Bundle optimization results: - Main bundle: 336KB (was 7.4MB) - Babylon chunk: 7MB (lazy-loaded) - BabylonViewer: 3.6KB (lazy-loaded) - BabylonTimelineViewer: 6.6KB (lazy-loaded) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../httprequestviewer/HTTPRequestViewer.tsx | 51 +++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/components/httprequestviewer/HTTPRequestViewer.tsx b/src/components/httprequestviewer/HTTPRequestViewer.tsx index bed1170..24bdb45 100644 --- a/src/components/httprequestviewer/HTTPRequestViewer.tsx +++ b/src/components/httprequestviewer/HTTPRequestViewer.tsx @@ -1,12 +1,49 @@ -import { useState, useMemo, useEffect } from 'react' +import { useState, useMemo, useEffect, lazy, Suspense } from 'react' import { useDatabaseTraceData } from '../../hooks/useDatabaseTraceData' import { getUrlParams, updateUrlWithTraceId } from '../../App' -import BabylonViewer from '../../BabylonViewer' -import BabylonTimelineViewer from '../../BabylonTimelineViewer' import RequestFilters from './RequestFilters' import RequestsTable from './RequestsTable' import styles from './HTTPRequestViewer.module.css' +// Lazy load 3D viewers to reduce main bundle size +const BabylonViewer = lazy(() => import('../../BabylonViewer')) +const BabylonTimelineViewer = lazy(() => import('../../BabylonTimelineViewer')) + +// Loading component for 3D viewers +const ThreeDViewerLoading = () => ( +
+
+
+ Loading 3D Viewer... +
+
+ Initializing Babylon.js +
+ +
+) + // Imported utilities import { ITEMS_PER_PAGE, SSIM_SIMILARITY_THRESHOLD } from './lib/httpRequestConstants' import { extractScreenshots, findUniqueScreenshots } from './lib/screenshotUtils' @@ -346,7 +383,9 @@ export default function HTTPRequestViewer({ traceId }: HTTPRequestViewerProps) {
- + }> + +
Legend:
@@ -385,7 +424,9 @@ export default function HTTPRequestViewer({ traceId }: HTTPRequestViewerProps) {
- + }> + +
Legend: