Image Cropper: Ensure to check for focal point#21275
Image Cropper: Ensure to check for focal point#21275bjarnef wants to merge 4 commits intoumbraco:mainfrom
Conversation
…ies on focal point
|
Hi there @bjarnef, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #21273 by adding defensive null/undefined checks before accessing the left and top properties of the focal point object in the image cropper component. This prevents runtime errors when the focal point value is null or undefined.
Key changes:
- Added null check in the
focalPointsetter before accessing properties - Added null check in
#initializeImagemethod to prevent errors during initialization - Added null check in
#onFocalPointUpdatedmethod before calling#isCentered
| this.#focalPoint = value; | ||
| this.#setFocalPointStyle(this.#focalPoint.left, this.#focalPoint.top); | ||
| if (this.#focalPoint) { | ||
| this.#setFocalPointStyle(this.#focalPoint.left, this.#focalPoint.top); | ||
| } | ||
| this.#onFocalPointUpdated(); |
There was a problem hiding this comment.
The null check is added after assigning the value to this.#focalPoint. If value is null or undefined, the private field #focalPoint will be set to null, which contradicts its initialization on line 50 where it has a default value of { left: 0.5, top: 0.5 }. This could cause issues elsewhere in the code that expects #focalPoint to always be a valid object.
Consider either:
- Not assigning null values: Check if
valueis truthy before assignment - Always calling
#onFocalPointUpdated()regardless of the value to handle the null state consistently
The current implementation sets #focalPoint to null but still calls #onFocalPointUpdated() which now has a null check added at line 107.
There was a problem hiding this comment.
It always call #onFocalPointUpdated().
It just ensure #focalPoint is not null or undefined before accessing left and top properties.
|
Hi @bjarnef Thanks for your PR (and for raising the related issue) to fix #21273, where you noted users are not able to set focal point to null in One of the Core Collaborators team will review this as soon as possible. I've noticed the issue is currently being labelled too by HQ :) It would also be useful to consider the AI GitHub CoPilot comments in case they have an impact too. Best wishes Emma |
|
@nielslyngsoe do you have input to if we can set focal point to null as it was possible in v13, but with because it in new backoffice set focal point style inside property setter, if doesn't allow me to reset/clear focal point in my Hotspot package, which is a show stopper to release the package for v17, as the reset/clear can't be made. I can of course copy the entire component, but ideally the idea is to reuse the core component. |
… before accessing left and top properties on focal point.
Prerequisites
If there's an existing issue for this PR then this fixes #21273
Description
This ensure to check for focal point value, before accessing
leftandtopproperties and allows me to use nullable property when re-using component.E.g.
We could add this change in this component as well, but it may be considered as a breaking change.
We may also consider something like this instead - or just an overload:
An option may also be to create a new component and deprecate the existing.
and maybe something moved to a utility/helper function: #21264