spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Error 500: There was a problem getting the parent element. #893

Closed proimage closed 4 weeks ago

proimage commented 1 month ago

Bug Description

I've got a nice comprehensive Page Builder-type Neo field on a client's site, and occasionally when editing a newly-created entry, I get an error 500. In dev tools, the Network panel reveals the Fetch request and response:

fetch("https://my-client.ddev.site/index.php?p=control%2Factions%2Fneo%2Finput%2Frender-blocks&v=1717607186561", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "accept-language": "en-US,en;q=0.9,he;q=0.8",
    "cache-control": "no-cache",
    "content-type": "application/json",
    "pragma": "no-cache",
    "sec-ch-ua": "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-csrf-token": "[[REDACTED]]",
    "x-registered-asset-bundles": "24ceeb85,7ca18ed1,22e517a2,aee7f8dc,e505ffd6,6b4d7555,e5e48399,bb2f10a0,815d39ea,fc0bc163,1ccab40d,1e21896b,54698ee0,b842675b,1c3c9add,4b1fd285,d8d08e47,8f00ce04,8768f48b,cf3018d6,b5cd99e7,275565dd,51caf461,841995d6,eccadbb,e7edf1c5,d9e46393,8b11e0eb,b3bb8e00,15a36a51,fd5957f8,9ffc82a4",
    "x-registered-js-files": "",
    "x-requested-with": "XMLHttpRequest"
  },
  "referrer": "https://my-client.ddev.site/control/entries/pages/108001?draftId=5860&fresh=1",
  "referrerPolicy": "origin-when-cross-origin",
  "body": "{\"namespace\":\"fields[pageBuilder][blocks]\",\"fieldId\":5,\"siteId\":\"2\",\"blocks\":[{\"collapsed\":false,\"enabled\":true,\"level\":3,\"ownerId\":108001,\"type\":24,\"prevSiblingId\":null,\"parentId\":108005}]}",
  "method": "POST",
  "mode": "cors",
  "credentials": "include"
});
{
    "name": "Exception",
    "message": "There was a problem getting the parent element.",
    "code": 0,
    "error": "There was a problem getting the parent element.",
    "exception": "yii\\base\\Exception",
    "file": "/var/www/html/vendor/craftcms/cms/src/services/Structures.php",
    "line": 317,
    "trace": [
        {
            "file": "/var/www/html/vendor/spicyweb/craft-neo/src/controllers/Input.php",
            "line": 133,
            "function": "prepend",
            "class": "craft\\services\\Structures",
            "type": "->"
        },
        {
            "function": "actionRenderBlocks",
            "class": "benf\\neo\\controllers\\Input",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/InlineAction.php",
            "line": 57,
            "function": "call_user_func_array"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Controller.php",
            "line": 178,
            "function": "runWithParams",
            "class": "yii\\base\\InlineAction",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Module.php",
            "line": 552,
            "function": "runAction",
            "class": "yii\\base\\Controller",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 340,
            "function": "runAction",
            "class": "yii\\base\\Module",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 641,
            "function": "runAction",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 302,
            "function": "_processActionRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Application.php",
            "line": 384,
            "function": "handleRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/web/index.php",
            "line": 12,
            "function": "run",
            "class": "yii\\base\\Application",
            "type": "->"
        }
    ]
}

Steps to reproduce

  1. Be me?
  2. Seriously, it's something to do with the entry only being an unsaved Draft... if I first save the entry (despite the Neo field not being valid, as far as required fields being filled out), then the error does not occur.
  3. For what it's worth, the Neo field blocks I'm dealing with are as follows:

A "Columns" container, which starts out with a mandatory minimum of two "Column" child blocks. Each "Column" block has a number of child blocks (so 3rd-level deep now?), such as Heading, Text, Image, etc.

Here's a video of the error happening:

https://github.com/spicywebau/craft-neo/assets/1027523/c7e3220e-4c21-407b-a377-f86a0c544af1

And here's the continuation right where the previous video ended, showing the same action working correctly if I try to save the entry first—even when the entry has invalid fields and doesn't properly save.

https://github.com/spicywebau/craft-neo/assets/1027523/d5ab9b18-4474-4752-bfd4-1e207177672f

Expected behaviour

No response

Neo version

4.2.1

Craft CMS version

4.9.6

What is the affected Neo field's propagation method?

No response

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

ttempleton commented 4 weeks ago

Thanks for reporting that - fixed now in 4.2.2 and 5.0.2.

proimage commented 4 weeks ago

That did the trick, thanks for the crazy-fast fix!