Skip to content

Commit 6c1b6df

Browse files
perf(web): load the pull request panels only when opened
ChatView imported PullRequestDetailPanel and ThreadPullRequestsPanel statically, so the pull request detail code shipped in the chat route's eager chunks for every thread, including threads that never open a pull request. In a production build the chat route's eager JS was 6958.8 KiB raw / 2230.6 KiB gzip. Load both panels with React.lazy behind Suspense, like the diff, device and file panels. The detail panel falls back to its existing ghost so a slow chunk load still shows the loading state. The chat route's eager JS drops to 6580.0 KiB raw / 2118.4 KiB gzip (-378.8 KiB raw, -112.2 KiB gzip). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c93a18c commit 6c1b6df

1 file changed

Lines changed: 55 additions & 43 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,10 @@ import {
286286
pullRequestPanelContext,
287287
threadPullRequestPanelTarget,
288288
} from "./pullRequest/pullRequestDetail.logic";
289-
import { PullRequestDetailPanel } from "./pullRequest/PullRequestDetailPanel";
290289
import { PullRequestDetailGhost } from "./pullRequest/PullRequestGhosts";
291290
import { PullRequestsUnavailableState } from "./pullRequest/PullRequestsUnavailableState";
292291
import { RightPanelTabs } from "./RightPanelTabs";
293292
import { LinkPullRequestDialogHost } from "./pullRequest/LinkPullRequestDialog";
294-
import { ThreadPullRequestsPanel } from "./pullRequest/ThreadPullRequestsPanel";
295293
import { useDeviceState } from "~/state/device";
296294
import { DeviceSetup } from "./device/DeviceSetup";
297295
import { Dialog } from "./ui/dialog";
@@ -714,6 +712,16 @@ const DevicePanel = lazy(() =>
714712
import("./device/DevicePanel").then((module) => ({ default: module.DevicePanel })),
715713
);
716714
const FilePreviewPanel = lazy(() => import("./files/FilePreviewPanel"));
715+
const PullRequestDetailPanel = lazy(() =>
716+
import("./pullRequest/PullRequestDetailPanel").then((module) => ({
717+
default: module.PullRequestDetailPanel,
718+
})),
719+
);
720+
const ThreadPullRequestsPanel = lazy(() =>
721+
import("./pullRequest/ThreadPullRequestsPanel").then((module) => ({
722+
default: module.ThreadPullRequestsPanel,
723+
})),
724+
);
717725
const EMPTY_PENDING_FILE_SURFACE_IDS: ReadonlySet<string> = new Set();
718726
const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
719727
"input",
@@ -11189,48 +11197,52 @@ export default function ChatView(props: ChatViewProps) {
1118911197
// is only right for the thread's own pull request, whose branch is already under the
1119011198
// reader's feet. A link the agent wrote can open any other one here, and that one has to be
1119111199
// checkable out like it is anywhere else.
11192-
<PullRequestDetailPanel
11193-
getShortcutContext={getShortcutContext}
11194-
shortcutsEnabled={
11195-
rightPanelOpen && activeRightPanelSurface?.id === renderedRightPanelSurface.id
11196-
}
11197-
key={`${renderedRightPanelSurface.host ?? ""}:${renderedRightPanelSurface.repository}#${renderedRightPanelSurface.number}`}
11198-
environmentId={activeThread.environmentId}
11199-
onSelectPullRequest={(reference) => {
11200-
if (activeThreadRef)
11201-
useRightPanelStore.getState().openPullRequest(activeThreadRef, {
11202-
projectId: reference.projectId,
11203-
repository: reference.repository,
11204-
number: reference.number,
11205-
...(reference.host ? { host: reference.host } : {}),
11206-
});
11207-
}}
11208-
threadRef={activeThreadRef}
11209-
reference={{
11210-
projectId: renderedRightPanelSurface.projectId as ProjectId,
11211-
...(renderedRightPanelSurface.host ? { host: renderedRightPanelSurface.host } : {}),
11212-
repository: renderedRightPanelSurface.repository,
11213-
number: renderedRightPanelSurface.number,
11214-
}}
11215-
context={pullRequestPanelContext(
11216-
{
11217-
projectId: activeThread.projectId,
11218-
pullRequests: visiblePullRequests,
11219-
linkedPullRequest: linkedThreadPullRequest,
11220-
branchPullRequest:
11221-
activeThreadShell?.branchPullRequest ?? activeThread.branchPullRequest,
11222-
},
11223-
renderedRightPanelSurface,
11224-
)}
11225-
composerDraftTarget={composerDraftTarget}
11226-
onBack={
11227-
activeThreadRef !== null && pullRequestsSurfaceAvailable && visiblePullRequestCount > 1
11228-
? addPullRequestsSurface
11229-
: undefined
11230-
}
11231-
/>
11200+
<Suspense fallback={<PullRequestDetailGhost />}>
11201+
<PullRequestDetailPanel
11202+
getShortcutContext={getShortcutContext}
11203+
shortcutsEnabled={
11204+
rightPanelOpen && activeRightPanelSurface?.id === renderedRightPanelSurface.id
11205+
}
11206+
key={`${renderedRightPanelSurface.host ?? ""}:${renderedRightPanelSurface.repository}#${renderedRightPanelSurface.number}`}
11207+
environmentId={activeThread.environmentId}
11208+
onSelectPullRequest={(reference) => {
11209+
if (activeThreadRef)
11210+
useRightPanelStore.getState().openPullRequest(activeThreadRef, {
11211+
projectId: reference.projectId,
11212+
repository: reference.repository,
11213+
number: reference.number,
11214+
...(reference.host ? { host: reference.host } : {}),
11215+
});
11216+
}}
11217+
threadRef={activeThreadRef}
11218+
reference={{
11219+
projectId: renderedRightPanelSurface.projectId as ProjectId,
11220+
...(renderedRightPanelSurface.host ? { host: renderedRightPanelSurface.host } : {}),
11221+
repository: renderedRightPanelSurface.repository,
11222+
number: renderedRightPanelSurface.number,
11223+
}}
11224+
context={pullRequestPanelContext(
11225+
{
11226+
projectId: activeThread.projectId,
11227+
pullRequests: visiblePullRequests,
11228+
linkedPullRequest: linkedThreadPullRequest,
11229+
branchPullRequest:
11230+
activeThreadShell?.branchPullRequest ?? activeThread.branchPullRequest,
11231+
},
11232+
renderedRightPanelSurface,
11233+
)}
11234+
composerDraftTarget={composerDraftTarget}
11235+
onBack={
11236+
activeThreadRef !== null && pullRequestsSurfaceAvailable && visiblePullRequestCount > 1
11237+
? addPullRequestsSurface
11238+
: undefined
11239+
}
11240+
/>
11241+
</Suspense>
1123211242
) : renderedRightPanelSurface?.kind === "pull-requests" && activeThreadRef ? (
11233-
<ThreadPullRequestsPanel threadRef={activeThreadRef} />
11243+
<Suspense fallback={null}>
11244+
<ThreadPullRequestsPanel threadRef={activeThreadRef} />
11245+
</Suspense>
1123411246
) : renderedRightPanelSurface?.kind === "device" ? (
1123511247
<Suspense fallback={null}>
1123611248
<DevicePanel

0 commit comments

Comments
 (0)