Skip to content

Clearing an Image Cropper inside a block stores "null" and leaves the uploaded file behind #110

Closed

Description

@talhamalik4025

Hi Daniel,

A follow-up to #102 / #103 (thanks for the quick fix). With 4.0.5 on Umbraco 17.7.1, clearing an Image Cropper inside a content block has two side effects:

  1. The nested value is stored as the JSON string "null" instead of null. After that, Actions → Publish… on the page fails with a 500: Could not parse editor value to a ImageCropperValue object.
  2. The uploaded file is not deleted from the media file system.

Root cause

In ContentBlocksValueEditor.FromEditor, each nested value goes through:

prop.Value = valueEditor.FromEditor(propData, prop.Value);

prop.Value is the incoming editor value, not the stored one. The Image Cropper's FromEditor uses currentValue to find the existing file, so it sees no current file. It then skips the delete and falls through to its "unchanged" path, which serializes the null value to the string "null". That last part is also an Umbraco bug, reported in umbraco/Umbraco-CMS#24335.

Umbraco's own block editors pass the stored nested value (BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditor matches edited and current items by key and values by alias). So in core, the same clear deletes the file and stores null.

Steps to reproduce

  1. Create an element type with a Textstring and a non-mandatory Image Cropper, plus a content block definition for it.
  2. Add the block to a page, upload an image, and Save and publish.
  3. Clear file(s), then Save and publish. The stored nested value is {"editorAlias":"Umbraco.ImageCropper",...,"alias":"image","value":"null"}, and the media file still exists.
  4. Actions → Publish… returns a 500.

Suggested fix

Pass the stored nested value as currentValue, matching blocks by id and values by alias, the way core does. Happy to open a PR.

Environment

  • Umbraco 17.7.1
  • Perplex.ContentBlocks 4.0.5

Activity

  1. PerplexDaniel commented on Nov 11, 2026

    @PerplexDaniel
    Member

    @talhamalik4025

    I just merged your PR as it seemed to work, however just now I was testing it again and I get the exception Could not parse editor value to a ImageCropperValue object in other very similar scenarios. It seems the fix is not complete yet. Can you check if you see the same behavior on your end?

    After page reload:

    This basically follows your reproduction steps, but then reloads the page. After that it's no longer possible to publish the page (with the empty cropper).

    1. Pick an image in the image cropper property
    2. Save and publish the page
    3. Remove the picked image
    4. Save and publish the page
    5. Reload the page (F5)
    6. Save and publish the page -> error shows

    Without saving and publishing a picked image:

    1. Pick an image in the image cropper property
    2. Remove the picked image
    3. Save and publish the page -> error shows
  2. talhamalik4025 commented on Nov 11, 2026

    @talhamalik4025
    ContributorAuthor

    Hi Daniel, thanks for testing it further. I could reproduce both cases on my end with current master (Umbraco 17.7.1), and they also happen in exactly the same way with Umbraco's own Block List, so they come from Umbraco's Image Cropper rather than from Content Blocks. When the cropper is empty and there's no existing file (because the earlier save already deleted it, or the image was never saved), Umbraco stores the text "null", and the publish step then can't parse it. It's the issue I mentioned at the end of the PR description, umbraco/Umbraco-CMS#24335.

    The fix is in umbraco/Umbraco-CMS#24336, which has been approved and is labelled for 17.10.0. With that change applied, both of your scenarios publish fine, for Content Blocks and Block List, and pages that already have "null" stored can be published again without a re-save.

    In case you'd like to try it yourself, this is how I tested it:

    1. Build Umbraco.Infrastructure 17.7.1 with the fix

    git clone --filter=blob:none https://github.com/umbraco/Umbraco-CMS.git
    cd Umbraco-CMS
    git fetch origin pull/24336/head
    git checkout -b test-24336 release-17.7.1
    git cherry-pick 2d6a6277def6b7d3a1547bf1cb61691349702882 f944ae7bf9312d86185fd4a533206bb45e95c356
    dotnet build src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj -c Release
    

    (On Windows, git config core.longpaths true may be needed. The two commits apply cleanly on 17.7.1; on 17.7.2 and later the file has changed.)

    2. Swap it into a 17.7.1 test site running Content Blocks master. Stop the site, back up bin/.../Umbraco.Infrastructure.dll, copy in the one from src/Umbraco.Infrastructure/bin/Release/net10.0/, and start the site again. The assembly version is the same (17.7.1.0), so nothing else needs changing. Put the backup back afterwards.

    3. Run your two scenarios again, on a page with a content block that has a non-mandatory Image Cropper:

    • Pick an image, Save and publish, remove it, Save and publish, reload (F5), Save and publish. This now succeeds and the cropper is stored as null.
    • On a page where the image was never saved, pick an image, remove it, and Save and publish. This now succeeds as well.
    • Optional: on a page that already failed before the swap (it has "null" stored), use Actions → Publish… without changing anything. It now publishes.

    With the original DLL, the same steps on a Block List with the same element type fail in the same way.

    If you'd like something in Content Blocks before 17.10.0, I could open a small PR that stores null when a nested editor returns the text "null". Happy to go with whatever you prefer.

  3. PerplexDaniel commented on Nov 11, 2026

    @PerplexDaniel
    Member

    I see. No need for a follow-up PR if it will be fixed by Umbraco itself at some point; although it will take some time considering 17.10.0 is scheduled for January 21st, 2027, more than 2 months from now.

    Regardless, if an Image Cropper now behaves the same in this package as in e.g. Umbraco.BlockList then it's OK. It does make the Image Cropper basically unusable until 17.10.0 since you cannot publish an empty value in many cases.

    I will close this one again and will release 4.0.7 with this (partial) fix today.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions