Fix linting

This commit is contained in:
yangdx
2025-04-22 09:05:23 +08:00
parent fd997f239b
commit be032db1f8

View File

@@ -25,7 +25,7 @@ export type MessageWithError = Message & {
export const ChatMessage = ({ message }: { message: MessageWithError }) => { export const ChatMessage = ({ message }: { message: MessageWithError }) => {
const { t } = useTranslation() const { t } = useTranslation()
// Remove extra spaces around bold text // Remove extra spaces around bold text
message.content = message.content.replace(/\*\ {3}/g, '').replace(/\ {4}\*\*/g, '**') message.content = message.content.replace(/\* {3}/g, '').replace(/ {4}\*\*/g, '**')
const handleCopyMarkdown = useCallback(async () => { const handleCopyMarkdown = useCallback(async () => {
if (message.content) { if (message.content) {
@@ -147,10 +147,10 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
if (!looksPotentiallyComplete) { if (!looksPotentiallyComplete) {
console.log("Mermaid content might be incomplete, skipping render attempt:", rawContent); console.log('Mermaid content might be incomplete, skipping render attempt:', rawContent);
// Keep loading indicator or show a message // Keep loading indicator or show a message
// container.innerHTML = '<p class="text-sm text-muted-foreground">Waiting for complete diagram...</p>'; // container.innerHTML = '<p class="text-sm text-muted-foreground">Waiting for complete diagram...</p>';
return; // Don't attempt to render potentially incomplete content return; // Don't attempt to render potentially incomplete content
} }
const processedContent = rawContent const processedContent = rawContent
@@ -181,13 +181,13 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
try { // Add try-catch around bindFunctions as it can also throw try { // Add try-catch around bindFunctions as it can also throw
bindFunctions(container); bindFunctions(container);
} catch (bindError) { } catch (bindError) {
console.error('Mermaid bindFunctions error:', bindError); console.error('Mermaid bindFunctions error:', bindError);
// Optionally display a message in the container // Optionally display a message in the container
container.innerHTML += `<p class="text-orange-500 text-xs">Diagram interactions might be limited.</p>`; container.innerHTML += '<p class="text-orange-500 text-xs">Diagram interactions might be limited.</p>';
} }
} }
} else { } else {
console.log("Mermaid container changed before rendering completed."); console.log('Mermaid container changed before rendering completed.');
} }
}) })
.catch(error => { .catch(error => {
@@ -207,13 +207,13 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
} catch (error) { } catch (error) {
console.error('Mermaid synchronous error (debounced):', error); console.error('Mermaid synchronous error (debounced):', error);
console.error('Failed content (debounced):', String(children)); console.error('Failed content (debounced):', String(children));
if (mermaidRef.current === container) { if (mermaidRef.current === container) {
const errorMessage = error instanceof Error ? error.message : String(error); const errorMessage = error instanceof Error ? error.message : String(error);
const errorPre = document.createElement('pre'); const errorPre = document.createElement('pre');
errorPre.className = 'text-red-500 text-xs whitespace-pre-wrap break-words'; errorPre.className = 'text-red-500 text-xs whitespace-pre-wrap break-words';
errorPre.textContent = `Mermaid diagram setup error: ${errorMessage}`; errorPre.textContent = `Mermaid diagram setup error: ${errorMessage}`;
container.innerHTML = ''; // Clear previous content container.innerHTML = ''; // Clear previous content
container.appendChild(errorPre); container.appendChild(errorPre);
} }
} }
}, 300); // 300ms debounce delay }, 300); // 300ms debounce delay