Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 46 additions & 20 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type {
import React, {
Children,
Fragment,
Suspense,
type CSSProperties,
type ComponentPropsWithoutRef,
type MouseEvent as ReactMouseEvent,
createContext,
isValidElement,
lazy,
useCallback,
memo,
useContext,
Expand Down Expand Up @@ -56,10 +58,9 @@ import {
runFileAction,
useFileActionLaunchers,
} from "./fileActionsMenu";
import { editorLabel } from "./EditorOpenOptions";
import { editorLabel } from "../editorLabels";
import { useComputerLabel } from "./sidebar/linkedComputers";
import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
import { fnv1a32 } from "../lib/diffRendering";
import { fnv1a32, resolveDiffThemeName, type DiffThemeName } from "../lib/diffThemeName";
import {
highlightCode,
openStreamingHighlight,
Expand Down Expand Up @@ -107,7 +108,6 @@ import {
buildFileLinkLabel,
CHAT_MARKDOWN_REMARK_PLUGINS,
chatMarkdownUrlTransform,
GITHUB_HTML_REHYPE_PLUGINS,
indexWrittenFilePathsByBasename,
isFileNameMention,
normalizeMarkdownLinkHrefKey,
Expand Down Expand Up @@ -464,11 +464,15 @@ function ChatCodeBlock({ className, code, plain }: ChatCodeBlockProps) {
if (highlightedCodeCache.get(cacheKey) != null) return;

let cancelled = false;
void highlightCode(code, language, themeName).then((html) => {
if (cancelled || html === null) return;
highlightedCodeCache.set(cacheKey, html, estimateHighlightedSize(html, code));
setHighlighted({ cacheKey, html });
});
void highlightCode(code, language, themeName)
.then((html) => {
if (cancelled || html === null) return;
highlightedCodeCache.set(cacheKey, html, estimateHighlightedSize(html, code));
setHighlighted({ cacheKey, html });
})
.catch(() => {
// Keep plain code fallback if highlighting fails.
});

return () => {
cancelled = true;
Expand Down Expand Up @@ -1708,20 +1712,39 @@ function ChatMarkdownDocument({
],
);

const plainMarkdown = (
<ReactMarkdown
remarkPlugins={CHAT_MARKDOWN_REMARK_PLUGINS}
components={MARKDOWN_COMPONENTS}
urlTransform={markdownUrlTransform}
>
{text}
</ReactMarkdown>
);

// When a GitHub document contains raw HTML tags or comments, avoid flashing
// literal markup through plain ReactMarkdown while the sanitizer chunk loads.
const githubFallback = text.includes("<") ? null : plainMarkdown;

return (
<MarkdownDocumentContext value={documentContext}>
<ReactMarkdown
remarkPlugins={CHAT_MARKDOWN_REMARK_PLUGINS}
rehypePlugins={html === "github" ? GITHUB_HTML_REHYPE_PLUGINS : undefined}
components={MARKDOWN_COMPONENTS}
urlTransform={markdownUrlTransform}
>
{text}
</ReactMarkdown>
{html === "github" ? (
<Suspense fallback={githubFallback}>
<LazyGitHubHtmlMarkdown
text={text}
components={MARKDOWN_COMPONENTS}
urlTransform={markdownUrlTransform}
/>
</Suspense>
) : (
plainMarkdown
)}
</MarkdownDocumentContext>
);
}

const LazyGitHubHtmlMarkdown = lazy(() => import("./chat/GitHubHtmlMarkdown"));

const MemoChatMarkdownDocument = memo(ChatMarkdownDocument);

/**
Expand Down Expand Up @@ -1821,12 +1844,15 @@ function ChatMarkdown({
className,
}: ChatMarkdownProps) {
const { resolvedTheme } = useTheme();
// Boots the highlighting worker and its theme while the page is idle, so the
// first code block of a session is not also the one that loads Shiki.
// Boot the highlighting worker and its theme while idle only once a message
// actually has a fenced code block, so prose-only threads avoid fetching
// @pierre/diffs on startup.
const codeThemeName = useCodeThemeName();
const hasFencedCode = text.includes("```") || text.includes("~~~");
useEffect(() => {
if (!hasFencedCode) return;
warmCodeHighlighter(codeThemeName);
}, [codeThemeName]);
}, [codeThemeName, hasFencedCode]);
const canRenderVisualizations = environmentId !== undefined && threadId !== undefined;
const parsedSegments = useMemo(() => {
const rawSegments = canRenderVisualizations
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/ChatView.panels.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ describe("ChatView (full app): right panel and header actions", () => {
"Unable to find the sidebar's Source tab.",
);
expect(changesTab.getAttribute("data-active")).toBe("true");
expect(visibleSourceControlPanel()).not.toBeNull();
await vi.waitFor(
() => {
expect(visibleSourceControlPanel()).not.toBeNull();
},
{ timeout: 8_000, interval: 16 },
);
expect(document.querySelector("[data-agents-panel]")).toBeNull();

// The `+` menu adds the second tab and focuses it.
Expand Down
75 changes: 51 additions & 24 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import { Debouncer } from "@tanstack/react-pacer";
import { useQueryClient } from "@tanstack/react-query";
import * as Option from "effect/Option";
import {
Suspense,
lazy,
memo,
useCallback,
useEffect,
Expand Down Expand Up @@ -191,7 +193,7 @@ import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { isKeyboardOwnedByDialog } from "../commands/shortcutBlock";
import { useChatFindStore } from "../chatFindStore";
import { installFindRegionTracking, resolveFindShortcutOwner } from "../lib/findShortcutOwner";
import { selectedChatText } from "./chat/chatFind/ChatFind";
import { selectedChatText } from "./chat/chatFind/chatFindSelection";
import {
RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY,
draftRightPanelStateKey,
Expand Down Expand Up @@ -319,7 +321,6 @@ import { McpAppSidePanel } from "./chat/McpAppCard";
import { NO_COMPOSER_PULL_REQUESTS, type ComposerPullRequest } from "./chat/ComposerPullRequestRow";
import { type ComposerGoalSetInput, threadGoalControls } from "./chat/ComposerGoalBar";
import { getComposerProviderState } from "./chat/composerProviderState";
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
import { useProjectBriefSupport } from "../projectBrief";
import { linkedThreadRouteParams } from "../environments/links/linkedThreads";
import { changeProjectNote, useThreadNoteSuggestions } from "../projectContext";
Expand Down Expand Up @@ -359,7 +360,29 @@ import {
} from "./chat/threadActivity";
import { currentWorkLine } from "./chat/activitySteps";
import { closeExpandedImagePreview, openExpandedImagePreview } from "./chat/ExpandedImagePreview";
import { FilePreviewDialog, type FilePreviewRequest } from "./chat/FilePreviewDialog";
import type { FilePreviewRequest } from "./chat/FilePreviewDialog";
import { SuspenseEscapeTrap } from "./SuspenseEscapeTrap";

const LazyPullRequestThreadDialog = lazy(() =>
import("./PullRequestThreadDialog").then((module) => ({
default: module.PullRequestThreadDialog,
})),
);
const LazyFilePreviewDialog = lazy(() =>
import("./chat/FilePreviewDialog").then((module) => ({
default: module.FilePreviewDialog,
})),
);
const LazyBrowserPanel = lazy(() =>
import("./browser/BrowserPanel").then((module) => ({
default: module.BrowserPanel,
})),
);
const LazyBrowserSplitHandle = lazy(() =>
import("./browser/BrowserSplitHandle").then((module) => ({
default: module.BrowserSplitHandle,
})),
);
import { NoActiveThreadState } from "./NoActiveThreadState";
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
import {
Expand Down Expand Up @@ -456,8 +479,6 @@ import {
} from "./ChatView.logic";
import { useLocalStorage } from "~/hooks/useLocalStorage";
import { selectThreadBrowserState, useBrowserPanelStore } from "../browserPanelStore";
import { BrowserPanel } from "./browser/BrowserPanel";
import { BrowserSplitHandle } from "./browser/BrowserSplitHandle";
import { useComposerHandleContext } from "../composerHandleContext";
import {
useServerAvailableEditors,
Expand Down Expand Up @@ -9364,33 +9385,35 @@ export default function ChatView(props: ChatViewProps) {
) : null}

{pullRequestDialogState ? (
<PullRequestThreadDialog
key={pullRequestDialogState.key}
open
environmentId={activeThread.environmentId}
threadId={pullRequestDialogState.threadId}
cwd={activeProject?.cwd ?? null}
initialReference={pullRequestDialogState.initialReference}
onOpenChange={(open) => {
if (!open) {
closePullRequestDialog();
}
}}
onPrepared={handlePreparedPullRequestThread}
/>
<Suspense fallback={<SuspenseEscapeTrap onClose={closePullRequestDialog} />}>
<LazyPullRequestThreadDialog
key={pullRequestDialogState.key}
open
environmentId={activeThread.environmentId}
threadId={pullRequestDialogState.threadId}
cwd={activeProject?.cwd ?? null}
initialReference={pullRequestDialogState.initialReference}
onOpenChange={(open) => {
if (!open) {
closePullRequestDialog();
}
}}
onPrepared={handlePreparedPullRequestThread}
/>
</Suspense>
) : null}
</div>
</SurfaceShownContext>
{/* end chat column */}
{browserOpen && routeThreadRef !== null ? (
<>
<Suspense fallback={null}>
{browserExpanded ? null : (
<BrowserSplitHandle
<LazyBrowserSplitHandle
chatFraction={splitChatFraction}
onChange={setSplitChatFraction}
/>
)}
<BrowserPanel
<LazyBrowserPanel
threadRef={routeThreadRef}
projectId={activeThread?.projectId ?? null}
flexGrow={browserExpanded ? 1 : 1 - splitChatFraction}
Expand All @@ -9402,7 +9425,7 @@ export default function ChatView(props: ChatViewProps) {
pendingReveal={pendingElementReveal}
onRevealHandled={() => setPendingElementReveal(null)}
/>
</>
</Suspense>
) : null}
</div>
{/* end horizontal flex container */}
Expand Down Expand Up @@ -9436,7 +9459,11 @@ export default function ChatView(props: ChatViewProps) {
setPendingTerminalAction(null);
}}
/>
{previewedFile && <FilePreviewDialog request={previewedFile} onClose={closePreviewedFile} />}
{previewedFile ? (
<Suspense fallback={<SuspenseEscapeTrap onClose={closePreviewedFile} />}>
<LazyFilePreviewDialog request={previewedFile} onClose={closePreviewedFile} />
</Suspense>
) : null}
</div>
);
}
12 changes: 6 additions & 6 deletions apps/web/src/components/ComposerPromptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ import {
type TerminalContextDraft,
} from "~/lib/terminalContext";
import { cn } from "~/lib/utils";
import { basenameOfPath, getVscodeIconUrlForEntry, inferEntryKindFromPath } from "~/vscode-icons";
import { basenameOfPath, inferEntryKindFromPath } from "~/lib/vscodeIconPath";
import { VscodeEntryIcon } from "./chat/VscodeEntryIcon";
import {
COMPOSER_INLINE_CHIP_CLASS_NAME,
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
Expand Down Expand Up @@ -170,12 +171,11 @@ function ComposerMentionDecorator(props: { path: string }) {
spellCheck={false}
data-composer-mention-chip="true"
>
<img
alt=""
aria-hidden="true"
<VscodeEntryIcon
pathValue={props.path}
kind={inferEntryKindFromPath(props.path)}
theme={theme}
className={COMPOSER_INLINE_CHIP_ICON_CLASS_NAME}
loading="lazy"
src={getVscodeIconUrlForEntry(props.path, inferEntryKindFromPath(props.path), theme)}
/>
<span className={COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME}>{basenameOfPath(props.path)}</span>
</span>
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch"
import { useComposerDraftStore } from "../composerDraftStore";
import { useTheme } from "../hooks/useTheme";
import { buildFileDiffRenderKey, getRenderablePatch } from "../lib/diffRendering";
import "../theme/attachPierreCodeThemes";
import { useCodeThemeName } from "../theme/codeTheme";
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
import { useStore } from "../store";
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/DiffWorkerPoolProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react";
import DiffsWorker from "../lib/diffsWorker.ts?worker";
import { useEffect, useMemo, type ReactNode } from "react";
import type { DiffThemeName } from "../lib/diffRendering";
import "../theme/attachPierreCodeThemes";
import { useCodeThemeName } from "../theme/codeTheme";

function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
Expand Down
31 changes: 2 additions & 29 deletions apps/web/src/components/EditorOpenOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import type { EditorId } from "@threadlines/contracts";
import { FolderClosedIcon } from "lucide-react";
import { useMemo } from "react";

import { isMacPlatform, isWindowsPlatform } from "~/lib/utils";
import { readPrimaryEnvironmentDescriptor } from "~/environments/primary/context";
import { editorLabel, hostFileManagerLabel } from "../editorLabels";
import { AntigravityIcon, CursorIcon, Icon, KiroIcon, TraeIcon, Zed } from "./Icons";
import { VisualStudioCode, VisualStudioCodeInsiders, VSCodium } from "./ToolIcons";
import {
Expand Down Expand Up @@ -60,33 +59,7 @@ const EDITOR_OPTIONS: ReadonlyArray<EditorOpenOption> = [
{ label: "WebStorm", Icon: WebStormIcon, value: "webstorm" },
];

function fileManagerLabel(platform: string): string {
return isMacPlatform(platform) ? "Finder" : isWindowsPlatform(platform) ? "Explorer" : "Files";
}

/**
* The file manager's name on the computer that opens it: the primary
* server's, which is not this device's when a browser on a Mac is paired with
* a Windows PC. This device's platform stands in until the server says.
*/
function hostFileManagerLabel(): string {
switch (readPrimaryEnvironmentDescriptor()?.platform.os) {
case "darwin":
return "Finder";
case "windows":
return "Explorer";
case "linux":
return "Files";
default:
return fileManagerLabel(navigator.platform);
}
}

/** The name an editor goes by in menus ("Cursor", "Finder"). */
export function editorLabel(editor: EditorId): string {
if (editor === "file-manager") return hostFileManagerLabel();
return EDITOR_OPTIONS.find((option) => option.value === editor)?.label ?? editor;
}
export { editorLabel };

/**
* Action label for an option: the file manager reveals a target rather than
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ProjectScriptsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
keybindingValueForCommand,
decodeProjectScriptKeybindingRule,
} from "~/lib/projectScriptKeybindings";
import { keybindingFromKeyboardEvent } from "~/components/settings/KeybindingsSettings.logic";
import { keybindingFromKeyboardEvent } from "~/components/settings/keybindingCapture";
import {
commandForProjectScript,
nextProjectScriptId,
Expand Down
Loading
Loading