Problem/Motivation

Summary of the issue
Ajax responses when there are multiple paragraph fields are not always updating the correct field

Original background
We have a weird issue where one paragraph field content gets replaced by another field when editing content.

Our content model has a hero element, which is a paragraph with a couple fields. We also have a "modular content" paragraph field, where we build the rest of the page. There we can create multiple paragraphs from a couple different paragraph types (image, text, whatever). Overall this works fine for us.

Recently however we've had a weird issue with this. When editing the main "modular content" paragraphs, the hero paragraph replaces the whole other paragraph. So let's say we have five paragraphs in the modular content, we then add another one, drag it to its proper place and fill it with content. So very basic content editing, but then suddenly all (now) six paragraphs disappear and get replaced by the hero element from earlier on the page. The hero element is not even a legal selection for the content paragraph and should never appear there.

Any ideas what might cause this? Seems very strange to me. Nothing weird in browser, drupal or nginx logs. This seems to happen more commonly when the site is under heavy (but normal) load, but is somehow connected to drupal paragraph configuration, since this only happens on a single node type, even though a similar structure is used on other types too.

Steps to reproduce

  1. Create 2 paragraph reference fields with autocollapse for example
  2. Create 2 paragraph instances in each
  3. Enable dev tools and go responsive mode, enabling throttle to low tier mobile*
  4. Click edit on paragraph 2.2
  5. Click edit on paragraph 2.1 then immediately collapse on paragraph 2.2
  6. Paragraphs 1.* get affected when none of those buttons were pressed

* This just makes it easier to reproduce, but bigger complex paragraphs with lots of content have the same effect

Screencast showing the issue described above

Proposed resolution

Perhaps disabling interaction on collapse/edit until ajax is completed like Core did for Ajax submit? https://git.drupalcode.org/project/drupal/-/merge_requests/5184/diffs from #3397594: Race condition on AJAX change event and form submission

Remaining tasks

  1. Maintainer opinion on plan
  2. Carry out the work

User interface changes

TBD

API changes

N/A

Data model changes

N/A

Comments

teemuaro created an issue. See original summary.

teemuaro’s picture

In this problematic content type we've used field groups to group fields to help content editor experience. Is this something that might cause problems?

scott_euser’s picture

Title: Paragraphs jumping to different elements » Paragraphs ajax interactions do not always update the correct field if interacted with while ajax is still carrying out a previous task
Issue summary: View changes
scott_euser’s picture

Issue summary: View changes
StatusFileSize
new2.49 MB
scott_euser’s picture

Issue summary: View changes
jeroen dost’s picture

We seem to have the sam issue, though we do not know for sure. Not all changes are saved, apparently only the last change. There is no dblog entry, no php error, nothing in console, so there is no way to find out what is really going wrong.

Does anyone have an idea where to look? Or if this is the same issue, or maybe there is a related issue?

bdunphy’s picture

This issue is related to one reported in 2020. The issue is that there is a race condition and I've been able to replicate this with rapid fire clicks. The resolution given for Drupal core was narrow in scope and there is an open issue regarding the race condition with a hunt for a more generic solution. https://www.drupal.org/project/drupal/issues/3400320.

I've been working and testing some code with the hopes of presenting for review.

bdunphy’s picture

Status: Active » Closed (duplicate)

This is a duplicate of #3143256 as noted in the related issues. Same root cause (parallel AJAX widget rebuilds), same symptom (field content
replaced/wiped), same fix approach. Merge request submitted on #3143256.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.