Overview

We recently faced an issue where we couldn't use nested components in an XB page that has multiple regions.

Steps to reproduce

  1. Have multiple regions set up.
  2. Place two components one with a prop and another one with a slot in a component with slots.
  3. Place another component with a prop inside the nested component.
  4. Fill the value of prop in first component. This one works.
  5. Fill the value of prop in 2nd component.(The one in nested component).
  6. See that the network call for this last one fails with 5xx error.

Expected result

Nested components should work well.

This fails at ApiLayoutController::267 because $regionForComponentId is null and it's not able to get the region even though content region exists under which this component is placed.

Proposed resolution

User interface changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

amangrover90 created an issue. See original summary.

amangrover90’s picture

Issue summary: View changes
amangrover90’s picture

wim leers’s picture

Assigned: Unassigned » amangrover90
Status: Active » Postponed (maintainer needs more info)

This fails at ApiLayoutController::267 because $regionForComponentId is null and it's not able to get the region even though content region exists under which this component is placed.

That's

      if ($regionForComponentId !== XbPageVariant::MAIN_CONTENT_REGION) {
        if (!$page_regions[$regionForComponentId]->access('edit')) {
          throw new AccessDeniedHttpException(sprintf('Access denied for region %s', $regionForComponentId));
        }

So … this would mean that $page_regions[$regionForComponentId] resolves to NULL, meaning that $regionForComponentId is NOT one of the existing PageRegion config entities?! 😱

Can you please apply this patch to get a more precise error message?

$ git diff
diff --git a/src/Controller/ApiLayoutController.php b/src/Controller/ApiLayoutController.php
index f34ce46cc..570082478 100644
--- a/src/Controller/ApiLayoutController.php
+++ b/src/Controller/ApiLayoutController.php
@@ -264,6 +264,9 @@ final class ApiLayoutController {
     if (!empty($page_regions)) {
       $regionForComponentId = $this->getRegionForComponentInstance($data['layout'], $componentInstanceUuid);
       if ($regionForComponentId !== XbPageVariant::MAIN_CONTENT_REGION) {
+        if (!array_key_exists($regionForComponentId, $page_regions)) {
+          throw new \LogicException(sprintf("Component instance %s is in a region (%s) for which no PageRegion config entity exists. Existing PageRegions: %s.", $componentInstanceUuid, $regionForComponentId, implode(', ', array_keys($page_regions))));
+        }
         if (!$page_regions[$regionForComponentId]->access('edit')) {
           throw new AccessDeniedHttpException(sprintf('Access denied for region %s', $regionForComponentId));
         }
wim leers’s picture

Issue tags: +Needs tests

Oh wait:

because $regionForComponentId is null

If true, this would most likely be a bug in \Drupal\experience_builder\Controller\ApiLayoutController::getRegionForComponentInstance()?

What would be really helpful is you sharing the full request body that triggered that 500 response 🙏 That would allow us to easily write a failing test case to ApiLayoutControllerPatchTest.

mglaman’s picture

I walked through the xdebug of this. The component was in the `content` region. I think the bug is in the `slots` code

          // Maybe it's not a component, but a slot inside a component.
          foreach ($componentData['slots'] as $slotData) {
            foreach ($slotData['components'] as $slotComponentData) {
              if ($slotComponentData['uuid'] === $componentInstanceUuid) {
                return TRUE;
              }
            }
          }

It was nested 2 or 3 levels deep.

wim leers’s picture

Component: … to be triaged » Internal HTTP API
Status: Postponed (maintainer needs more info) » Active
Issue tags: +beta target
wim leers’s picture

amangrover90’s picture

StatusFileSize
new1.21 KB

Uploaded the payload for which there was 500 error. It fails trying to calculate the regionForComponentId.

wim leers’s picture

Issue tags: +blocker

This blocks #3535078, see #3535078-9: Bug in `generateComponentTreeKeys()` causes XB config entity containing a component tree to loses some component instances upon creation. More likely: that is a duplicate of this issue: different symptom, same root cause. Still, let's double-check there after this lands 👍

isholgueras made their first commit to this issue’s fork.

wim leers’s picture

Assigned: thoward216 » isholgueras

isholgueras’s picture

Assigned: isholgueras » wim leers
Status: Active » Needs review

This is ready with all tests green. Let me know if we can create a follow-up ticket for tests or if we should include here the tests

wim leers’s picture

Status: Needs review » Needs work

Yes, we do, hence the Needs tests tag 😇

See #9 for a sample payload, but it sounds like you were able to reproduce this yourself already :)

wim leers’s picture

Assigned: wim leers » isholgueras

larowlan made their first commit to this issue’s fork.

larowlan’s picture

Status: Needs work » Needs review
Issue tags: +beta blocker

I think this should be a beta blocker, its pretty easy to get this error.

Pushed a failing test and rebased off 0.x

If you checkout 185d8c32 and run ApiLayoutControllerPatchTest it fails.

We already had most of the required structure in XbTestSetup, just needed to do some fernangling to mirror the nesting.

Adding the tag, asking for forgiveness not permission etc

wim leers’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

2 questions on the MR — one about a remaining @todo, one about something I don't understand.

wim leers’s picture

Assigned: isholgueras » Unassigned
Status: Needs work » Reviewed & tested by the community
isholgueras’s picture

… but let's land !1204 first, that is much harder to reroll.

Sure! feel free to throw it back to me if we need a reroll here.

penyaskito’s picture

wim leers’s picture

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.