Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

perf([issue-3282]): memoize the card-body flatten and line-scope its emphasis regexes

[._.]/ Adam Eivy0ff6b375044e
diff --git a/client/src/components/ui/CollapsibleText.jsx b/client/src/components/ui/CollapsibleText.jsx
index 0a127aa6c5..e61b503f6e 100644
--- a/client/src/components/ui/CollapsibleText.jsx
+++ b/client/src/components/ui/CollapsibleText.jsx
@@ -72,7 +72,7 @@ export default function CollapsibleText({
return (
<>
{expanded && expandedContent ? (
- <div id={id} className={`${className} ${expandedClassName}`}>{expandedContent}</div>
+ <div id={id} className={`break-words ${className} ${expandedClassName}`}>{expandedContent}</div>
) : (
<p
ref={ref}
diff --git a/client/src/pages/Review.jsx b/client/src/pages/Review.jsx
index ddb112da4e..3c81a17921 100644
--- a/client/src/pages/Review.jsx
+++ b/client/src/pages/Review.jsx
@@ -692,6 +692,10 @@ function ReviewItem({ item, config, idScope, isEditing, onComplete, onDismiss, o
const [editTitle, setEditTitle] = useState(item.title);
const [editDescription, setEditDescription] = useState(item.description || '');
const isPending = item.status === 'pending';
+ // The page re-renders on every socket event and on every keystroke in the
+ // quick-add input, and a body can be a multi-thousand-word agent prompt —
+ // flatten once per description rather than once per render, per card.
+ const bodyPreview = useMemo(() => markdownToPlainText(item.description), [item.description]);
useEffect(() => {
if (isEditing) {
@@ -763,7 +767,7 @@ function ReviewItem({ item, config, idScope, isEditing, onComplete, onDismiss, o
<CollapsibleText
id={`review-item-body-${idScope}-${item.id}`}
lines={3}
- text={markdownToPlainText(item.description)}
+ text={bodyPreview}
className="text-xs text-gray-500 mt-0.5"
expandedContent={<MarkdownOutput content={item.description} />}
expandedClassName="max-h-80 overflow-y-auto pr-1"
diff --git a/client/src/utils/markdownText.js b/client/src/utils/markdownText.js
index b4a7d8b883..02b7b46ecb 100644
--- a/client/src/utils/markdownText.js
+++ b/client/src/utils/markdownText.js
@@ -40,9 +40,13 @@ export function markdownToPlainText(markdown) {
.replace(/!\[([^\]]*)\]\([^)]*\)/g, (_, alt) => (alt ? `[${alt}]` : '[image]'))
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1') // links → their text
.replace(/`([^`]*)`/g, '$1') // inline code
- .replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, '$2') // bold
- .replace(/(\*|_)(?=\S)([^*_]*?\S)\1/g, '$2') // italic
- .replace(/~~(?=\S)([\s\S]*?\S)~~/g, '$1') // strikethrough
+ // Emphasis spans are matched within a single line ([^\n], not [\s\S]). Real
+ // markdown emphasis doesn't span paragraphs, and a line-bounded lazy
+ // quantifier means an unclosed `**` in a multi-thousand-word agent body
+ // backtracks over one line instead of the whole document.
+ .replace(/(\*\*|__)(?=\S)([^\n]*?\S)\1/g, '$2') // bold
+ .replace(/(\*|_)(?=\S)([^*_\n]*?\S)\1/g, '$2') // italic
+ .replace(/~~(?=\S)([^\n]*?\S)~~/g, '$1') // strikethrough
.replace(/[ \t]+/g, ' ')
.replace(/\n{2,}/g, '\n') // collapse blank-line runs
.split('\n')
diff --git a/client/src/utils/markdownText.test.js b/client/src/utils/markdownText.test.js
index f3e2349423..e90935b97b 100644
--- a/client/src/utils/markdownText.test.js
+++ b/client/src/utils/markdownText.test.js
@@ -27,6 +27,14 @@ describe('markdownToPlainText', () => {
.toBe('see the report');
});
+ it('scopes emphasis to a single line so a stray marker cannot swallow the body', () => {
+ // An unclosed `**` in an agent-authored body must leave the rest of the
+ // document intact (and must not backtrack across it): the marker on the
+ // first line stays, and a genuine pair on a later line still unwraps.
+ expect(markdownToPlainText('open **here\nplain line\n**closed** later'))
+ .toBe('open **here\nplain line\nclosed later');
+ });
+
it('renders images as a bracketed alt placeholder rather than a URL', () => {
expect(markdownToPlainText('![a diagram](/img/x.png)')).toBe('[a diagram]');
expect(markdownToPlainText('![](/img/x.png)')).toBe('[image]');