From 55ac67b306a9e1e506e6ed6ceccc8bd7992dbdaf Mon Sep 17 00:00:00 2001 From: Houssem Eddine BENABDALLAH Date: Thu, 22 Oct 2026 23:35:30 +0200 Subject: [PATCH] perf: load the photo viewer only when a photo opens --- resources/js/layouts/app-layout.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/resources/js/layouts/app-layout.tsx b/resources/js/layouts/app-layout.tsx index e0af24a906..3224de61b1 100644 --- a/resources/js/layouts/app-layout.tsx +++ b/resources/js/layouts/app-layout.tsx @@ -1,5 +1,5 @@ import { Head, usePage, usePoll } from '@inertiajs/react'; -import { useCallback, useEffect, useState } from 'react'; +import { lazy, Suspense, useCallback, useEffect, useState } from 'react'; import { AppAside } from '@/components/app-aside'; import { AppNav, @@ -13,7 +13,6 @@ import { CommitComposerDialog, focusVisibleComposer, } from '@/components/commit-composer-dialog'; -import { CommitImageViewer } from '@/components/commit-image-viewer'; import { CommitStarPolling } from '@/components/commit-star-polling'; import { DeletedPageDialog } from '@/components/deleted-page-dialog'; import { ExternalLinkGuard } from '@/components/external-link-guard'; @@ -42,6 +41,7 @@ import { useIsListening } from '@/hooks/use-realtime'; import { useTabSlide } from '@/hooks/use-tab-slide'; import { signIn } from '@/lib/auth'; import { backgroundPollOptions } from '@/lib/background-poll'; +import type { CommitPhoto } from '@/lib/commit-photo'; import { isPageGone } from '@/lib/deleted-resources'; import type { IssueKind } from '@/lib/issue-commands'; import { userChannel } from '@/lib/realtime'; @@ -49,11 +49,17 @@ import type { SearchAction } from '@/lib/search-actions'; import { cn } from '@/lib/utils'; import type { AppLayoutProps } from '@/types'; +// The lightbox is only needed once a photo opens, so it loads then instead of on every page. +const CommitImageViewer = lazy(async () => ({ + default: (await import('@/components/commit-image-viewer')) + .CommitImageViewer, +})); + export default function AppLayout({ children }: AppLayoutProps) { const { component, - props: { auth, isLiteMobileApp }, - } = usePage(); + props: { auth, isLiteMobileApp, photo }, + } = usePage<{ photo?: CommitPhoto }>(); const { isLayoutOpen } = useNavOpen(); const [isShowingShortcuts, setIsShowingShortcuts] = useState(false); const [isSearching, setIsSearching] = useState(false); @@ -62,6 +68,12 @@ export default function AppLayout({ children }: AppLayoutProps) { null, ); const [isGoingLive, setIsGoingLive] = useState(false); + // Stays mounted after the photo closes, so the lightbox can animate out. + const [hasShownPhoto, setHasShownPhoto] = useState(false); + + if (photo !== undefined && !hasShownPhoto) { + setHasShownPhoto(true); + } const showShortcuts = useCallback(() => setIsShowingShortcuts(true), []); const openSearch = useCallback(() => setIsSearching(true), []); const isGuest = auth.user === null; @@ -179,7 +191,11 @@ export default function AppLayout({ children }: AppLayoutProps) { {deletedPage === null ? ( - + hasShownPhoto && ( + + + + ) ) : ( )}