Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.2 RC] Unable to save content with a block editor containing an RTE when using block-level variations #18174

Open
arknu opened this issue Jan 30, 2025 · 2 comments

Comments

@arknu
Copy link
Contributor

arknu commented Jan 30, 2025

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

15.2.0 RC

Bug summary

When trying to save content, I get the following exception (was fine on 15.1):

System.NullReferenceException: The property BlockEditorValues must be initialized at value editor construction
   at Umbraco.Cms.Core.PropertyEditors.BlockValuePropertyValueEditorBase`2.get_BlockEditorValues()
   at Umbraco.Cms.Core.PropertyEditors.BlockValuePropertyValueEditorBase`2.MergeVariantInvariantPropertyValue(Object sourceValue, Object targetValue, Boolean canUpdateInvariantData, HashSet`1 allowedCultures)
   at Umbraco.Cms.Core.PropertyEditors.RichTextPropertyEditor.MergeVariantInvariantPropertyValue(Object sourceValue, Object targetValue, Boolean canUpdateInvariantData, HashSet`1 allowedCultures)
   at Umbraco.Cms.Core.PropertyEditors.BlockValuePropertyValueEditorBase`2.CleanupVariantValues(List`1 sourceBlockItems, List`1 targetBlockItems, Boolean canUpdateInvariantData, HashSet`1 allowedCultures)
   at Umbraco.Cms.Core.PropertyEditors.BlockValuePropertyValueEditorBase`2.MergeVariantInvariantPropertyValue(Object sourceValue, Object targetValue, Boolean canUpdateInvariantData, HashSet`1 allowedCultures)
   at Umbraco.Cms.Core.PropertyEditors.BlockListPropertyEditor.MergeVariantInvariantPropertyValue(Object sourceValue, Object targetValue, Boolean canUpdateInvariantData, HashSet`1 allowedCultures)
   at Umbraco.Cms.Core.Services.ContentEditingService.EnsureOnlyAllowedFieldsAreUpdated(IContent contentWithPotentialUnallowedChanges, Guid userKey)
   at Umbraco.Cms.Core.Services.ContentEditingService.UpdateAsync(Guid key, ContentUpdateModel updateModel, Guid userKey)
   at Umbraco.Cms.Api.Management.Controllers.Document.UpdateDocumentController.<>c__DisplayClass4_0.<<Update>b__0>d.MoveNext()

This seems to be happening because the RichTextPropertyValueEditor constructor is not initializing the BlockValues property here:

public RichTextPropertyValueEditor(
DataEditorAttribute attribute,
PropertyEditorCollection propertyEditors,
IDataTypeConfigurationCache dataTypeReadCache,
ILogger<RichTextPropertyValueEditor> logger,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IShortStringHelper shortStringHelper,
HtmlImageSourceParser imageSourceParser,
HtmlLocalLinkParser localLinkParser,
RichTextEditorPastedImages pastedImages,
IJsonSerializer jsonSerializer,
IHtmlSanitizer htmlSanitizer,
IBlockEditorElementTypeCache elementTypeCache,
IPropertyValidationService propertyValidationService,
DataValueReferenceFactoryCollection dataValueReferenceFactoryCollection,
IRichTextRequiredValidator richTextRequiredValidator,
BlockEditorVarianceHandler blockEditorVarianceHandler,
ILanguageService languageService,
IIOHelper ioHelper)
: base(propertyEditors, dataTypeReadCache, shortStringHelper, jsonSerializer, dataValueReferenceFactoryCollection, blockEditorVarianceHandler, languageService, ioHelper, attribute)
{
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_imageSourceParser = imageSourceParser;
_localLinkParser = localLinkParser;
_pastedImages = pastedImages;
_htmlSanitizer = htmlSanitizer;
_elementTypeCache = elementTypeCache;
_richTextRequiredValidator = richTextRequiredValidator;
_jsonSerializer = jsonSerializer;
_logger = logger;
Validators.Add(new RichTextEditorBlockValidator(propertyValidationService, CreateBlockEditorValues(), elementTypeCache, jsonSerializer, logger));
}

Adding this line fixes this issue:

BlockEditorValues = new BlockEditorValues<RichTextBlockValue, RichTextBlockLayoutItem>(new RichTextEditorBlockDataConverter(jsonSerializer), elementTypeCache, logger);

However, this now exposes further issues. The logic for meging blocks seems to be broken, selecting the first element with just a matching culture:

BlockPropertyValue? sourceBlockPropertyValue =
sourceBlockItem?.Values.FirstOrDefault(v => v.Culture == targetBlockPropertyValue.Culture);

In my testing, this always just selects the first block, which surely cannot be right. I tried selecting with the alias as well:

BlockPropertyValue? sourceBlockPropertyValue =
    sourceBlockItem?.Values.FirstOrDefault(v => v.Alias == targetBlockPropertyValue.Alias && v.Culture == targetBlockPropertyValue.Culture);

In my limited testing, this seems to select the right block, though I am unsure if this is always correct

This fix is still not enough, as now the RTE breaks trying to read the blocks JSON. I haven't dug too much into this, but the cause seems to be that it is trying to read the whole JSON value (including the markup property, instead of only reading the blocks property.

In short, v15.2 seems to be pretty badly broken when it comes to the block list editor, particularly involving the RTE. You cannot save any content at all.

Specifics

No response

Steps to reproduce

Create a doc type (language variant) with a block grid/list editor that is invariant. Make sure it has an item with an RTE. Watch things break.

If the property has language variants turned on, nothing happens. So this seems to be related to the new blocks variants feature in v15.

Expected result / actual result

I would expect saving content to work normally, no matter what the configuration is

@arknu arknu added the type/bug label Jan 30, 2025
Copy link

Hi there @arknu!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@arknu arknu changed the title [15.2 RC] Unable to save content with a block editor containing an RTE [15.2 RC] Unable to save content with a block editor containing an RTE when using block-level variations Jan 30, 2025
@NguyenThuyLan
Copy link
Contributor

Thank you @arknu , I was able to reproduce it on v15.3.0-rc.
BlockEditorValues was not initialized
Image

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

No branches or pull requests

2 participants