Fix preview tooltip content size in macromolecules mode #8257
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.
Problem
When hovering over peptides in macromolecules flex layout mode, the preview tooltip displays molecules at a tiny size, making them nearly impossible to see.
Root Cause
The issue occurs in
packages/ketcher-core/src/application/render/renderStruct.tswhen rendering structures in polymer editor mode. The code calculates SVG dimensions based on the wrapper element's bounding client rect:When the wrapper element hasn't been fully laid out yet or has very small initial dimensions (0x0 or 1x1 pixels),
svgSizebecomes tiny, causing the SVG to render at an unusable size.Solution
Added a minimum threshold check (
MIN_SVG_SIZE = 50) to prevent setting explicit dimensions when the calculated size is too small:When dimensions are not explicitly set, the renderer uses its default behavior ('100%' width/height with auto-scaling), which properly sizes the structure based on the wrapper element's actual dimensions once it's laid out.
Testing
Fixes #5573
Original prompt
Fixes #7728
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.