Skip to content

Commit 18ac898

Browse files
committed
perf: lazy load FAQ and OriginStory modals
Use React.lazy() to defer loading of FaqModal and OriginStoryModal until they are actually needed. This reduces the initial bundle size since these modals are only shown occasionally.
1 parent 7a5999c commit 18ac898

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

src/App.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import { useCallback, useEffect, useState, useRef } from 'react'
1+
import { useCallback, useEffect, useState, useRef, lazy, Suspense } from 'react'
22
import { ToastContainer } from './components/Notifications/ToastContainer'
33
import { ApiKeyInput } from './components/Auth/ApiKeyInput'
44
import { ApiKeyStatus } from './components/Auth/ApiKeyStatus'
55
import { FilterBar } from './components/Filters/FilterBar'
66
import { Board } from './components/Board/Board'
77
import { EmptyBoardWelcome } from './components/Board/EmptyBoardWelcome'
88
import { ApplyChangesButton } from './components/Board/ApplyChangesButton'
9-
import { FAQModal } from './components/FAQ/FaqModal'
10-
import { OriginStoryModal } from './components/OriginStory/OriginStoryModal'
9+
10+
// Lazy load modals to improve initial bundle size
11+
const FAQModal = lazy(() =>
12+
import('./components/FAQ/FaqModal').then((m) => ({ default: m.FAQModal })),
13+
)
14+
const OriginStoryModal = lazy(() =>
15+
import('./components/OriginStory/OriginStoryModal').then((m) => ({
16+
default: m.OriginStoryModal,
17+
})),
18+
)
1119
import { useStore } from './store'
1220
import { useUrlFilters } from './hooks/use-url-filters'
1321
import { saveFilters, getFilters } from './lib/storage/filter-storage'
@@ -388,12 +396,14 @@ function App() {
388396
<ApiKeyInput isOpen={true} onClose={() => {}} onOpenFAQ={handleOpenFAQ} />
389397

390398
{/* FAQ Modal */}
391-
<FAQModal
392-
isOpen={showFAQModal}
393-
onClose={() => {
394-
setShowFAQModal(false)
395-
}}
396-
/>
399+
<Suspense fallback={null}>
400+
<FAQModal
401+
isOpen={showFAQModal}
402+
onClose={() => {
403+
setShowFAQModal(false)
404+
}}
405+
/>
406+
</Suspense>
397407

398408
<ToastContainer toasts={toasts} removeToast={removeToast} />
399409
</div>
@@ -553,20 +563,24 @@ function App() {
553563
<ApiKeyInput isOpen={showApiKeyModal} onClose={handleCloseModal} onOpenFAQ={handleOpenFAQ} />
554564

555565
{/* FAQ Modal */}
556-
<FAQModal
557-
isOpen={showFAQModal}
558-
onClose={() => {
559-
setShowFAQModal(false)
560-
}}
561-
/>
566+
<Suspense fallback={null}>
567+
<FAQModal
568+
isOpen={showFAQModal}
569+
onClose={() => {
570+
setShowFAQModal(false)
571+
}}
572+
/>
573+
</Suspense>
562574

563575
{/* Origin Story Modal (easter egg) */}
564-
<OriginStoryModal
565-
isOpen={showOriginStoryModal}
566-
onClose={() => {
567-
setShowOriginStoryModal(false)
568-
}}
569-
/>
576+
<Suspense fallback={null}>
577+
<OriginStoryModal
578+
isOpen={showOriginStoryModal}
579+
onClose={() => {
580+
setShowOriginStoryModal(false)
581+
}}
582+
/>
583+
</Suspense>
570584
</div>
571585
)
572586
}

0 commit comments

Comments
 (0)