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

[3.x]: Unpredictable Javascript error when entry auto-saves causes regular save to fail #12445

Closed
andersaloof opened this issue Dec 13, 2022 · 4 comments
Assignees

Comments

@andersaloof
Copy link

What happened?

Description

Sometimes when editing fields inside a matrix, auto-save triggers a warning that in turn makes saving impossible.

The triggered error is the following:
image

This error is triggered because nestedNames inside _filterFieldInputName() (https://github.com/craftcms/cms/blob/3.8/src/web/assets/cp/src/js/DraftEditor.js#L1289) returns null (I haven't been able to determine why this returns null).

The first time the error is triggered, it is caught by https://github.com/craftcms/cms/blob/3.8/src/web/assets/cp/src/js/DraftEditor.js#L890 and logged as a warning to the console, and the auto-save icon turns into an endless spinner.

When the first warning has occured, an error will be triggerd if the user then tries to save the entry.

Steps to reproduce

I've not been able to reproduce this error in a consistant manner, but it has been triggered sometimes following these steps.

  1. Create a new matrix field with 1 block containing 3 fields; one text field for title, one URL field for the url and one lightswitch.
  2. Create new entry type containing the new matrix field.
  3. Create a new entry of the new type and add some blocks to the new matrix and save the entry.
  4. After saving the entry, reload the page, and open developer tools.
  5. Edit one of the fields (either the title or the URL field), by either adding or removing content. Try to do this at various input sppeds as this has increased my chances of triggering the error.
  6. When autosave triggers, check for the console warning "Couldn't save draft" and the endless spinner icon. If the warning was not triggered, continue editing other fields in the entry, or reload the page again to start over. Eventually the error will be triggered.
  7. If warning has been triggered, try to save with CTRL + S and observe error in console.

Expected behavior

Update of content should work as expected.

Actual behavior

Javascript error is triggered causing auto-save and save to fail.

Craft CMS version

3.7.61

PHP version

7.4.3

Operating system and version

Linux 5.10.102.1-microsoft-standard-WSL2

Database type and version

MySQL 8.0.29

Image driver and version

GD 7.4.30

Installed plugins and versions

  • Amazon S3 1.3.0
  • Asset Rev 6.0.2
  • Cookies 1.1.15
  • CP Field Inspect 1.4.4
  • Craft Youtube 1.0.23
  • Dumper 2.0.0
  • Expanded Singles 1.2.0
  • Feed Me 4.5.3
  • Imageshop 1.0.21
  • Imgix 2.1.0
  • Navigation 1.4.31
  • Redactor 2.10.10
  • Retour 3.2.4
  • SEOMate 1.1.13
  • Super Table 2.7.3
  • Typed link field 1.0.25
@brandonkelly
Copy link
Member

Thanks for reporting that! We just released Craft 3.7.62 and 4.3.5 with updates to that logic to be a bit more defensive. Now if _filterFieldInputName() comes across an input name it wasn’t expecting, a warning will be logged out to the console.

If you don’t mind, it would be great if you could attempt to reproduce on 3.7.62 with your browser console open, and let me know what the warning message is, so we can fix the bug at the source.

@andersaloof
Copy link
Author

Testing on the 3.7.62 release I was not able to reproduce the endless spinner and subsequent error log, as the added throw/catch fixes this, instead I got the new console warnings:

I did notice that when the "Unexpected input name" warning appears, ANY content changes done, including the one that triggered that warning, will be lost when the document is saved. This wasn't an issue earlier, as saving would not work anymore when the error had occured, but now an editor would assume everything is OK, even when it's not.

image

A little breakdown of what steps I did the for the screenshot above:

  1. Loaded the relevant entry
  2. Did a content change to one field, this triggered the first network request for save-draft (see screenshots below)
  3. Did 3 further content changes to various input fields, all of them triggering a network request (see screenshots below) and also a a warnings for "Unexpected input name" (screenshot above)
  4. Saved the entry with ctrl + s
  5. Verified that the 3 content changes that was done was NOT saved (screenshots below)

Updated entry content before saving
image

Loaded entry content after save (only the first of the content changes was saved)
image

Screenshot of all network requests, payload and response preview

Request #1
image
image

Request #2
image
image

Request #3
image
image

Request #4
image
image

@brandonkelly
Copy link
Member

We were able to track down the underlying culprit, and just released Craft 3.7.63.1 and 4.3.6.1 with a fix 🎉

@andersaloof
Copy link
Author

Thanks for fixing this! 🥳

I can confirm that I'm not able to trigger this error and loose content anymore.

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

2 participants