The best way to control Claude Code, Codex and more from any computer or phone
perf(web): chat markdown compiles with the React Compiler (#20715)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:34 UTC
fcda161afb902f73dc39a7512c461bb519872bfe
1 file changed
+440
-533
apps/web/src/components/ChatMarkdown.tsx
+440
-533
@@ -87,10 +87,9 @@ import React, {
87
type MouseEvent as ReactMouseEvent,
88
isValidElement,
89
use,
90
- useCallback,
90
memo,
91
useEffect,
93
- useMemo,
92
+ useLayoutEffect,
93
useRef,
94
useState,
95
type ReactNode,
@@ -109,7 +108,6 @@ import { parseComposerContextHref } from "@t3tools/shared/composerContextReferen
108
import { parseThreadLinkHref } from "@t3tools/shared/threadLinks";
109
import { AssistantCitationChip } from "./chat/AssistantCitationChip";
110
import { MarkdownThreadLink } from "./chat/MarkdownThreadLink";
112
-import { isWindowsAbsolutePath } from "@t3tools/shared/path";
111
import {
112
artifactTemplateFromHastProperties,
113
renderCodexInlineDirectivesAsMarkdown,
@@ -479,16 +477,6 @@ function isClosedCodeFence(node: ReactMarkdownExtraProps["node"], text: string):
477
);
478
}
479
482
-type MarkdownAstNode = {
483
- type?: string;
484
- meta?: unknown;
485
- url?: string;
486
- data?: {
487
- hProperties?: Record<string, unknown>;
488
- };
489
- children?: MarkdownAstNode[];
490
-};
491
-
480
function nodeToPlainText(node: ReactNode): string {
481
if (typeof node === "string" || typeof node === "number") {
482
return String(node);
@@ -575,7 +563,7 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
563
setExpanded((value) => !value);
564
}
565
578
- const handleCopy = useCallback((format: "markdown" | "csv") => {
566
+ const handleCopy = (format: "markdown" | "csv") => {
567
const table = containerRef.current?.querySelector("table");
568
if (!table || typeof navigator === "undefined" || navigator.clipboard == null) {
569
return;
@@ -599,7 +587,7 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
587
.catch((cause) => {
588
reportMarkdownActionFailure({ operation: "copy-table", format }, cause);
589
});
602
- }, []);
590
+ };
591
592
useEffect(
593
() => () => {
@@ -677,7 +665,7 @@ function MarkdownDetails({
665
const [isOpen, setIsOpen] = useState(open);
666
const searching = use(MarkdownFindContext);
667
const expanded = isOpen;
680
- const revealForFind = useCallback(() => setIsOpen(true), []);
668
+ const revealForFind = () => setIsOpen(true);
669
// Base UI only listens for `beforematch` on a panel mounted at its first
670
// render; a closed panel mounts later, when find starts, so listen here.
671
const findRevealRef = useFindRevealRef(revealForFind);
@@ -853,7 +841,7 @@ function MarkdownCodeBlock({
841
// make the rendered command differ from what the terminal would receive.
842
!/[\p{Cc}\p{Cf}]/u.test(code.slice(0, -1));
843
856
- const handleCopy = useCallback(() => {
844
+ const handleCopy = () => {
845
if (typeof navigator === "undefined" || navigator.clipboard == null) {
846
return;
847
}
@@ -879,7 +867,7 @@ function MarkdownCodeBlock({
867
cause,
868
);
869
});
882
- }, [code, fenceTitle, language]);
870
+ };
871
872
useEffect(
873
() => () => {
@@ -995,7 +983,7 @@ function MarkdownMermaidCodeBlock({
983
}) {
984
const [showCode, setShowCode] = useState(false);
985
const searching = use(MarkdownFindContext);
998
- const revealSource = useCallback(() => setShowCode(true), []);
986
+ const revealSource = () => setShowCode(true);
987
const sourceRevealRef = useFindRevealRef(revealSource);
988
const showDiagram = !showCode && !isStreaming && code.trim().length > 0;
989
const toggleLabel = showCode ? "Show diagram" : "Show code";
@@ -1114,12 +1102,10 @@ function UncachedShikiCodeBlock({
1102
preserveLines,
1103
}: UncachedShikiCodeBlockProps) {
1104
const highlighter = use(getSyntaxHighlighterPromise(language));
1117
- const incrementalHighlight = useMemo(
1118
- () =>
1119
- preserveLines ? createIncrementalHighlightedDocument(highlighter, language, themeName) : null,
1120
- [highlighter, preserveLines, language, themeName],
1121
- );
1122
- const highlighted = useMemo(() => {
1105
+ const incrementalHighlight = preserveLines
1106
+ ? createIncrementalHighlightedDocument(highlighter, language, themeName)
1107
+ : null;
1108
+ const highlighted = (() => {
1109
try {
1110
if (incrementalHighlight) return incrementalHighlight(code);
1111
return preserveLines
@@ -1134,7 +1120,7 @@ function UncachedShikiCodeBlock({
1120
? highlighter.codeToHast(code, { lang: "text", theme: themeName })
1121
: highlighter.codeToHtml(code, { lang: "text", theme: themeName });
1122
}
1137
- }, [code, highlighter, incrementalHighlight, language, preserveLines, themeName]);
1123
+ })();
1124
1125
useEffect(() => {
1126
if (!isStreaming) {
@@ -1191,23 +1177,22 @@ const MARKDOWN_LINK_FAVICON_CLASS_NAME = "block size-full shrink-0 select-none";
1177
1178
const failedFaviconHosts = new Set<string>();
1179
1194
-function brandLinkIcon(host: string): typeof GitHubIcon | null {
1180
+function isGitHubHost(host: string): boolean {
1181
const hostname = host.toLowerCase();
1196
- if (hostname === "github.com" || hostname.endsWith(".github.com")) return GitHubIcon;
1197
- return null;
1182
+ return hostname === "github.com" || hostname.endsWith(".github.com");
1183
}
1184
1185
const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host: string }) {
1186
const [failedHost, setFailedHost] = useState<string | null>(null);
1202
- const BrandIcon = brandLinkIcon(host);
1203
- const faviconUrl = BrandIcon ? null : faviconUrlForOrigin(`https://${host}`);
1187
+ const brandIcon = isGitHubHost(host);
1188
+ const faviconUrl = brandIcon ? null : faviconUrlForOrigin(`https://${host}`);
1189
return (
1190
<span
1191
className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
1192
aria-hidden
1193
>
1209
- {BrandIcon ? (
1210
- <BrandIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
1194
+ {brandIcon ? (
1195
+ <GitHubIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
1196
) : faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (
1197
<GlobeIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
1198
) : (
@@ -1375,19 +1360,16 @@ function ChatMarkdownImage(props: {
1360
const failed = props.sourceFailed === true || (src !== null && failedSrc === src);
1361
const settled = src !== null && !failed && (!props.standalone || loadedSrc !== null);
1362
// Cached images are complete before `onLoad` can fire.
1378
- const markLoadedIfComplete = useCallback(
1379
- (image: HTMLImageElement | null) => {
1380
- if (!image) return;
1381
- if (image.complete && image.naturalWidth > 0) setLoadedSrc(image.currentSrc || image.src);
1382
- markdownImageItems.set(image, {
1383
- src,
1384
- name: props.alt.trim() || "image",
1385
- actionsSource: props.actionsSource,
1386
- ...(props.originalUrl ? { originalUrl: props.originalUrl } : {}),
1387
- });
1388
- },
1389
- [props.actionsSource, props.alt, props.originalUrl, src],
1390
- );
1363
+ const markLoadedIfComplete = (image: HTMLImageElement | null) => {
1364
+ if (!image) return;
1365
+ if (image.complete && image.naturalWidth > 0) setLoadedSrc(image.currentSrc || image.src);
1366
+ markdownImageItems.set(image, {
1367
+ src,
1368
+ name: props.alt.trim() || "image",
1369
+ actionsSource: props.actionsSource,
1370
+ ...(props.originalUrl ? { originalUrl: props.originalUrl } : {}),
1371
+ });
1372
+ };
1373
const imageEvents = (loadingSrc: string) => ({
1374
onLoad: () => {
1375
setLoadedSrc(loadingSrc);
@@ -1881,7 +1863,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1863
onReveal,
1864
revealLabel,
1865
}: MarkdownFileLinkProps) {
1884
- const handleOpenInEditor = useCallback(() => {
1866
+ const handleOpenInEditor = () => {
1867
if (!onOpen) {
1868
return;
1869
}
@@ -1917,9 +1899,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1899
);
1900
}
1901
})();
1920
- }, [onOpen, targetPath]);
1902
+ };
1903
1922
- const handleOpenInFilePreview = useCallback(() => {
1904
+ const handleOpenInFilePreview = () => {
1905
if (threadRef && panelPath) {
1906
onOpenInPanel(panelPath, line);
1907
return;
@@ -1929,9 +1911,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1911
return;
1912
}
1913
handleOpenInEditor();
1932
- }, [handleOpenInEditor, line, onOpenInPanel, onOpenMedia, panelPath, threadRef]);
1914
+ };
1915
1934
- const handleOpenInBrowser = useCallback(() => {
1916
+ const handleOpenInBrowser = () => {
1917
if (!onOpenInBrowser) {
1918
return;
1919
}
@@ -1967,9 +1949,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1949
);
1950
}
1951
})();
1970
- }, [onOpenInBrowser, targetPath]);
1952
+ };
1953
1972
- const handleRevealInFileManager = useCallback(() => {
1954
+ const handleRevealInFileManager = () => {
1955
if (!onReveal) {
1956
return;
1957
}
@@ -2005,128 +1987,106 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1987
);
1988
}
1989
})();
2008
- }, [onReveal, targetPath]);
1990
+ };
1991
2010
- const handleCopy = useCallback(
2011
- (value: string, title: string) => {
2012
- if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
1992
+ const handleCopy = (value: string, title: string) => {
1993
+ if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
1994
+ toastManager.add(
1995
+ stackedThreadToast({
1996
+ type: "error",
1997
+ title: `Failed to copy ${title.toLowerCase()}`,
1998
+ description: "Clipboard API unavailable.",
1999
+ }),
2000
+ );
2001
+ return;
2002
+ }
2003
+
2004
+ void navigator.clipboard.writeText(value).then(
2005
+ () => {
2006
+ toastManager.add({
2007
+ type: "success",
2008
+ title: `${title} copied`,
2009
+ description: value,
2010
+ });
2011
+ },
2012
+ (error) => {
2013
+ reportMarkdownActionFailure(
2014
+ { operation: "copy-file-path", target: targetPath, copyTarget: title },
2015
+ error,
2016
+ );
2017
toastManager.add(
2018
stackedThreadToast({
2019
type: "error",
2020
title: `Failed to copy ${title.toLowerCase()}`,
2017
- description: "Clipboard API unavailable.",
2021
+ description: error instanceof Error ? error.message : "An error occurred.",
2022
}),
2023
);
2020
- return;
2021
- }
2022
-
2023
- void navigator.clipboard.writeText(value).then(
2024
- () => {
2025
- toastManager.add({
2026
- type: "success",
2027
- title: `${title} copied`,
2028
- description: value,
2029
- });
2030
- },
2031
- (error) => {
2032
- reportMarkdownActionFailure(
2033
- { operation: "copy-file-path", target: targetPath, copyTarget: title },
2034
- error,
2035
- );
2036
- toastManager.add(
2037
- stackedThreadToast({
2038
- type: "error",
2039
- title: `Failed to copy ${title.toLowerCase()}`,
2040
- description: error instanceof Error ? error.message : "An error occurred.",
2041
- }),
2042
- );
2043
- },
2044
- );
2045
- },
2046
- [targetPath],
2047
- );
2024
+ },
2025
+ );
2026
+ };
2027
2049
- const showFileContextMenu = useCallback(
2050
- async (position: { x: number; y: number }) => {
2051
- const api = readLocalApi();
2052
- if (!api) return;
2028
+ const showFileContextMenu = async (position: { x: number; y: number }) => {
2029
+ const api = readLocalApi();
2030
+ if (!api) return;
2031
2054
- try {
2055
- const clicked = await api.contextMenu.show(
2056
- [
2057
- ...(onOpenMedia ? ([{ id: "preview-media", label: "Preview media" }] as const) : []),
2058
- ...(onOpen ? ([{ id: "open", label: openInEditorMenuLabel }] as const) : []),
2059
- ...(onOpenInBrowser
2060
- ? ([{ id: "open-in-browser", label: "Open in integrated browser" }] as const)
2061
- : []),
2062
- ...(onReveal && revealLabel ? ([{ id: "reveal", label: revealLabel }] as const) : []),
2063
- { id: "copy-relative", label: "Copy relative path" },
2064
- { id: "copy-full", label: "Copy full path" },
2065
- ] as const,
2066
- position,
2067
- );
2032
+ try {
2033
+ const clicked = await api.contextMenu.show(
2034
+ [
2035
+ ...(onOpenMedia ? ([{ id: "preview-media", label: "Preview media" }] as const) : []),
2036
+ ...(onOpen ? ([{ id: "open", label: openInEditorMenuLabel }] as const) : []),
2037
+ ...(onOpenInBrowser
2038
+ ? ([{ id: "open-in-browser", label: "Open in integrated browser" }] as const)
2039
+ : []),
2040
+ ...(onReveal && revealLabel ? ([{ id: "reveal", label: revealLabel }] as const) : []),
2041
+ { id: "copy-relative", label: "Copy relative path" },
2042
+ { id: "copy-full", label: "Copy full path" },
2043
+ ] as const,
2044
+ position,
2045
+ );
2046
2069
- if (clicked === "preview-media") {
2070
- onOpenMedia?.();
2071
- return;
2072
- }
2073
- if (clicked === "open") {
2074
- handleOpenInEditor();
2075
- return;
2076
- }
2077
- if (clicked === "open-in-browser") {
2078
- handleOpenInBrowser();
2079
- return;
2080
- }
2081
- if (clicked === "reveal") {
2082
- handleRevealInFileManager();
2083
- return;
2084
- }
2085
- if (clicked === "copy-relative") {
2086
- handleCopy(displayPath, "Relative path");
2087
- return;
2088
- }
2089
- if (clicked === "copy-full") {
2090
- handleCopy(targetPath, "Full path");
2091
- }
2092
- } catch (cause) {
2093
- reportMarkdownActionFailure(
2094
- { operation: "show-file-context-menu", target: targetPath },
2095
- cause,
2096
- );
2047
+ if (clicked === "preview-media") {
2048
+ onOpenMedia?.();
2049
+ return;
2050
}
2098
- },
2099
- [
2100
- displayPath,
2101
- handleCopy,
2102
- handleOpenInBrowser,
2103
- handleOpenInEditor,
2104
- handleRevealInFileManager,
2105
- onOpenInBrowser,
2106
- onOpenMedia,
2107
- onOpen,
2108
- onReveal,
2109
- openInEditorMenuLabel,
2110
- revealLabel,
2111
- targetPath,
2112
- ],
2113
- );
2051
+ if (clicked === "open") {
2052
+ handleOpenInEditor();
2053
+ return;
2054
+ }
2055
+ if (clicked === "open-in-browser") {
2056
+ handleOpenInBrowser();
2057
+ return;
2058
+ }
2059
+ if (clicked === "reveal") {
2060
+ handleRevealInFileManager();
2061
+ return;
2062
+ }
2063
+ if (clicked === "copy-relative") {
2064
+ handleCopy(displayPath, "Relative path");
2065
+ return;
2066
+ }
2067
+ if (clicked === "copy-full") {
2068
+ handleCopy(targetPath, "Full path");
2069
+ }
2070
+ } catch (cause) {
2071
+ reportMarkdownActionFailure(
2072
+ { operation: "show-file-context-menu", target: targetPath },
2073
+ cause,
2074
+ );
2075
+ }
2076
+ };
2077
2115
- const handleContextMenu = useCallback(
2116
- (event: ReactMouseEvent<HTMLElement>) => {
2117
- event.preventDefault();
2118
- event.stopPropagation();
2119
- const position =
2120
- event.clientX === 0 && event.clientY === 0
2121
- ? (() => {
2122
- const bounds = event.currentTarget.getBoundingClientRect();
2123
- return { x: bounds.left, y: bounds.bottom };
2124
- })()
2125
- : { x: event.clientX, y: event.clientY };
2126
- void showFileContextMenu(position);
2127
- },
2128
- [showFileContextMenu],
2129
- );
2078
+ const handleContextMenu = (event: ReactMouseEvent<HTMLElement>) => {
2079
+ event.preventDefault();
2080
+ event.stopPropagation();
2081
+ const position =
2082
+ event.clientX === 0 && event.clientY === 0
2083
+ ? (() => {
2084
+ const bounds = event.currentTarget.getBoundingClientRect();
2085
+ return { x: bounds.left, y: bounds.bottom };
2086
+ })()
2087
+ : { x: event.clientX, y: event.clientY };
2088
+ void showFileContextMenu(position);
2089
+ };
2090
2091
const canOpenInEditor = onOpen !== undefined;
2092
const canOpenInBrowser = onOpenInBrowser !== undefined;
@@ -2266,16 +2226,41 @@ function useChatMarkdownState({
2226
githubMedia = false,
2227
}: ChatMarkdownProps) {
2228
const { resolvedTheme } = useTheme();
2269
- const [localMediaPreview, setLocalMediaPreview] = useState<ExpandedImagePreview | null>(null);
2229
const markdownRef = useRef<HTMLDivElement>(null);
2271
- const expandMedia = onImageExpand ?? setLocalMediaPreview;
2230
const mediaRequestId = useRef(0);
2273
- useEffect(() => {
2274
- setLocalMediaPreview(null);
2275
- return () => {
2231
+ // A preview opened from another thread or workspace never carries over.
2232
+ const mediaScopeKey = [
2233
+ threadRef?.environmentId,
2234
+ threadRef?.threadId,
2235
+ explicitEnvironmentId,
2236
+ cwd,
2237
+ imageBaseDir,
2238
+ ].join("\u0000");
2239
+ // Tagged with the scope it was opened in: a request from the previous scope can
2240
+ // resolve before the effect cleanup below invalidates it, and must stay hidden.
2241
+ const [localMedia, setLocalMedia] = useState<{
2242
+ scope: string;
2243
+ preview: ExpandedImagePreview;
2244
+ } | null>(null);
2245
+ const localMediaPreview = localMedia?.scope === mediaScopeKey ? localMedia.preview : null;
2246
+ const closeLocalMediaPreview = () => setLocalMedia(null);
2247
+ const expandMedia =
2248
+ onImageExpand ??
2249
+ ((preview: ExpandedImagePreview) => setLocalMedia({ scope: mediaScopeKey, preview }));
2250
+ const [mediaScope, setMediaScope] = useState(mediaScopeKey);
2251
+ if (mediaScope !== mediaScopeKey) {
2252
+ setMediaScope(mediaScopeKey);
2253
+ setLocalMedia(null);
2254
+ }
2255
+ // A layout cleanup runs in the commit that changes scope, so a request resolving
2256
+ // before paint cannot reach a parent onImageExpand either.
2257
+ useLayoutEffect(
2258
+ () => () => {
2259
mediaRequestId.current += 1;
2277
- };
2278
- }, [threadRef?.environmentId, threadRef?.threadId, explicitEnvironmentId, cwd, imageBaseDir]);
2260
+ },
2261
+ // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Leaving the scope invalidates media requests still loading for it.
2262
+ [mediaScopeKey],
2263
+ );
2264
const createAssetUrl = useAtomQueryRunner(assetEnvironment.createUrl, {
2265
reportFailure: false,
2266
refresh: true,
@@ -2295,48 +2280,49 @@ function useChatMarkdownState({
2280
canOperateHost &&
2281
canUseMarkdownFileShellActions(environmentId, remoteOpen.state.mode, remoteOpen.isResolved);
2282
const preparedConnection = usePreparedConnection(environmentId);
2298
- const openMarkdownMedia = useCallback(
2299
- (source: string, resolvedFilePath?: string, clickedImage?: HTMLImageElement | null) => {
2300
- const requestId = ++mediaRequestId.current;
2301
- void resolveMarkdownMediaPreview({
2302
- source,
2303
- resolvedFilePath,
2304
- cwd,
2305
- threadRef,
2306
- httpBaseUrl:
2307
- preparedConnection._tag === "Some" ? preparedConnection.value.httpBaseUrl : undefined,
2308
- createAssetUrl,
2309
- onOpenFile: threadRef
2310
- ? (path) => useRightPanelStore.getState().openFile(threadRef, path)
2311
- : undefined,
2312
- }).then(
2313
- (preview) => {
2314
- if (preview && mediaRequestId.current === requestId) {
2315
- const selected = preview.images[preview.index];
2316
- expandMedia(
2317
- selected && selected.type !== "video" && markdownRef.current
2318
- ? markdownImageGallery(clickedImage ?? markdownRef.current, selected)
2319
- : preview,
2320
- );
2321
- }
2322
- },
2323
- (error: unknown) => {
2324
- if (mediaRequestId.current !== requestId) return;
2325
- toastManager.add(
2326
- stackedThreadToast({
2327
- type: "error",
2328
- title: "Media unavailable",
2329
- description:
2330
- error instanceof Error
2331
- ? error.message
2332
- : "The file could not be loaded. It may have been moved or deleted.",
2333
- }),
2283
+ const openMarkdownMedia = (
2284
+ source: string,
2285
+ resolvedFilePath?: string,
2286
+ clickedImage?: HTMLImageElement | null,
2287
+ ) => {
2288
+ const requestId = ++mediaRequestId.current;
2289
+ void resolveMarkdownMediaPreview({
2290
+ source,
2291
+ resolvedFilePath,
2292
+ cwd,
2293
+ threadRef,
2294
+ httpBaseUrl:
2295
+ preparedConnection._tag === "Some" ? preparedConnection.value.httpBaseUrl : undefined,
2296
+ createAssetUrl,
2297
+ onOpenFile: threadRef
2298
+ ? (path) => useRightPanelStore.getState().openFile(threadRef, path)
2299
+ : undefined,
2300
+ }).then(
2301
+ (preview) => {
2302
+ if (preview && mediaRequestId.current === requestId) {
2303
+ const selected = preview.images[preview.index];
2304
+ expandMedia(
2305
+ selected && selected.type !== "video" && markdownRef.current
2306
+ ? markdownImageGallery(clickedImage ?? markdownRef.current, selected)
2307
+ : preview,
2308
);
2335
- },
2336
- );
2337
- },
2338
- [createAssetUrl, cwd, expandMedia, preparedConnection, threadRef],
2339
- );
2309
+ }
2310
+ },
2311
+ (error: unknown) => {
2312
+ if (mediaRequestId.current !== requestId) return;
2313
+ toastManager.add(
2314
+ stackedThreadToast({
2315
+ type: "error",
2316
+ title: "Media unavailable",
2317
+ description:
2318
+ error instanceof Error
2319
+ ? error.message
2320
+ : "The file could not be loaded. It may have been moved or deleted.",
2321
+ }),
2322
+ );
2323
+ },
2324
+ );
2325
+ };
2326
// Only the parts of the server config markdown reads. The config object itself
2327
// changes with every provider status push, which would re-render every
2328
// visible reply.
@@ -2358,31 +2344,28 @@ function useChatMarkdownState({
2344
const openInEditor = useAtomCommand(shellEnvironment.openInEditor, {
2345
reportFailure: false,
2346
});
2361
- const revealFileInFileManager = useCallback(
2362
- (filePath: string) => {
2363
- if (environmentId === null) {
2364
- return Promise.resolve(
2365
- AsyncResult.failure<void, PreferredEditorEnvironmentRequiredError>(
2366
- Cause.fail(new PreferredEditorEnvironmentRequiredError({ targetPath: filePath })),
2367
- ),
2368
- );
2369
- }
2370
- if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) {
2371
- return Promise.resolve(
2372
- AsyncResult.failure<void, Error>(
2373
- Cause.fail(new Error("This connection cannot reveal files on this environment.")),
2374
- ),
2375
- );
2376
- }
2377
- return openInEditor({
2378
- environmentId,
2379
- input: { cwd: filePath, editor: "file-manager", reveal: true },
2380
- });
2381
- },
2382
- [environmentId, openInEditor],
2383
- );
2347
+ const revealFileInFileManager = (filePath: string) => {
2348
+ if (environmentId === null) {
2349
+ return Promise.resolve(
2350
+ AsyncResult.failure<void, PreferredEditorEnvironmentRequiredError>(
2351
+ Cause.fail(new PreferredEditorEnvironmentRequiredError({ targetPath: filePath })),
2352
+ ),
2353
+ );
2354
+ }
2355
+ if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) {
2356
+ return Promise.resolve(
2357
+ AsyncResult.failure<void, Error>(
2358
+ Cause.fail(new Error("This connection cannot reveal files on this environment.")),
2359
+ ),
2360
+ );
2361
+ }
2362
+ return openInEditor({
2363
+ environmentId,
2364
+ input: { cwd: filePath, editor: "file-manager", reveal: true },
2365
+ });
2366
+ };
2367
const diffThemeName = resolveDiffThemeName(resolvedTheme);
2385
- const markdownFileLinkMetaByHref = useMemo(() => {
2368
+ const markdownFileLinkMetaByHref = (() => {
2369
const metaByHref = new Map<
2370
string,
2371
NonNullable<ReturnType<typeof resolveMarkdownFileLinkMeta>>
@@ -2397,8 +2380,8 @@ function useChatMarkdownState({
2380
}
2381
}
2382
return metaByHref;
2400
- }, [cwd, imageBaseDir, text]);
2401
- const inlineCodeFileLinkMetaByText = useMemo(() => {
2383
+ })();
2384
+ const inlineCodeFileLinkMetaByText = (() => {
2385
const metaByText = new Map<string, MarkdownFileLinkMeta>();
2386
for (const span of extractInlineCodeSpans(text)) {
2387
if (metaByText.has(span)) continue;
@@ -2408,22 +2391,22 @@ function useChatMarkdownState({
2391
}
2392
}
2393
return metaByText;
2411
- }, [cwd, imageBaseDir, text]);
2412
- const fileLinkParentSuffixByPath = useMemo(() => {
2394
+ })();
2395
+ const fileLinkParentSuffixByPath = (() => {
2396
const filePaths = [
2397
...[...markdownFileLinkMetaByHref.values()].map((meta) => meta.filePath),
2398
...[...inlineCodeFileLinkMetaByText.values()].map((meta) => meta.filePath),
2399
];
2400
return buildFileLinkParentSuffixByPath(filePaths);
2418
- }, [inlineCodeFileLinkMetaByText, markdownFileLinkMetaByHref]);
2419
- const markdownUrlTransform = useCallback((href: string) => {
2401
+ })();
2402
+ const markdownUrlTransform = (href: string) => {
2403
if (parseAssistantCitationHref(href)) return href;
2404
if (parseComposerContextHref(href)) return href;
2405
if (parseThreadLinkHref(href)) return href;
2406
if (isWindowsDrivePathHref(href)) return href;
2407
return rewriteMarkdownFileUriHref(href) ?? defaultUrlTransform(href);
2425
- }, []);
2426
- const handleCopy = useCallback((event: ReactClipboardEvent<HTMLDivElement>) => {
2408
+ };
2409
+ const handleCopy = (event: ReactClipboardEvent<HTMLDivElement>) => {
2410
const selection = window.getSelection();
2411
if (!selection || selection.isCollapsed || !event.clipboardData) return;
2412
const payload = chatMarkdownClipboardPayload(selection);
@@ -2437,301 +2420,231 @@ function useChatMarkdownState({
2420
? encodeComposerContextClipboardHtml(payload.text, fragment, payload.html)
2421
: payload.html,
2422
);
2440
- }, []);
2423
+ };
2424
const openChangeRequestLink = useOpenChangeRequestLink(threadRef, pullRequestPanelRef);
2425
const openDeferredMarkdownLink = useOpenLink(threadRef);
2426
// Subscribed rather than read at click time: the anchor has to decide
2427
// synchronously whether to intercept its `_blank`, and a subscription is what
2428
// makes a persisted "app" apply once settings hydrate after launch.
2429
const linkTargetPreference = useClientSettings((settings) => settings.browserLinkTarget);
2447
- const resolveThreadPullRequest = useCallback(
2448
- (href: string): (ThreadPullRequestKey & { readonly url: string }) | null => {
2449
- if (
2450
- threadRef === undefined ||
2451
- readThreadShell(threadRef) === null ||
2452
- !pullRequestLinking.canLink(href)
2453
- )
2454
- return null;
2455
- const parsed = parseChangeRequestUrl(href);
2456
- return parsed === null ? null : { ...parsed, url: href };
2457
- },
2458
- [pullRequestLinking, threadRef],
2459
- );
2460
- const linkedThreadPullRequestFor = useCallback(
2461
- (href: string) => {
2462
- if (threadRef === undefined || !pullRequestLinking.isLinked(readThreadShell(threadRef), href))
2463
- return null;
2464
- const parsed = parseChangeRequestUrl(href);
2465
- return parsed === null ? null : { ...parsed, url: href };
2466
- },
2467
- [pullRequestLinking, threadRef],
2468
- );
2469
- const updateThreadPullRequestLink = useCallback(
2470
- async (href: string, linked: boolean) => {
2471
- if (threadRef === undefined || (!linked && linkedThreadPullRequestFor(href) === null)) return;
2472
- if (!readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope)) return;
2473
- await pullRequestLinking.changeLink(threadRef, href, linked);
2474
- },
2475
- [linkedThreadPullRequestFor, pullRequestLinking, threadRef],
2476
- );
2477
- const openExternalLinkInPreview = useCallback(
2478
- (url: string) => {
2479
- if (!threadRef || !canOperatePreview) {
2480
- return Promise.resolve(
2481
- AsyncResult.failure<void, BrowserPreviewUnavailableError>(
2482
- Cause.fail(
2483
- new BrowserPreviewUnavailableError({
2484
- message: "Preview access is unavailable for this client.",
2485
- }),
2486
- ),
2430
+ const resolveThreadPullRequest = (
2431
+ href: string,
2432
+ ): (ThreadPullRequestKey & { readonly url: string }) | null => {
2433
+ if (
2434
+ threadRef === undefined ||
2435
+ readThreadShell(threadRef) === null ||
2436
+ !pullRequestLinking.canLink(href)
2437
+ )
2438
+ return null;
2439
+ const parsed = parseChangeRequestUrl(href);
2440
+ return parsed === null ? null : { ...parsed, url: href };
2441
+ };
2442
+ const linkedThreadPullRequestFor = (href: string) => {
2443
+ if (threadRef === undefined || !pullRequestLinking.isLinked(readThreadShell(threadRef), href))
2444
+ return null;
2445
+ const parsed = parseChangeRequestUrl(href);
2446
+ return parsed === null ? null : { ...parsed, url: href };
2447
+ };
2448
+ const updateThreadPullRequestLink = async (href: string, linked: boolean) => {
2449
+ if (threadRef === undefined || (!linked && linkedThreadPullRequestFor(href) === null)) return;
2450
+ if (!readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope)) return;
2451
+ await pullRequestLinking.changeLink(threadRef, href, linked);
2452
+ };
2453
+ const openExternalLinkInPreview = (url: string) => {
2454
+ if (!threadRef || !canOperatePreview) {
2455
+ return Promise.resolve(
2456
+ AsyncResult.failure<void, BrowserPreviewUnavailableError>(
2457
+ Cause.fail(
2458
+ new BrowserPreviewUnavailableError({
2459
+ message: "Preview access is unavailable for this client.",
2460
+ }),
2461
),
2488
- );
2489
- }
2490
- return openUrlInPreview({ threadRef, url, openPreview }).then((result) => {
2491
- if (result._tag === "Success") recordVisitForThread(threadRef, url);
2492
- else if (!isAtomCommandInterrupted(result)) {
2493
- const error = squashAtomCommandFailure(result);
2494
- if (error instanceof BrowserSettingsReadError) {
2495
- toastManager.add(
2496
- stackedThreadToast({
2497
- type: "error",
2498
- title: "Unable to open link in browser",
2499
- description: error.message,
2500
- }),
2501
- );
2502
- }
2462
+ ),
2463
+ );
2464
+ }
2465
+ return openUrlInPreview({ threadRef, url, openPreview }).then((result) => {
2466
+ if (result._tag === "Success") recordVisitForThread(threadRef, url);
2467
+ else if (!isAtomCommandInterrupted(result)) {
2468
+ const error = squashAtomCommandFailure(result);
2469
+ if (error instanceof BrowserSettingsReadError) {
2470
+ toastManager.add(
2471
+ stackedThreadToast({
2472
+ type: "error",
2473
+ title: "Unable to open link in browser",
2474
+ description: error.message,
2475
+ }),
2476
+ );
2477
}
2504
- return result;
2505
- });
2506
- },
2507
- [canOperatePreview, openPreview, threadRef],
2508
- );
2509
- const openMarkdownFileInPreview = useCallback(
2510
- (path: string) => {
2511
- if (!threadRef || !canOperatePreview || preparedConnection._tag === "None") {
2512
- return Promise.resolve(
2513
- AsyncResult.failure<void, BrowserPreviewUnavailableError>(
2514
- Cause.fail(
2515
- new BrowserPreviewUnavailableError({
2516
- message: "Environment is not connected.",
2517
- }),
2518
- ),
2519
- ),
2520
- );
2521
- }
2522
- return openFileInPreview({
2523
- threadRef,
2524
- filePath: path,
2525
- workspaceRoot: cwd,
2526
- httpBaseUrl: preparedConnection.value.httpBaseUrl,
2527
- createAssetUrl,
2528
- openPreview,
2529
- });
2530
- },
2531
- [canOperatePreview, createAssetUrl, cwd, openPreview, preparedConnection, threadRef],
2532
- );
2533
- const findWorkspaceBasenameMatch = useCallback(
2534
- async (workspaceRelativePath: string) => {
2535
- if (
2536
- !cwd ||
2537
- environmentId === null ||
2538
- !readEnvironmentScope(environmentId, AuthFilesystemReadScope) ||
2539
- !needsWorkspaceBasenameLookup(workspaceRelativePath)
2540
- ) {
2541
- return null;
2542
- }
2543
- const result = await searchProjectEntries({
2544
- environmentId,
2545
- input: {
2546
- cwd,
2547
- query: workspaceRelativePath,
2548
- limit: WORKSPACE_BASENAME_LOOKUP_LIMIT,
2549
- kind: "file",
2550
- },
2551
- });
2552
- return result._tag === "Success"
2553
- ? pickWorkspaceBasenameMatch(workspaceRelativePath, result.value.entries)
2554
- : null;
2555
- },
2556
- [cwd, environmentId, searchProjectEntries],
2557
- );
2558
- const openFileInPanel = useCallback(
2559
- (panelPath: string, line: number | undefined) => {
2560
- if (!threadRef) return;
2561
- // Claimed on every open so a synchronous one supersedes a lookup already
2562
- // in flight.
2563
- const isLatestLookup = claimWorkspaceBasenameLookup();
2564
- const openAt = (path: string) =>
2565
- useRightPanelStore.getState().openFile(threadRef, path, line);
2566
- if (!cwd || !needsWorkspaceBasenameLookup(panelPath)) {
2567
- openAt(panelPath);
2568
- return;
2478
}
2570
- void (async () => {
2571
- const match = await findWorkspaceBasenameMatch(panelPath);
2572
- if (!isLatestLookup()) return;
2573
- openAt(match ?? panelPath);
2574
- })();
2575
- },
2576
- [cwd, findWorkspaceBasenameMatch, threadRef],
2577
- );
2578
- const revealMarkdownFileInFileManager = useCallback(
2579
- async (fileLinkMeta: MarkdownFileLinkMeta) => {
2580
- const workspaceRelativePath = fileLinkMeta.workspaceRelativePath;
2581
- const match = workspaceRelativePath
2582
- ? await findWorkspaceBasenameMatch(workspaceRelativePath)
2583
- : null;
2584
- const filePath = match && cwd ? resolvePathLinkTarget(match, cwd) : fileLinkMeta.filePath;
2585
- return revealFileInFileManager(filePath);
2586
- },
2587
- [cwd, findWorkspaceBasenameMatch, revealFileInFileManager],
2588
- );
2589
- const fileLinkChip = useCallback(
2590
- (fileLinkMeta: MarkdownFileLinkMeta, copyMarkdown: string, mediaSource?: string) => {
2591
- const mediaPath = mediaSource ?? fileLinkMeta.filePath;
2592
- const canPreviewMedia =
2593
- mediaMimeTypeFromExtension(
2594
- fileLinkMeta.basename.slice(fileLinkMeta.basename.lastIndexOf(".")),
2595
- ) !== null;
2596
- const panelPath =
2597
- fileLinkMeta.workspaceRelativePath ??
2598
- (!canPreviewMedia && isAbsolutePath(fileLinkMeta.filePath) ? fileLinkMeta.filePath : null);
2599
-
2600
- return (
2601
- <MarkdownFileLink
2602
- environmentId={environmentId}
2603
- href={fileLinkMeta.targetPath}
2604
- targetPath={fileLinkMeta.targetPath}
2605
- iconPath={fileLinkMeta.filePath}
2606
- displayPath={fileLinkMeta.displayPath}
2607
- panelPath={panelPath}
2608
- line={fileLinkMeta.line}
2609
- label={fileLinkLabel(
2610
- {
2611
- path: fileLinkMeta.filePath,
2612
- ...(fileLinkMeta.line !== undefined ? { line: fileLinkMeta.line } : {}),
2613
- ...(fileLinkMeta.column !== undefined ? { column: fileLinkMeta.column } : {}),
2614
- },
2615
- fileLinkParentSuffixByPath,
2616
- )}
2617
- copyMarkdown={copyMarkdown}
2618
- theme={resolvedTheme}
2619
- threadRef={threadRef}
2620
- {...(canUseShellActions ? { onOpen: openInPreferredEditor } : {})}
2621
- onOpenInPanel={openFileInPanel}
2622
- onOpenMedia={
2623
- threadRef && canPreviewMedia
2624
- ? () => openMarkdownMedia(mediaPath, fileLinkMeta.filePath)
2625
- : undefined
2626
- }
2627
- openInEditorMenuLabel={preferredEditorMenuLabel}
2628
- onReveal={
2629
- canUseShellActions && revealInFileManagerLabel !== undefined
2630
- ? () => revealMarkdownFileInFileManager(fileLinkMeta)
2631
- : undefined
2632
- }
2633
- revealLabel={revealInFileManagerLabel}
2634
- onOpenInBrowser={
2635
- threadRef &&
2636
- canOperatePreview &&
2637
- isPreviewAvailableFor(threadRef.environmentId) &&
2638
- isBrowserPreviewFile(fileLinkMeta.filePath)
2639
- ? () => openMarkdownFileInPreview(fileLinkMeta.filePath)
2640
- : undefined
2641
- }
2642
- />
2479
+ return result;
2480
+ });
2481
+ };
2482
+ const openMarkdownFileInPreview = (path: string) => {
2483
+ if (!threadRef || !canOperatePreview || preparedConnection._tag === "None") {
2484
+ return Promise.resolve(
2485
+ AsyncResult.failure<void, BrowserPreviewUnavailableError>(
2486
+ Cause.fail(
2487
+ new BrowserPreviewUnavailableError({
2488
+ message: "Environment is not connected.",
2489
+ }),
2490
+ ),
2491
+ ),
2492
);
2644
- },
2645
- [
2646
- canUseShellActions,
2647
- canOperatePreview,
2648
- environmentId,
2649
- fileLinkParentSuffixByPath,
2650
- openFileInPanel,
2651
- openInPreferredEditor,
2652
- openMarkdownFileInPreview,
2653
- openMarkdownMedia,
2654
- preferredEditorMenuLabel,
2655
- resolvedTheme,
2656
- revealInFileManagerLabel,
2657
- revealMarkdownFileInFileManager,
2658
- threadRef,
2659
- ],
2660
- );
2661
-
2662
- const componentState = useMemo(
2663
- () => ({
2664
- canOperateHost,
2665
- canOperatePreview,
2666
- cwd,
2667
- diffThemeName,
2668
- environmentId,
2669
- expandMedia,
2670
- fileLinkChip,
2671
- githubMedia,
2672
- renderContextReference,
2673
- headingLevelOffset,
2674
- imageBaseDir,
2675
- inlineCodeFileLinkMetaByText,
2676
- isStreaming,
2677
- linkTargetPreference,
2678
- markdownFileLinkMetaByHref,
2679
- onTaskListChange,
2680
- onUseArtifactTemplate,
2681
- onRunShellCommand,
2682
- openChangeRequestLink,
2683
- openDeferredMarkdownLink,
2684
- openExternalLinkInPreview,
2685
- openMarkdownMedia,
2686
- projects,
2687
- linkedThreadPullRequestFor,
2688
- resolveThreadPullRequest,
2689
- resolvedTheme,
2690
- pullRequestsEnabled,
2691
- skills,
2493
+ }
2494
+ return openFileInPreview({
2495
threadRef,
2693
- updateThreadPullRequestLink,
2694
- }),
2695
- [
2696
- canOperateHost,
2697
- canOperatePreview,
2698
- cwd,
2699
- diffThemeName,
2496
+ filePath: path,
2497
+ workspaceRoot: cwd,
2498
+ httpBaseUrl: preparedConnection.value.httpBaseUrl,
2499
+ createAssetUrl,
2500
+ openPreview,
2501
+ });
2502
+ };
2503
+ const findWorkspaceBasenameMatch = async (workspaceRelativePath: string) => {
2504
+ if (
2505
+ !cwd ||
2506
+ environmentId === null ||
2507
+ !readEnvironmentScope(environmentId, AuthFilesystemReadScope) ||
2508
+ !needsWorkspaceBasenameLookup(workspaceRelativePath)
2509
+ ) {
2510
+ return null;
2511
+ }
2512
+ const result = await searchProjectEntries({
2513
environmentId,
2701
- expandMedia,
2702
- fileLinkChip,
2703
- githubMedia,
2704
- renderContextReference,
2705
- headingLevelOffset,
2706
- imageBaseDir,
2707
- inlineCodeFileLinkMetaByText,
2708
- isStreaming,
2709
- linkTargetPreference,
2710
- markdownFileLinkMetaByHref,
2711
- onTaskListChange,
2712
- onUseArtifactTemplate,
2713
- onRunShellCommand,
2714
- openChangeRequestLink,
2715
- openDeferredMarkdownLink,
2716
- openExternalLinkInPreview,
2717
- openMarkdownMedia,
2718
- projects,
2719
- linkedThreadPullRequestFor,
2720
- resolveThreadPullRequest,
2721
- resolvedTheme,
2722
- pullRequestsEnabled,
2723
- skills,
2724
- threadRef,
2725
- updateThreadPullRequestLink,
2726
- ],
2727
- );
2514
+ input: {
2515
+ cwd,
2516
+ query: workspaceRelativePath,
2517
+ limit: WORKSPACE_BASENAME_LOOKUP_LIMIT,
2518
+ kind: "file",
2519
+ },
2520
+ });
2521
+ return result._tag === "Success"
2522
+ ? pickWorkspaceBasenameMatch(workspaceRelativePath, result.value.entries)
2523
+ : null;
2524
+ };
2525
+ const openFileInPanel = (panelPath: string, line: number | undefined) => {
2526
+ if (!threadRef) return;
2527
+ // Claimed on every open so a synchronous one supersedes a lookup already
2528
+ // in flight.
2529
+ const isLatestLookup = claimWorkspaceBasenameLookup();
2530
+ const openAt = (path: string) => useRightPanelStore.getState().openFile(threadRef, path, line);
2531
+ if (!cwd || !needsWorkspaceBasenameLookup(panelPath)) {
2532
+ openAt(panelPath);
2533
+ return;
2534
+ }
2535
+ void (async () => {
2536
+ const match = await findWorkspaceBasenameMatch(panelPath);
2537
+ if (!isLatestLookup()) return;
2538
+ openAt(match ?? panelPath);
2539
+ })();
2540
+ };
2541
+ const revealMarkdownFileInFileManager = async (fileLinkMeta: MarkdownFileLinkMeta) => {
2542
+ const workspaceRelativePath = fileLinkMeta.workspaceRelativePath;
2543
+ const match = workspaceRelativePath
2544
+ ? await findWorkspaceBasenameMatch(workspaceRelativePath)
2545
+ : null;
2546
+ const filePath = match && cwd ? resolvePathLinkTarget(match, cwd) : fileLinkMeta.filePath;
2547
+ return revealFileInFileManager(filePath);
2548
+ };
2549
+ const fileLinkChip = (
2550
+ fileLinkMeta: MarkdownFileLinkMeta,
2551
+ copyMarkdown: string,
2552
+ mediaSource?: string,
2553
+ ) => {
2554
+ const mediaPath = mediaSource ?? fileLinkMeta.filePath;
2555
+ const canPreviewMedia =
2556
+ mediaMimeTypeFromExtension(
2557
+ fileLinkMeta.basename.slice(fileLinkMeta.basename.lastIndexOf(".")),
2558
+ ) !== null;
2559
+ const panelPath =
2560
+ fileLinkMeta.workspaceRelativePath ??
2561
+ (!canPreviewMedia && isAbsolutePath(fileLinkMeta.filePath) ? fileLinkMeta.filePath : null);
2562
+
2563
+ return (
2564
+ <MarkdownFileLink
2565
+ environmentId={environmentId}
2566
+ href={fileLinkMeta.targetPath}
2567
+ targetPath={fileLinkMeta.targetPath}
2568
+ iconPath={fileLinkMeta.filePath}
2569
+ displayPath={fileLinkMeta.displayPath}
2570
+ panelPath={panelPath}
2571
+ line={fileLinkMeta.line}
2572
+ label={fileLinkLabel(
2573
+ {
2574
+ path: fileLinkMeta.filePath,
2575
+ ...(fileLinkMeta.line !== undefined ? { line: fileLinkMeta.line } : {}),
2576
+ ...(fileLinkMeta.column !== undefined ? { column: fileLinkMeta.column } : {}),
2577
+ },
2578
+ fileLinkParentSuffixByPath,
2579
+ )}
2580
+ copyMarkdown={copyMarkdown}
2581
+ theme={resolvedTheme}
2582
+ threadRef={threadRef}
2583
+ {...(canUseShellActions ? { onOpen: openInPreferredEditor } : {})}
2584
+ onOpenInPanel={openFileInPanel}
2585
+ onOpenMedia={
2586
+ threadRef && canPreviewMedia
2587
+ ? () => openMarkdownMedia(mediaPath, fileLinkMeta.filePath)
2588
+ : undefined
2589
+ }
2590
+ openInEditorMenuLabel={preferredEditorMenuLabel}
2591
+ onReveal={
2592
+ canUseShellActions && revealInFileManagerLabel !== undefined
2593
+ ? () => revealMarkdownFileInFileManager(fileLinkMeta)
2594
+ : undefined
2595
+ }
2596
+ revealLabel={revealInFileManagerLabel}
2597
+ onOpenInBrowser={
2598
+ threadRef &&
2599
+ canOperatePreview &&
2600
+ isPreviewAvailableFor(threadRef.environmentId) &&
2601
+ isBrowserPreviewFile(fileLinkMeta.filePath)
2602
+ ? () => openMarkdownFileInPreview(fileLinkMeta.filePath)
2603
+ : undefined
2604
+ }
2605
+ />
2606
+ );
2607
+ };
2608
+
2609
+ const componentState = {
2610
+ canOperateHost,
2611
+ canOperatePreview,
2612
+ cwd,
2613
+ diffThemeName,
2614
+ environmentId,
2615
+ expandMedia,
2616
+ fileLinkChip,
2617
+ githubMedia,
2618
+ renderContextReference,
2619
+ headingLevelOffset,
2620
+ imageBaseDir,
2621
+ inlineCodeFileLinkMetaByText,
2622
+ isStreaming,
2623
+ linkTargetPreference,
2624
+ markdownFileLinkMetaByHref,
2625
+ onTaskListChange,
2626
+ onUseArtifactTemplate,
2627
+ onRunShellCommand,
2628
+ openChangeRequestLink,
2629
+ openDeferredMarkdownLink,
2630
+ openExternalLinkInPreview,
2631
+ openMarkdownMedia,
2632
+ projects,
2633
+ linkedThreadPullRequestFor,
2634
+ resolveThreadPullRequest,
2635
+ resolvedTheme,
2636
+ pullRequestsEnabled,
2637
+ skills,
2638
+ threadRef,
2639
+ updateThreadPullRequestLink,
2640
+ };
2641
return {
2642
componentState,
2643
handleCopy,
2644
markdownRef,
2645
markdownUrlTransform,
2646
localMediaPreview,
2734
- setLocalMediaPreview,
2647
+ closeLocalMediaPreview,
2648
};
2649
}
2650
@@ -3355,20 +3268,17 @@ function ChatMarkdown({
3268
markdownRef,
3269
markdownUrlTransform,
3270
localMediaPreview,
3358
- setLocalMediaPreview,
3271
+ closeLocalMediaPreview,
3272
} = useChatMarkdownState({ text, ...props });
3273
const incrementalParsing =
3274
props.isStreaming === true &&
3275
extraRemarkPlugins.length === 0 &&
3276
/(?:^|\n) {0,3}(?:`{3}|~{3})/.test(text);
3364
- const remarkPlugins = useMemo(
3365
- () => [
3366
- ...(lineBreaks ? CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS : CHAT_MARKDOWN_REMARK_PLUGINS),
3367
- ...extraRemarkPlugins,
3368
- ...(incrementalParsing ? [createIncrementalMarkdownPlugin()] : []),
3369
- ],
3370
- [extraRemarkPlugins, incrementalParsing, lineBreaks],
3371
- );
3277
+ const remarkPlugins = [
3278
+ ...(lineBreaks ? CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS : CHAT_MARKDOWN_REMARK_PLUGINS),
3279
+ ...extraRemarkPlugins,
3280
+ ...(incrementalParsing ? [createIncrementalMarkdownPlugin()] : []),
3281
+ ];
3282
3283
return (
3284
<div
@@ -3398,10 +3308,7 @@ function ChatMarkdown({
3308
</ChatMarkdownTextContext>
3309
</ChatMarkdownRendererContext>
3310
{localMediaPreview ? (
3401
- <ExpandedImageDialog
3402
- preview={localMediaPreview}
3403
- onClose={() => setLocalMediaPreview(null)}
3404
- />
3311
+ <ExpandedImageDialog preview={localMediaPreview} onClose={closeLocalMediaPreview} />
3312
) : null}
3313
</div>
3314
);