feat: #4636 Mermaid chart rendering Retry functionality #4867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves Mermaid diagram rendering and error recovery in the webview. It fixes syntax issues that caused rendering failures, adds robust error handling, and allows users to quickly resend and regenerate only the faulty Mermaid code block without affecting the rest of the answer.
Changes Made
Fixed syntax issues in Mermaid diagrams that caused rendering failures
Improved error handling for Mermaid chart rendering
Added a "Retry" button to regenerate only the problematic diagram
Ensured only the faulty diagram is regenerated, preserving the rest of the answer
Made error and code parameters optional and provided default values for better type safety
Technical Details
New Files
src/core/prompts/instructions/fix-mermaid.ts – Generates instructions for fixing Mermaid diagrams
Modified Files
src/core/prompts/instructions/instructions.ts – Integrated Mermaid fix instructions, made parameters optional, and added defaults
src/core/webview/webviewMessageHandler.ts – Handles new "fixMermaidChart" message type
src/shared/WebviewMessage.ts – Added "fixMermaidChart" to message types
webview-ui/src/components/common/MermaidBlock.tsx – Added "Retry" button and improved error UI/UX
Localization files: Added "retry" string in multiple languages
webview-ui/src/i18n/locales/en/common.json (and other language files)
Testing
All changes are type-safe and TypeScript compiles successfully
Linting passes with no errors
Build process completes without errors
Manual testing confirms improved error handling and retry functionality for Mermaid diagrams
How to Use
Trigger a Mermaid diagram rendering error in the webview
Use the new "Retry" button to regenerate only the faulty diagram
The rest of the answer remains unchanged, and the error message is improved
Notes
This update improves the user experience for working with Mermaid diagrams in the webview
All error handling and UI changes are fully localized
Important
Adds retry functionality for Mermaid chart rendering with improved error handling and localization support.
MermaidBlock.tsxto regenerate only faulty Mermaid diagrams without affecting others.MermaidBlock.tsx.fixMermaidChartmessage type inWebviewMessage.tsand handles it inwebviewMessageHandler.ts.createMermaidFixInstructions()infix-mermaid.tsto generate instructions for fixing diagrams.instructions.ts.This description was created by
for b758065. You can customize this summary. It will automatically update as commits are pushed.
