Skip to content

Image Cropper: Ensure to check for focal point#21275

Open
bjarnef wants to merge 4 commits intoumbraco:mainfrom
bjarnef:feature/image-cropper-focal-point-nullable
Open

Image Cropper: Ensure to check for focal point#21275
bjarnef wants to merge 4 commits intoumbraco:mainfrom
bjarnef:feature/image-cropper-focal-point-nullable

Conversation

@bjarnef
Copy link
Contributor

@bjarnef bjarnef commented Jan 2, 2026

… before accessing left and top properties on focal point.

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #21273

Description

This ensure to check for focal point value, before accessing left and top properties and allows me to use nullable property when re-using component.

E.g.

#focalPoint: UmbImageCropperFocalPoint | null = { left: 0.5, top: 0.5 };

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:

#setFocalPointStyle(focalPoint: UmbImageCropperFocalPoint)

An option may also be to create a new component and deprecate the existing.

and maybe something moved to a utility/helper function: #21264

Copilot AI review requested due to automatic review settings January 2, 2026 12:39
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

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:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

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 🤖 🙂

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 focalPoint setter before accessing properties
  • Added null check in #initializeImage method to prevent errors during initialization
  • Added null check in #onFocalPointUpdated method before calling #isCentered

Comment on lines 40 to 44
this.#focalPoint = value;
this.#setFocalPointStyle(this.#focalPoint.left, this.#focalPoint.top);
if (this.#focalPoint) {
this.#setFocalPointStyle(this.#focalPoint.left, this.#focalPoint.top);
}
this.#onFocalPointUpdated();
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

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:

  1. Not assigning null values: Check if value is truthy before assignment
  2. 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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It always call #onFocalPointUpdated().

It just ensure #focalPoint is not null or undefined before accessing left and top properties.

@emmagarland
Copy link
Collaborator

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 umb-image-cropper-focus-setter.

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

@bjarnef bjarnef changed the title Image Cropper: Ensure to check for focal point before accessing left and top propert… Image Cropper: Ensure to check for focal point Jan 2, 2026
@bjarnef
Copy link
Contributor Author

bjarnef commented Feb 7, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not able to set focal point to null in umb-image-cropper-focus-setter

3 participants