[lexical-playground] Fix: add fallback for dimensionless images to prevent collapse#8186
Open
Sa-Te wants to merge 1 commit intofacebook:mainfrom
Open
[lexical-playground] Fix: add fallback for dimensionless images to prevent collapse#8186Sa-Te wants to merge 1 commit intofacebook:mainfrom
Sa-Te wants to merge 1 commit intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
1a6e1d0 to
39219a4
Compare
etrepum
reviewed
Feb 28, 2026
Comment on lines
+165
to
+166
| const isActuallySVG = | ||
| isSVG(src) || src.toLowerCase().startsWith('data:image/svg+xml'); |
Collaborator
There was a problem hiding this comment.
Why not change isSVG accordingly?
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 SVGs inserted without explicit
widthandheightattributes (such as dimensionless SVGs or base64 data URIs) would visually collapse to0x0in the editor.The Problem
When a dimensionless SVG or a base64 SVG string is parsed:
naturalWidthandnaturalHeightas0.ImageNodeconstructor defaults missing dimensions to'inherit'.ImageComponent), the previous fallback logic relied on a fragileisSVGcheck that failed for base64 data URIs.0, the component rendered with0pxinline styles, making the node invisible and unselectable.The Fix
I pivoted from a global fallback to a Surgical SVG Fallback to maintain compatibility with Lexical's existing E2E test suite:
data:image/svg+xmlprefixes.'inherit'for dimensions. This ensures that existing E2E tests (which rely on specific HTML snapshots for standard images) remain green and global CSS remains in control of responsive sizing.maxWidth. This ensures a visible bounding box is rendered, allowing the user to see, select, and resize the image.Fixes #7511
Test Plan
Images.spec.ts-> "Dimensionless SVG renders with a visible bounding box instead of collapsing". This verifies that a base64 encoded SVG without attributes renders with a width/height > 0.Toolbar.spec.mjs) still receivestyle="width: inherit; height: inherit"to satisfy existing Playwright assertions.npx playwright test packages/lexical-playground/__tests__/e2e/and confirmed all 600+ tests pass.