Skip to content

Commit 8255ea1

Browse files
committed
fix: add error handling to CodeBlock lazy loading
- Add catch handler for dynamic import failures - Provide fallback component when import fails - Log error to console for debugging
1 parent 976023c commit 8255ea1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/components/CodeBlockLazy.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import React, { lazy, Suspense } from 'react';
22

3-
const CodeBlock = lazy(() => import('./CodeBlock'));
3+
// Lazy load with error boundary
4+
const CodeBlock = lazy(() =>
5+
import('./CodeBlock').catch(() => {
6+
console.error('Failed to load CodeBlock component');
7+
// Return a fallback component on error
8+
return { default: ({ children, className = '' }) => (
9+
<code className={`block bg-gray-100 dark:bg-gray-800 p-3 rounded-lg overflow-x-auto my-4 text-gray-800 dark:text-gray-200 text-sm font-mono whitespace-pre-wrap break-words ${className}`}>
10+
{children}
11+
</code>
12+
)};
13+
})
14+
);
415

516
const CodeBlockFallback = ({ children, className = '' }) => (
617
<code className={`block bg-gray-100 dark:bg-gray-800 p-3 rounded-lg overflow-x-auto my-4 text-gray-800 dark:text-gray-200 text-sm font-mono whitespace-pre-wrap break-words ${className}`}>

0 commit comments

Comments
 (0)