Fixes wide Mermaid diagrams rendered with extremely small text due to responsive SVG sizing. #480
Open
aradhyacp wants to merge 6 commits intovercel:mainfrom
Open
Fixes wide Mermaid diagrams rendered with extremely small text due to responsive SVG sizing. #480aradhyacp wants to merge 6 commits intovercel:mainfrom
aradhyacp wants to merge 6 commits intovercel:mainfrom
Conversation
…ove diagram readability and auto-fit functionality
Contributor
|
@aradhyacp is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 fixes an issue where wide Mermaid diagrams rendered with extremely small text due to SVG responsive scaling.
The solution introduces a two-layer approach:
This ensures diagrams are neither too small (unreadable) nor overly zoomed on initial render.
Type of Change
Related Issues
Fixes #479
Closes #479
Related to #479
Changes Made
getMermaidSvgSizeto extract intrinsic dimensions from SVGviewBoxnormalizeMermaidInlineSvgto remove responsive sizing and enforce fixed width/heightPanZoomwith:contentSizefor geometry-aware scalingisAutoFitto enable automatic fittingfitKeyto trigger refit on diagram changesbaseZoom,effectiveMinZoom, andhasUserInteractedstate for stable zoom behaviorminZoomTesting
Test Coverage
Manually tested the Mermaid diagrams rendered
How I tested it locally:
I wanted to verify my changes, so I linked the local package into a test React app:
Then I used the following test component:
Screenshots/Demos
Before
After
Checklist
pnpm changeset)Changeset
Additional Notes
This fix intentionally separates content geometry (SVG intrinsic size) from viewport geometry (container size) and computes scaling explicitly rather than relying on browser responsiveness.
The approach resolves both failure modes:
Auto-fit is applied only until user interaction to preserve user intent.