verbb / vizy

A flexible visual editor for Craft CMS
Other
43 stars 8 forks source link

Re-ordering of blocks within Vizy not working as expected when using a Neo field #272

Closed AyupMike closed 6 months ago

AyupMike commented 6 months ago

Describe the bug

I'm experiencing some strange behaviour when re-ordering Vizy blocks in the editor, where the ordering of blocks doesn't get saved correctly when a block contains a Neo field.

It appears that once a block which contains a Neo field is moved to the first position, it then can't be moved to any other position and is "stuck", despite being able to change the order within the editor.

See video below for clarity:

https://github.com/verbb/vizy/assets/11300657/2cb377df-4c6f-4ba0-866a-567afcc3ff19

I am unsure if this is an issue with Vizy or Neo, so reporting here first.

Steps to reproduce

Setup

  1. Create a new Vizy field and add two new blocks to the field
  2. For one block, select an existing field which uses the Neo field type
  3. For the other block, select an existing field which does not use a Neo field type
  4. Create a new entry and add the Vizy block which contains the Neo field first, then add the Vizy block which does not contain the Neo field
  5. Save the entry - there should be two blocks within the Vizy editor now.

Replication of the bug

  1. Open the entry and re-order the blocks, so that the block with the Neo field is below the block without the Neo field
  2. Click save
  3. Re-open the same entry and observe that the order of the blocks has not been saved

Craft CMS version

4.5.11.1

Plugin version

2.1.13

Multi-site?

No

Additional context

Installed plugins

engram-design commented 6 months ago

I'll give this a test shortly, but wanted to check if this happens without a Neo field in the mix? Do two of your non-Neo field blocks retain their sorted order?

And JS errors in your web developer tools console?

AyupMike commented 6 months ago

Thanks Josh.

engram-design commented 6 months ago

Looks to be due to the code here for Neo.

I've been warned about Vizy doing a similar thing (see https://github.com/verbb/vizy/issues/224), but I believe this is because the Neo field is being re-initialized when the block is moved. This is somewhat unavoidable due to how Vue renders things, but it's producing buggy behaviour like you describe. You might also notice a duplicate "add" button for Neo.

I'll see what can be done about this, but basically Neo is forcing the entries data to be "reset" every time their field is rendered. I'm not sure why they do this, and it's probably our fault due to re-initializing the Neo field when it moves (but that's just how Tiptap/Vue works).

engram-design commented 6 months ago

Looks like another issue with Neo (see https://github.com/spicywebau/craft-neo/pull/818), but I've managed to fix what I can in Vizy.

Fixed for the next release. To get this early, run composer require verbb/vizy:"dev-craft-4 as 2.1.13"

engram-design commented 6 months ago

Fixed in 2.1.14