Skip to content

Error in processValueBlockData when removing item - contentData or settingsData may be undefined #19602

@martinthogersen

Description

@martinthogersen

Which Umbraco version are you using?

16.0.0

Bug summary

When attempting to remove an item from a block list, an error is thrown in the processValueBlockData method. This happens because value.contentData and value.settingsData can be undefined, which causes the Promise.all() mapping to fail.

The error seems to be related to migrated content from previous Umbraco-versions.

Update the code to safely handle undefined by defaulting to an empty array when contentData or settingsData are not present.

Current Code:

const contentData = await Promise.all(
  value.contentData?.map(async (entry) => ({
    ...entry,
    values: (await valuesCallback(entry.values)) ?? [],
  })),
);
const settingsData = await Promise.all(
  value.settingsData?.map(async (entry) => ({
    ...entry,
    values: (await valuesCallback(entry.values)) ?? [],
  })),
);

Suggested Change:

const contentData = await Promise.all(
  (value.contentData ?? []).map(async (entry) => ({
    ...entry,
    values: (await valuesCallback(entry.values)) ?? [],
  })),
);
const settingsData = await Promise.all(
  (value.settingsData ?? []).map(async (entry) => ({
    ...entry,
    values: (await valuesCallback(entry.values)) ?? [],
  })),
);

Video/screenshot demonstrating the error:

Image

Image

Specifics

No response

Steps to reproduce

See above.

Expected result / actual result

The removal should complete without error, regardless of whether contentData or settingsData exist.

An exception is thrown during the Promise.all() operation when either of the properties is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions