Closed rbaud closed 4 years ago
I have just tested this with Neo 2.7.15 and Craft 3.4.22.1 on a fresh install with no other plugins. The issue exists under these conditions, and I have recorded the results of my test below.
First, I setup a Neo field with 4 levels of nesting. Each level can only contain the next level (e.g. L1 only can contain L2). I added this field to the "Homepage" Single Section.
I then created an index template that displays the following recursive code, based on the sample in the docs:
<ol>
{% nav block in entry.neoField.all() %}
<li>
{{ block.level }}
{% ifchildren %}
<ol>
{% children %}
</ol>
{% endifchildren %}
</li>
{% endnav %}
</ol>
Next, I added the following blocks and opened Live Preview.
-L1
--L2
---L3-A
----L4-X
---L3-B
----L4-Y
----L4-Z
On load, Live Preview displayed the following, as expected:
I then collapsed the L1 block, which yielded no effect, and then expanded it again (both times via double-clicking the block's top bar), which yielded this:
I closed Live Preview, which displayed the Neo structure as it was originally created:
And finally, I published the changes, which refreshed the page and displayed the new, broken structure/nesting:
I have experienced this to last week! Unfortunately it makes the plugin unusable for clients to work with. Let's hope this will be fixed soon.
I've been testing with Neo 2.7.16 and Craft 3.4.24, and have been unable to reproduce the issue -- can you update both and let me know if it still happens?
Ok, I've tried a couple of things:
First, I rolled up a 100% fresh install with an empty test database via composer create-project
and ./craft setup
, installed Neo 2.7.16 via the Plugin Store, setup a Home Entry and Neo field as I did above, and couldn't reproduce the issue.
Next, I tried upgrading from Neo 2.7.15 and Craft 3.4.23 using the following steps:
1) Removed all tables in the test DB, cleared the /vendor folder, deleted composer.lock, and ran composer install
and ./craft setup
after adjusting composer.json like so:
{
"require": {
"craftcms/cms": "3.4.23",
"spicyweb/craft-neo": "2.7.15",
"vlucas/phpdotenv": "^3.4.0"
},
"require-dev": {
"yiisoft/yii2-shell": "^2.0.3"
},
"autoload": {
"psr-4": {
"modules\\": "modules/"
}
},
"config": {
"sort-packages": true,
"optimize-autoloader": true,
"platform": {
"php": "7.0"
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
}
}
2) Installed Neo 2.7.15 via Settings > Plugins, setup the Home Entry and Neo field as above, and was able to reproduce the issue.
3) I then manually fixed the structure/nesting and resaved the Entry before upgrading to Craft 3.4.24 and Neo 2.7.16 via the web Updater.
4) I then went back to the Home Entry and, following the steps in Live Preview I detailed above, was able to reproduce the issue.
I took snapshots of the database all along the way. Please let me know where to send them if they'd be helpful.
Thanks for that, @rbaud, with that information I could reliably reproduce the issue for entry drafts in general, not just with live preview.
So, when Craft prepares to save the draft, part of Craft's preparation of the draft data to be POSTed involves replacing original element IDs with their duplicates' IDs. Because of the way Craft's element ID replacing needs to work, and the way Neo's form data is formatted, Neo block levels could get caught up in this process (Neo's form data is formatted in pretty much the same way as Matrix, but Matrix obviously doesn't have levels, or any other properties that could be affected by this, as far as I can see).
In my case, and I assume in your case as well, the homepage has element ID 2. So any blocks at level 3 (in the block form data, levels start from 0) were getting their level replaced with the element ID of the draft, which will almost certainly be far higher than 3.
Fortunately, adding a leading 0 to the level in the block form data is sufficient to avoid Craft's ID replacing and fix the issue, and this fix has been released in Neo 2.7.17.
Looks like the leading 0 fix works :) thanks Thomas!
@ttempleton, 2.7.17 fixes this issue for us across our sites. Thank you for addressing this!
Description
We are continuing to face an issue in Neo 2.7.15 and Craft 3.4.22.1 where making changes to an Entry with a Neo field (while in Live Preview) causes deeply-nested blocks to break out of their nesting. This is likely related to some or all of the following issues: #305, #323, #325, #356 & #364.
This issue makes editing via Live Preview, a critical tool in our workflow and part of the appeal of Craft itself, unpredictable and therefore unusable.
Here is what we have discovered:
This issue specifically affects changes made while using Live Preview. Making identical changes as described below OUTSIDE of Live Preview does not cause the issues we are describing.
This issue definitely affects Neo structures with 4 levels of nesting, but I have not exhaustively tested issues at lower/higher depths.
Steps for reproducing:
The first Live Preview refresh/reload/update will be fine. For us, the second throws an "Unable to find one of the following templates" error (this is because our Neo uses different templates at different levels), which is an indication that the nesting/structure has changed.
Close Live Preview, make note that as yet the nesting/structure in the control panel has not changed, and then Publish changes.
After the control panel has refreshed, you should notice that the structure is now broken like so:
Other information