verbb / vizy

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

Vizy causes draft to be created without changing entry #114

Closed sjelfull closed 2 years ago

sjelfull commented 2 years ago

Description

It looks like a draft is created some times when landing or idling on the entry edit form - without any fields being edited.

The source of the draft is this line in DraftEditor.js and the checkForm() method.

if (force || data !== (this.lastSerializedValue || Craft.cp.$primaryForm.data('initialSerializedValue'))) {

Here Craft compares the last serialized value with the current serialized value of the form. I went digging into the shape of the data to see why it this comparison would trigger a save.

It looks to me like the raw data of the Vizy field is double encoded when comparing the data, meaning it will trigger the save always (?).

image

I'm not sure if this is on the Vizy or Craft side.

Steps to reproduce

  1. Add a Vizy field and content
  2. Try to idle or click around, to trigger the modified check.
  3. Notice that the current entry will get a draft (Edited status).

Additional info

dGilli commented 2 years ago

Same behavior as I observed in #34. Thank you for the digging it has not been "breaking" enough yet for us to investigate further but this helps.

engram-design commented 2 years ago

This seems to be related to nested Vizy fields, if you're able to confirm @dGilli ?

engram-design commented 2 years ago

No response, but I was able to replicate this with nested Vizy fields. The issue is mainly that there are technically changes from the front-end of the field to the saves value, but they're mostly superficial. Things like false being "" (and empty string), which is just coming from PHP to JS differences in casting variables. However, this change is enough to trigger Craft's warnings that something has changed.

To get around this, content changes are only started when focusing on the Vizy field (any field in the case of a nested setup).

Would you be able to try the latest fix? To get the fix early, change your verbb/vizy requirement in composer.json to:

"require": {
  "verbb/vizy": "dev-craft-3 as 1.0.15",
  "...": "..."
}

Then run composer update.

Mosnar commented 2 years ago

@engram-design Noticing this issue on Craft 4 as well! Removing the nested Vizy field seems to prevent it from happening.

engram-design commented 2 years ago

@Mosnar After some more digging after this, it might be unavoidable for the moment, just because of how the complexities are with nested Vizy fields. I know its a bit of a pain...

engram-design commented 2 years ago

Fixed in 1.0.16