"Unsaved changes" message incorrectly appears on layout builder

Created on 8 April 2021, almost 4 years ago
Updated 10 September 2024, 4 months ago

Problem/Motivation

After the initial load of a layout builder edit page (either per-entity overrides or the per-display defaults), any subsequent visits to the page will trigger a "You have unsaved changes" message, even when no changes have been made.

(this bug was introduced by #3144010: New pseudo-fields cannot be removed, InvalidArgumentException thrown โ†’ )

Steps to reproduce

Scenario 1:

  1. Enable layout builder for a content type.
  2. Click the "Manage layout" link.
  3. Refresh the page.

Scenario 2:

  1. Enable layout builder for a content type, and allow each content item to have its layout customized.
  2. Create a node.
  3. Click the "Layout" tab.
  4. Refresh the page.

Actual result: "You have unsaved changes" message appears.
Expected result: The message should not appear, since there are no unsaved changes.

Proposed resolution

Update LayoutTempstoreRepository so that it can explicitly keep track of whether any given SectionStorage in the repository has unsaved changes.

Remaining tasks

Review

User interface changes

The "You have unsaved changes" message will only appear when you have unsaved changes

API changes

LayoutTempstoreRepositoryInterface has a new public hasUnsavedChanges() function. Note that this interface has a one-to-one correspondence with the LayoutTempstoreRepository class, so we can add functions without breaking any BC rules.

In addition, LayoutTempstoreRepositoryInterface::set() has a new optional boolean argument called $has_unsaved_changes, which is used to track whether there are unsaved changes in the SectionStorage being set.

Data model changes

N/A

Release notes snippet

N/A

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Layout builderย  โ†’

Last updated 3 days ago

Created by

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria a.milkovsky UTC +2

    @AndyThornton could you please share your solution ("own version of that subscriber")?

  • First commit to issue fork.
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada bwaindwain

    Patch from #20 doesn't work with 10.3.0 because of "Add static caching to LayoutTempstoreRepository"

    https://www.drupal.org/project/drupal/issues/3445909 ๐Ÿ› Add static caching to LayoutTempstoreRepository Fixed

  • Update patch #20 to be compatible with Drupal 10.3

  • ๐Ÿ‡ช๐Ÿ‡ธSpain Carlos Romero

    Carlos Romero โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain Carlos Romero

    Applied changes from patch #37 to the corresponding branches and created mr

  • Status changed to Needs review 5 months ago
  • Pipeline finished with Failed
    5 months ago
    Total: 310s
    #265783
  • Pipeline finished with Failed
    5 months ago
    Total: 487s
    #265789
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    smustgrave โ†’ changed the visibility of the branch 11.x to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    smustgrave โ†’ changed the visibility of the branch 3207875-unsaved-changes-message to hidden.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR appears to have test failures.

  • Pipeline finished with Failed
    5 months ago
    Total: 203s
    #272495
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Binoli Lalani Gujarat

    binoli lalani โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    5 months ago
    Total: 720s
    #272501
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Binoli Lalani Gujarat

    Hello,

    I merged latest code changes from base branch into fork's branch and rerun the pipeline. Testcases are passed. Please review.

    Thank You!

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Left comments on MR.

  • Pipeline finished with Success
    4 months ago
    Total: 443s
    #291316
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Binoli Lalani Gujarat

    Hello,

    Thank you for reviewing the code. I pushed the code for comment on MR. Please review.

    Thank you!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bebalachandra

    Verified the issue on 11.x-dev.

    Steps to be followed to verify the issue.

    Scenario 1:

    1. Navigate to any content type by admin > structure > content types.
    2. Edit content type by clicking manage fields.
    3. Navigate to manage display tab.
    4.navigate to layout option section and enable "use layout builder"
    5.Save the changes and click "manage layout" button.
    6.Refresh the page and you will see "unsaved changes" message.

    Scenario 2:
    1. Navigate to any content type by admin > structure > content types.
    2. Edit content type by clicking manage fields.
    3. Navigate to manage display tab.
    4.navigate to layout option section and enable "use layout builder" and "Allow each content item to have its layout customized."
    5.Create a node and Click the "Layout" tab.
    6.Refresh the page and you will see "unsaved changes" message.

    Issue was there in both scenarios before applying the MR!9333.

    After The MR!9333 issue resolved for both scenarios. I suggest move this issue to RTBC

    Attached screenshots for reference.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback appears to be addressed

    Saving credit.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    I made two comment changes using the suggestions feature. Then phpstan was failing so I regenerated the baseline as well as properly wrapping one of the comments. There were no code changes.

    Therefor I will leave this at RTBC.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Kudos to whoever decided to put the sections inside a top-level key named 'section_storage' so we don't have any BC update path issues here.

    It looks like #27.1 has not been answered yet, back to NR for that

  • ๐Ÿ‡ต๐Ÿ‡ฐPakistan ugintl

    Patch from #37 worked for me. I was getting following error.

    Fatal error: Declaration of Drupal\layout_builder\LayoutTempstoreRepository::set(Drupal\layout_builder\SectionStorageInterface $section_storage) must be compatible with Drupal\layout_builder\LayoutTempstoreRepositoryInterface::set(Drupal\layout_builder\SectionStorageInterface $section_storage, $has_unsaved_changes = true) in C:\laragon\www\commerce\web\core\modules\layout_builder\src\LayoutTempstoreRepository.php on line 80

  • ๐Ÿ‡จ๐Ÿ‡ดColombia yasminOrj

    Hi, Iโ€™ve tried patch โ†’ #37 ๐Ÿ› "Unsaved changes" message incorrectly appears on layout builder Needs work , and it worked for me. Please find the attached screenshots as evidence.

    Thank you!

  • ๐Ÿ‡จ๐Ÿ‡ดColombia yasminOrj
  • ๐Ÿ‡จ๐Ÿ‡ดColombia yasminOrj
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Please don't put an issue back to RTBC without addressing the question/reason it was set the needs review

    We need to answer the question in 27.1

    Thanks

  • ๐Ÿ‡ต๐Ÿ‡ฐPakistan ugintl

    I would like to add one more thing regarding patch in #37 is that i had to apply it manually. I am using commerce kickstart V3. It has latest version of drupal 10.

    On looking closely, I noticed that some part of the patch was already applied. I guess that is why it was not applying automatically.

    Thought it may help.

  • ๐Ÿ‡ต๐Ÿ‡ฐPakistan ugintl

    I do not know what happened, I tried to clear all caches and now I am seeing the same error again suddenly.

    Fatal error: Declaration of Drupal\layout_builder\LayoutTempstoreRepository::set(Drupal\layout_builder\SectionStorageInterface $section_storage) must be compatible with Drupal\layout_builder\LayoutTempstoreRepositoryInterface::set(Drupal\layout_builder\SectionStorageInterface $section_storage, $has_unsaved_changes = true) in C:\laragon\www\commerce\web\core\modules\layout_builder\src\LayoutTempstoreRepository.php on line 80

    Isn't there any workaround?

  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

Production build 0.71.5 2024