Skip to content

Commit 345895b

Browse files
fix(web): keep chat shell fence check linear and match toolbar styling
The closing-fence regex nested `[ \t]*` inside a repeated group, so a finished assistant code block with a line of repeated `> ` markers backtracked exponentially (28 markers took ~5s, 30 took ~20s) on every render. It ran for every code block, not just shell ones. Collapse the blockquote prefix into one character class; the match is unchanged. Also reject invisible format characters (bidi overrides, zero-width) so the rendered command matches what Run sends, and use the ghost-muted variant that main now gives the sibling Copy and Wrap actions. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent cdaac7b commit 345895b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎apps/web/src/components/ChatMarkdown.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ describe("ChatMarkdown streaming", () => {
225225
"```bash\necho one\necho two\n```",
226226
"```typescript\necho hello\n```",
227227
"```bash\n\n```",
228+
"```bash\necho safe \u202e#\n```",
228229
"```bash\necho incomplete",
229230
"~~~bash\necho incomplete",
230231
"````bash\necho incomplete\n```",

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ function isClosedCodeFence(node: ReactMarkdownExtraProps["node"], text: string):
591591
if (start === undefined || end === undefined) return false;
592592
const source = text.slice(start, end);
593593
const opening = /^(?:`{3,}|~{3,})/.exec(source)?.[0];
594-
const closing = /(?:^|\n)(?:[ \t]*>[ \t]*)*[ \t]*(`{3,}|~{3,})[ \t\r]*$/.exec(source)?.[1];
594+
// One class for the blockquote prefix: nested quantifiers here backtrack
595+
// exponentially on code lines that start with many `> ` markers.
596+
const closing = /(?:^|\n)[ \t>]*(`{3,}|~{3,})[ \t\r]*$/.exec(source)?.[1];
595597
return (
596598
opening !== undefined &&
597599
closing !== undefined &&
@@ -959,7 +961,9 @@ function MarkdownCodeBlock({
959961
!isStreaming &&
960962
/^(?:sh|bash|zsh|fish|shell|powershell|pwsh)$/.test(language) &&
961963
command.length > 0 &&
962-
!/\p{Cc}/u.test(command);
964+
// Control and invisible format characters (bidi overrides, zero-width) can
965+
// make the rendered command differ from what the terminal would receive.
966+
!/[\p{Cc}\p{Cf}]/u.test(command);
963967

964968
const handleCopy = useCallback(() => {
965969
if (typeof navigator === "undefined" || navigator.clipboard == null) {
@@ -1038,7 +1042,7 @@ function MarkdownCodeBlock({
10381042
render={
10391043
<Button
10401044
type="button"
1041-
variant="ghost"
1045+
variant="ghost-muted"
10421046
size="icon-xs"
10431047
onClick={() => onRunShellCommand(command)}
10441048
aria-label="Run in terminal"

0 commit comments

Comments
 (0)