yangdx
commited on
Commit
·
87eb497
1
Parent(s):
d46882c
Fix linting
Browse files
lightrag_webui/src/components/retrieval/ChatMessage.tsx
CHANGED
@@ -25,7 +25,7 @@ export type MessageWithError = Message & {
|
|
25 |
export const ChatMessage = ({ message }: { message: MessageWithError }) => {
|
26 |
const { t } = useTranslation()
|
27 |
// Remove extra spaces around bold text
|
28 |
-
message.content = message.content.replace(
|
29 |
|
30 |
const handleCopyMarkdown = useCallback(async () => {
|
31 |
if (message.content) {
|
@@ -147,10 +147,10 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
|
|
147 |
|
148 |
|
149 |
if (!looksPotentiallyComplete) {
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
}
|
155 |
|
156 |
const processedContent = rawContent
|
@@ -181,13 +181,13 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
|
|
181 |
try { // Add try-catch around bindFunctions as it can also throw
|
182 |
bindFunctions(container);
|
183 |
} catch (bindError) {
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
}
|
188 |
}
|
189 |
} else {
|
190 |
-
|
191 |
}
|
192 |
})
|
193 |
.catch(error => {
|
@@ -207,13 +207,13 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
|
|
207 |
} catch (error) {
|
208 |
console.error('Mermaid synchronous error (debounced):', error);
|
209 |
console.error('Failed content (debounced):', String(children));
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
}
|
218 |
}
|
219 |
}, 300); // 300ms debounce delay
|
|
|
25 |
export const ChatMessage = ({ message }: { message: MessageWithError }) => {
|
26 |
const { t } = useTranslation()
|
27 |
// Remove extra spaces around bold text
|
28 |
+
message.content = message.content.replace(/\* {3}/g, '').replace(/ {4}\*\*/g, '**')
|
29 |
|
30 |
const handleCopyMarkdown = useCallback(async () => {
|
31 |
if (message.content) {
|
|
|
147 |
|
148 |
|
149 |
if (!looksPotentiallyComplete) {
|
150 |
+
console.log('Mermaid content might be incomplete, skipping render attempt:', rawContent);
|
151 |
+
// Keep loading indicator or show a message
|
152 |
+
// container.innerHTML = '<p class="text-sm text-muted-foreground">Waiting for complete diagram...</p>';
|
153 |
+
return; // Don't attempt to render potentially incomplete content
|
154 |
}
|
155 |
|
156 |
const processedContent = rawContent
|
|
|
181 |
try { // Add try-catch around bindFunctions as it can also throw
|
182 |
bindFunctions(container);
|
183 |
} catch (bindError) {
|
184 |
+
console.error('Mermaid bindFunctions error:', bindError);
|
185 |
+
// Optionally display a message in the container
|
186 |
+
container.innerHTML += '<p class="text-orange-500 text-xs">Diagram interactions might be limited.</p>';
|
187 |
}
|
188 |
}
|
189 |
} else {
|
190 |
+
console.log('Mermaid container changed before rendering completed.');
|
191 |
}
|
192 |
})
|
193 |
.catch(error => {
|
|
|
207 |
} catch (error) {
|
208 |
console.error('Mermaid synchronous error (debounced):', error);
|
209 |
console.error('Failed content (debounced):', String(children));
|
210 |
+
if (mermaidRef.current === container) {
|
211 |
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
212 |
+
const errorPre = document.createElement('pre');
|
213 |
+
errorPre.className = 'text-red-500 text-xs whitespace-pre-wrap break-words';
|
214 |
+
errorPre.textContent = `Mermaid diagram setup error: ${errorMessage}`;
|
215 |
+
container.innerHTML = ''; // Clear previous content
|
216 |
+
container.appendChild(errorPre);
|
217 |
}
|
218 |
}
|
219 |
}, 300); // 300ms debounce delay
|