Skip to content

Blocks are returned in the wrong order to a backoffice view #20792

@sussexrick

Description

@sussexrick

Which Umbraco version are you using?

17.0.0-rc1

Bug summary

Suppose you have a page with a block list property (A). You add a block, which itself has a block list property (B). The block has a custom backoffice view which loops through the blocks in its property (B). Those blocks are not returned to the backoffice view in the correct order. They appear to be returned in the order the blocks were created.

Specifics

No response

Steps to reproduce

I've uploaded a repro at https://github.com/[sussexrick/umbraco-v17-block-order-repro](https://github.com/sussexrick/umbraco-v17-block-order-repro) based on the standard starter kit.

Backoffice login details are [email protected] with a password of testtesttest.

I've added an extra block list property to the 'Feature' document type to demonstrate the issue.

Go to the Products > Unicorn page and observe the Features section, which has a custom backoffice view. Its child blocks are in the wrong order. This does reflect the order the child blocks were created, before I moved one of them further down the block list using drag and drop.

one, four, two, three

Click on the edit item for that block and the child blocks are in the correct order.

one, two, three, four

The custom backoffice view is:

import { html, customElement, LitElement, property, repeat } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import type { UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view';

@customElement('demo-feature')
export class FeatureView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement {

    @property({ attribute: false })
    content?: any;
    constructor() {
        super();
    }

    override render() {
        return html`<h2>Feature block custom view</h2>
                ${this?.content?.childBlockList?.contentData ? repeat(this.content?.childBlockList?.contentData,
            (child: any) => child.key,
            (child: any) => {
                const label = child?.values.find((props: any) => props.alias == "label")?.value;

                return html`<p>${label}</p>`
            }
        ) : null}`;
    }
}

export default FeatureView;

Expected result / actual result

I would expect the blocks to be returned to in the correct order.

Failing that, I would expect them to have an order property that could be used to sort them.

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