feat(SyntaxHighlighting): Improve stability of syntax highlighting so it doesn't flicker.

This commit is contained in:
Willie Zutz 2025-08-11 23:53:37 -06:00
parent 88e7a5bb7e
commit 3369e2bf69
3 changed files with 15 additions and 25 deletions

View file

@ -152,3 +152,4 @@ When working on this codebase, you might need to:
- `/quantizor/markdown-to-jsx` for Markdown to JSX conversion
- `/context7/headlessui_com` for Headless UI components
- `/tailwindlabs/tailwindcss.com` for Tailwind CSS documentation
- `/vercel/next.js` for Next.js documentation

View file

@ -181,25 +181,6 @@ const CodeBlock = ({
className?: string;
children: React.ReactNode;
}) => {
// Determine dark mode based on html.dark class so custom themes are respected
const [isDark, setIsDark] = useState(false);
useEffect(() => {
const getIsDark = () =>
typeof document !== 'undefined' &&
document.documentElement.classList.contains('dark');
setIsDark(getIsDark());
const observer = new MutationObserver(() => setIsDark(getIsDark()));
if (typeof document !== 'undefined') {
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['class'],
});
}
return () => observer.disconnect();
}, []);
// Extract language from className (format could be "language-javascript" or "lang-javascript")
let language = '';
if (className) {
@ -219,7 +200,9 @@ const CodeBlock = ({
setTimeout(() => setIsCopied(false), 2000);
};
// Choose syntax highlighting style based on actual dark/light class
const root = document.documentElement;
const isDark = root.classList.contains('dark');
const syntaxStyle = isDark ? oneDark : oneLight;
const backgroundStyle = isDark ? '#1c1c1c' : '#fafafa';
@ -248,10 +231,10 @@ const CodeBlock = ({
borderRadius: 0,
backgroundColor: backgroundStyle,
}}
wrapLines={true}
wrapLongLines={true}
wrapLines
wrapLongLines
showLineNumbers={language !== '' && content.split('\n').length > 1}
useInlineStyles={true}
useInlineStyles
PreTag="div"
>
{content}

View file

@ -18,7 +18,10 @@ import {
} from '@/lib/tools/agents';
import { formatDateForLLM } from '../utils';
import { getModelName } from '../utils/modelUtils';
import { removeThinkingBlocks, removeThinkingBlocksFromMessages } from '../utils/contentUtils';
import {
removeThinkingBlocks,
removeThinkingBlocksFromMessages,
} from '../utils/contentUtils';
import { getLangfuseCallbacks } from '@/lib/tracing/langfuse';
/**
@ -499,7 +502,10 @@ Use all available tools strategically to provide comprehensive, well-researched,
console.log(`SimplifiedAgent: Focus mode: ${focusMode}`);
console.log(`SimplifiedAgent: File IDs: ${fileIds.join(', ')}`);
const messagesHistory = [...removeThinkingBlocksFromMessages(history), new HumanMessage(query)];
const messagesHistory = [
...removeThinkingBlocksFromMessages(history),
new HumanMessage(query),
];
// Initialize agent with the provided focus mode and file context
// Pass the number of messages that will be sent to the LLM so prompts can adapt.
const llmMessagesCount = messagesHistory.length;