Message "You have unsaved changes on this Paragraph item." when no changes are made

Created on 28 May 2018, over 6 years ago
Updated 5 September 2024, 3 months ago

When clicking "Edit" on a paragraphs preview in the edit form and then clicking "Collapse", without making any changes, it shows: "You have unsaved changes on this Paragraph item."

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium mpp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States angelamnr

    The issue is still occurring with the new/experimental widget. So far, I've only noticed it with paragraphs that have an image upload field.

    To replicate:

    1. Build a stock Drupal site with the Standard installation profile. Also install paragraphs.
    2. Create a new paragraph type.
    3. Add an image upload field to your new paragraph type. Use all the default values when setting up your image field.
    4. Create a custom block type.
    5. Add a paragraph field to your new custom block type. Make sure to allow adding the new paragraph type you just created.
    6. Create a content block using the new custom block type that you just created. Add an image to the paragraph in your block. Fill out any other required fields. Save.
    7. Edit the content block that you just created. Collapse all of the paragraphs. Note that your paragraph has unsaved changes, which is impossible because you have not made any changes since saving.

    The isChanged() method in the Paragraphs entity class compares the latest revision of each field to the version that is currently present in the form when the accordion is collapsed. The latest revision of the ImageItem field contains height and width data that does not exist in the current version. The values in the ImageItem revision will look something like this:

    values => {
      target_id => 1,
      alt => "test image",
      title => "",
      width => "2000",
      height => "500",
    }

    The values in the current ImageItem will look like this even when there aren't any changes to it:

    values => {
      alt => "test image",
      display => 1,
      description => "",
      upload_button => {Drupal\Core\StringTranslation\TranslatableMarkup}
      remove_button => {Drupal\Core\StringTranslation\TranslatableMarkup}
      upload => "",
      title => "",
      target_id => 1,
    }

    In FieldItemList::equals, this is filtered down to this for the ImageItem revision before determining whether or not to show the Unsaved Changes icon:

    values => {
      target_id => 1,
      alt => "test image",
      title => "",
      width => "2000",
      height => "500",
    }

    And this for the current ImageItem:

    values => {
      alt => "test image",
      title => "",
      target_id => 1,
    }

    Because there's no height or width set on the current ImageItem and it isn't possible to set these values by default, any paragraph with an image upload field will always show as having unsaved changes. I'm not really sure what should be done to fix this, because some people might have the image upload field set up to expose the width and height for users to change, in which case this difference becomes important. If you don't allow users to change the width and height in the field, however, these values should be ignored somehow.

  • πŸ‡¬πŸ‡§United Kingdom JennyDumitrescu

    I can confirm that this is still an issue on the newer (marked 'stable' version) of Paragraphs widget. We have had this issue raised where a user did the same approach as above (added a paragraph that contained an image field, added the image, and on collapse of the paragraph to continue their work, got the alert that they had unsaved content). This produced confusion in our case to the user due to the fact the only way to then save is to save to avoid the message, is to save the whole page rather than being able to save a paragraph alone to remove the error.

Production build 0.71.5 2024