Skip to content

[lexical-playground] Bug Fix: Use natural dimensions for inherited image size#7388

Merged
etrepum merged 3 commits intofacebook:mainfrom
bgwebagency:fix/image-natural-dimensions
Mar 27, 2025
Merged

[lexical-playground] Bug Fix: Use natural dimensions for inherited image size#7388
etrepum merged 3 commits intofacebook:mainfrom
bgwebagency:fix/image-natural-dimensions

Conversation

@kirandash
Copy link
Copy Markdown
Contributor

Description

Current Behavior

Currently, when an image is inserted with 'inherit' dimensions in the Lexical playground, it defaults to arbitrary 200x200 dimensions without considering the image's natural size. This causes visual inconsistency and incorrect image rendering on initial load.

Changes in this PR

  1. Using the image's natural dimensions (naturalWidth/naturalHeight) when width/height is set to 'inherit'
  2. Maintaining proper aspect ratio during scaling
  3. Adding proper dimension detection on both initial mount and image load
  4. Keeping the existing maxWidth and maxHeight (500px) constraints for editor usability
  5. Using fallback dimensions (200x200) only while the image is loading

Closes #7376

Test plan

Before

image

After

image

- Use image's natural dimensions when width/height is 'inherit'
- Add fallback dimensions (200x200) while image loads
- Scale proportionally if exceeds maxWidth/maxHeight constraints
- Handle dimensions on both initial mount and image load
- Maintain aspect ratio during scaling

Fixes facebook#7376
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 26, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 27, 2025 1:12pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 27, 2025 1:12pm

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 26, 2025
@kirandash kirandash marked this pull request as draft March 26, 2025 18:50
@kirandash kirandash changed the title [lexical-playground] Bug Fix: Use natural dimensions for inherited image size [WIP][lexical-playground] Bug Fix: Use natural dimensions for inherited image size Mar 26, 2025
@potatowagon potatowagon requested a review from lilshady March 27, 2025 02:44
- Add proper dimension calculation for SVG images
- Ensure SVG images maintain aspect ratio while respecting maxWidth
- Add comprehensive test case for both SVG and JPG image handling

Fixes facebook#7376
- Skip test in collab mode where dimensions are handled differently

Fixes facebook#7376
@kirandash kirandash marked this pull request as ready for review March 27, 2025 13:36
@kirandash kirandash requested a review from takuyakanbr as a code owner March 27, 2025 13:36
@kirandash kirandash changed the title [WIP][lexical-playground] Bug Fix: Use natural dimensions for inherited image size [lexical-playground] Bug Fix: Use natural dimensions for inherited image size Mar 27, 2025
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I notice that the tests depend on a particular URL on the website which could make things fail unexpectedly in the future but it doesn't seem to be the only test that's doing it so we can worry about that another time

@etrepum etrepum added this pull request to the merge queue Mar 27, 2025
Merged via the queue into facebook:main with commit 74efb1d Mar 27, 2025
39 checks passed
@etrepum etrepum mentioned this pull request Apr 7, 2025
GermanJablo added a commit to payloadcms/payload that referenced this pull request Sep 3, 2025
Fixes #13386

Below I write a clarification to copy and paste into the release note,
based on our latest upgrade of Lexical [in
v3.29.0](https://github.com/payloadcms/payload/releases/tag/v3.29.0).

## Important
This release upgrades the lexical dependency from 0.28.0 to 0.34.0.

If you installed lexical manually, update it to 0.34.0. Installing
lexical manually is not recommended, as it may break between updates,
and our re-exported versions should be used. See the [yellow banner
box](https://payloadcms.com/docs/rich-text/custom-features) for details.

If you still encounter richtext-lexical errors, do the following, in
this order:

- Delete node_modules
- Delete your lockfile (e.g. pnpm-lock.json)
- Reinstall your dependencies (e.g. pnpm install)

### Lexical Breaking Changes

The following Lexical releases describe breaking changes. We recommend
reading them if you're using Lexical APIs directly
(`@payloadcms/richtext-lexical/lexical/*`).

- [v.0.33.0](https://github.com/facebook/lexical/releases/tag/v0.33.0)
- [v.0.30.0](https://github.com/facebook/lexical/releases/tag/v0.30.0)
- [v.0.29.0](https://github.com/facebook/lexical/releases/tag/v0.29.0)

___

TODO:
- [x] facebook/lexical#7719
- [x] facebook/lexical#7362
- [x] facebook/lexical#7707
- [x] facebook/lexical#7388
- [x] facebook/lexical#7357
- [x] facebook/lexical#7352
- [x] facebook/lexical#7472
- [x] facebook/lexical#7556
- [x] facebook/lexical#7417
- [x] facebook/lexical#1036
- [x] facebook/lexical#7509
- [x] facebook/lexical#7693
- [x] facebook/lexical#7408
- [x] facebook/lexical#7450
- [x] facebook/lexical#7415
- [x] facebook/lexical#7368
- [x] facebook/lexical#7372
- [x] facebook/lexical#7572
- [x] facebook/lexical#7558
- [x] facebook/lexical#7613
- [x] facebook/lexical#7405
- [x] facebook/lexical#7420
- [x] facebook/lexical#7662

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211202581885926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Inserting Image via url

3 participants