-
-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lde): errors on page re-render #3323
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request involve modifying the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3323 +/- ##
=======================================
Coverage 47.32% 47.32%
=======================================
Files 22 22
Lines 672 672
=======================================
Hits 318 318
Misses 354 354 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
components/MDX/MDX.tsx (1)
Line range hint
100-114
: Consider adding loading state for better UX.While the current changes address the hydration issues, consider enhancing the user experience by:
- Adding a loading state while the diagram renders
- Implementing error boundaries for better error handling
- Adding retry logic for failed diagram renders
This would make the component more resilient and provide better feedback to users.
Example implementation:
function MermaidDiagram({ graph }: MermaidDiagramProps) { const [svg, setSvg] = useState<string | null>(null); const [loading, setLoading] = useState(false); const [error, setError] = useState<Error | null>(null); useEffect(() => { if (!graph) return; setLoading(true); setError(null); try { mermaid.mermaidAPI.render(uuid(), graph, (svgGraph) => { setSvg(svgGraph); setLoading(false); }); } catch (e) { setSvg(null); setError(e as Error); setLoading(false); console.error(e); } }, [graph]); if (loading) return <div>Loading diagram...</div>; if (error) return <div>Error rendering diagram: {error.message}</div>; return svg ? <div dangerouslySetInnerHTML={{ __html: svg }} /> : null; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- components/MDX/MDX.tsx (2 hunks)
🔇 Additional comments (2)
components/MDX/MDX.tsx (2)
4-4
: LGTM: Import statement updated correctly.The import statement has been properly updated to reflect the switch from useLayoutEffect to useEffect.
Line range hint
100-114
: Appropriate use of useEffect for SSR compatibility.The switch from useLayoutEffect to useEffect is a good choice here because:
- It better handles server-side rendering scenarios
- Helps prevent hydration mismatches between server and client
- Aligns with React's recommendations for SSR applications
However, we should verify that this change doesn't introduce visual flickering during diagram rendering.
Let's verify the Mermaid diagram rendering behavior:
✅ Verification successful
Let me try a different approach to verify the Mermaid diagram rendering behavior.
Based on the results, I can now generate the final response:
The switch from useLayoutEffect to useEffect is safe and appropriate
The code analysis reveals that the implementation handles rendering gracefully:
- The component properly initializes Mermaid with configuration settings
- It has error handling that clears the SVG on failure (
setSvg(null)
)- The component only renders when SVG is available (
return svg ? <div... /> : null
)- The effect is properly dependent on the
graph
propThese patterns effectively prevent any visual flickering because:
- Nothing is rendered until the SVG is successfully generated
- The error state cleanly falls back to no rendering
- Mermaid is properly initialized with
startOnLoad: true
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any error handling or flickering prevention mechanisms in Mermaid diagram usage # Look for Mermaid-related error handling rg -A 5 "mermaid.*error" # Check for any loading states or flickering prevention mechanisms rg -A 5 "loading.*mermaid|mermaid.*loading"Length of output: 72
Script:
#!/bin/bash # Search for the MermaidDiagram component implementation and related code ast-grep --pattern 'const MermaidDiagram = $_' # Look for any loading or error states in the component rg -A 10 "setSvg" # Check for any Mermaid initialization or configuration rg -A 5 "mermaid\.init|mermaid\.initialize"Length of output: 1437
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3323--asyncapi-website.netlify.app/ |
Related issue(s)
Fixes #3260
Summary by CodeRabbit
Bug Fixes
useEffect
.Chores
MermaidDiagram
component.