Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Craft 5] If I miss a required field while saving, all neo blocks get flattened #907

Closed
ayush000 opened this issue Jul 2, 2024 · 13 comments

Comments

@ayush000
Copy link

ayush000 commented Jul 2, 2024

Bug Description

While working on a new entry in Craft CMS, let's say I forget inputting a required field (such as entry title). When I try to save the entry, I get a validation error. All's good, but now when I fix the validation error and try to save the entry again, something weird happens. All the neo blocks that I had added before get flattened and they lose their content. I tried it with a couple of neo fields with different hierarchy, this issue is reproducible with all of them.

Steps to reproduce

  1. Set autoSaveDrafts to false in CMS config (not sure if it's the same with autosaveDraft turned on)
  2. Create a new entry
  3. Add a nested neo block
  4. Don't put in a required field
  5. Save it. Craft will give a validation error
  6. Fix that validation error and save it again
  7. Neo blocks will get flattened and sometimes even have their content deleted
    Screen Recording 2024-07-02 at 14.17.49.webm

Expected behaviour

Neo blocks should maintain their original hierarchy and should preserve content after save

Neo version

5.0.5

Craft CMS version

5.2.0

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
Copy link
Contributor

I'm able to reproduce the content loss when doing this with Matrix blocks as well, so I'm guessing there is some common issue in Craft itself. I'm unsure if the Neo block structure loss is related to that or a separate bug.

(For the record - yes, it is specific to autosaveDrafts being false)

@ttempleton ttempleton added bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed and removed bug report status: new labels Jul 3, 2024
@ttempleton
Copy link
Contributor

I'm going to close this issue for now, due to being presumed to have an external cause. Happy to reopen if the content loss issue with Matrix fields is fixed in Craft and that does not also fully fix the Neo issues.

@ttempleton ttempleton closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
@ttempleton ttempleton added bug report status: external cause A bug report that was caused by behaviour external to this project and removed bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed labels Jul 9, 2024
@AleksanderKampus1
Copy link

AleksanderKampus1 commented Jul 19, 2024

@ttempleton can you try this again with Matrix blocks? I decided to create a bug on Craft side today. However when testing it myself I found that Matrix blocks don't get flattened. The may have fixed it on Craft side with the latest version 5.2.8 but it's still broken with Neo. Also if it keeps happening with matrix blocks, can you send us a screen recording so Craft team has more to work from?

@ttempleton
Copy link
Contributor

It looks like the field content loss has been resolved for both Matrix and Neo field types, but the Neo block structure loss is still happening. So that part now looks very likely to be a Neo bug, separate from the field content loss bug. Reopening the issue.

@ttempleton ttempleton reopened this Jul 19, 2024
@ttempleton ttempleton added bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed and removed bug report status: external cause A bug report that was caused by behaviour external to this project labels Jul 19, 2024
@ayush000 ayush000 changed the title [Craft 5] If I miss a required field while saving, all neo blocks get flattened and lose content [Craft 5] If I miss a required field while saving, all neo blocks get flattened Jul 24, 2024
@ttempleton
Copy link
Contributor

Sorry, looks like that might be a Craft bug after all.

It turns out that some non-field data belonging to blocks isn't being picked up, such as block level and whether the block is enabled, when the owner entry is saved. It is also happening with non-field data belonging to Matrix entries when they're set to display as blocks. This can be observed with Matrix blocks by setting blocks as disabled before the initial save that fails due to validation errors. After the second successful save attempt, the Matrix blocks will be enabled.

I've opened a Craft issue for this (craftcms/cms#15418) and will reopen this issue if a resolution to the Craft issue does not also resolve this one.

@ttempleton ttempleton closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2024
@ttempleton ttempleton added bug report status: external cause A bug report that was caused by behaviour external to this project and removed bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed labels Jul 26, 2024
@AleksanderKampus1
Copy link

OK thanks 👍 .

@ayush000
Copy link
Author

Hey @ttempleton ! The issue was marked as fixed on Craft side but the issue of flattening of Neo blocks is still there. I tried out craftcms/cms:5.3.x-dev and spicyweb/craft-neo:5.1.1

@ttempleton
Copy link
Contributor

Yeah, I will likely need to apply some form of the fix to Neo separately.

@ttempleton ttempleton reopened this Jul 29, 2024
@ttempleton ttempleton added bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed and removed bug report status: external cause A bug report that was caused by behaviour external to this project labels Jul 29, 2024
@ttempleton ttempleton added this to the 5.2.0 milestone Jul 29, 2024
ttempleton added a commit that referenced this issue Aug 1, 2024
@ttempleton
Copy link
Contributor

I've just released Neo 5.2.0-beta.1 including a fix for this (requires at least Craft 5.3.0-beta.1).

@ttempleton ttempleton added bug report status: fixed and removed bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed labels Aug 1, 2024
@AleksanderKampus1
Copy link

@ttempleton now that Craft is officially out in 5.3.1, can we also do a stable 5.2.0 release? Also tried it out and it works 👍, the Neo structure stays the same, if there is a validation errors.

@ttempleton
Copy link
Contributor

Thanks for that feedback @AleksanderKampus1! I'd like to resolve issue #917 first, so I'll release 5.2.0 on Monday. I'll update here after that's done.

@ttempleton
Copy link
Contributor

Neo 5.2.0 has now been released.

@AleksanderKampus1
Copy link

@ttempleton can you also take a look at the new bug? This seems to be related to this. Sorry if you are already looking into it. #929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants