Commit b332bff
fix(ui): prevent NaN aspect ratio in createThumbnail on svg files (#10488)
<!--
Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.
Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.
The following items will ensure that your PR is handled as smoothly as
possible:
- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change
### What?
### Why?
### How?
Fixes #
-->
### What?
This PR fixes an issue for Firefox users encountered when
drag-and-dropping an svg file into the BulkUpload drawer dropzone where,
because of both img.width and img.height being 0, aspect ratio becomes
NaN due to division by zero.
### Why?
To prevent a runtime error for Firefox users and to render an
appropriate thumbnail as expected.
### How?
By logically checking that the divisor, in this case `img.height` is not
zero, and setting a fallback if so.
Notes:
- This is a follow-up to an issue I found while authoring #10475 which
shows up as a runtime error in the below videos as well.
- As a result of this PR, I was reminded of another bug where thumbnails
were not correctly updated if the BulkUpload EditForm contained only
some successful files saved.
Before:
https://github.com/user-attachments/assets/e1b12a55-551a-4fcb-9df7-dabde87729b6
After:
https://github.com/user-attachments/assets/52791919-b657-4580-ac37-ca4be749c9a7
---------
Co-authored-by: Paul Popus <paul@payloadcms.com>1 parent 216d162 commit b332bff
2 files changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments