Sitecore / ASP.NET-Core-SDK

The official open source ASP.NET Core SDK for Sitecore DXP and XM Cloud.
https://sitecore.github.io/ASP.NET-Core-SDK/
Apache License 2.0
7 stars 1 forks source link

Support for Placeholder Fields property to be an Array #8

Closed robearlam closed 1 week ago

robearlam commented 1 month ago

What happened?

The OOTB Navigation component in XM-Cloud uses a custom Content Resolver to adjust the returned JSON and make the route.placeholders.placeholder[0].fields property into an Array. This SDK is configured to only handle the field property as an Object.

Navigation Item RCR Field contents: image

Target RCR type: image

This causes the Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization.Converter.FieldParser to throw a JsonException as its expecting and object and not an array:

image

Reproduction Steps

  1. Create a site in XM Cloud
  2. Point your ASP.NET Core Head application to the site
  3. Drag the Navigation component to the page

Actual Behavior

Expected Behavior

Relevant log output

{
  "sitecore": {
    "context": {
      "pageEditing": false,
      "site": {
        "name": "aspnet-core-starter"
      },
      "pageState": "normal",
      "editMode": "chromes",
      "language": "en",
      "itemPath": "/"
    },
    "route": {
      "name": "Home",
      "displayName": "Home",
      "fields": {
        "Title": {
          "value": "aspnet-core-starter-123"
        },
        "Content": {
          "value": "<p>Page COntent COntent!</p>"
        },
        "NavigationClass": null,
        "NavigationFilter": [

        ],
        "NavigationTitle": {
          "value": "aspnet-core-starter"
        },
        "Page Design": null,
        "SxaTags": [

        ]
      },
      "databaseName": "master",
      "deviceId": "fe5d7fdf-89c0-4d99-9aa3-b5fbd009c9f3",
      "itemId": "27fa2701-5a1a-43b8-bb6b-c86baae7961d",
      "itemLanguage": "en",
      "itemVersion": 1,
      "layoutId": "96e5f4ba-a2cf-4a4c-a4e7-64da88226362",
      "templateId": "195a62a9-2c45-4f38-b9f7-6aff652bdadf",
      "templateName": "Page",
      "placeholders": {
        "headless-header": [
          {
            "uid": "e92cda14-efca-4abd-8e0f-cff8dfd74066",
            "componentName": "Navigation",
            "dataSource": "",
            "params": {
              "GridParameters": "col-12",
              "FieldNames": "Default",
              "LevelFrom": "{1BB88840-5FB3-4353-AD8D-81136F6FF75A}",
              "LevelTo": "{A59325BB-5A27-46F9-8110-9D499715F3BE}"
            },
            "fields": [
              {
                "Id": "b0dade99-22d2-4853-aa53-b4e1b2bdd680",
                "Styles": [
                  "level1",
                  "item0",
                  "odd",
                  "first"
                ],
                "Href": "/Page2",
                "Querystring": "",
                "NavigationTitle": {
                  "value": "Page2",
                  "editable": "Page2"
                }
              },
              {
                "Id": "cead36eb-cc39-401a-8ea7-37252d1a34f6",
                "Styles": [
                  "level1",
                  "item1",
                  "even",
                  "last"
                ],
                "Href": "/Page3",
                "Querystring": "",
                "NavigationTitle": {
                  "value": "Page3",
                  "editable": "Page3"
                }
              }
            ]
          }
        ],
        "headless-main": [

        ],
        "headless-footer": [

        ]
      }
    }
  }
}

Code of Conduct

jbreuer commented 3 weeks ago

I encountered a similar issue with handling empty strings and have submitted a pull request to address it. You can review the changes here: https://github.com/Sitecore/ASP.NET-Core-SDK/pull/12

sc-ivanlieckens commented 3 weeks ago

I have commented on #12 and I believe these 2 issues are indeed very similar and require a strategic architectural decision on the support of Custom Content Resolvers.