Problem/Motivation

Follow-up from #2886686: Collapsable paragraphs always show "You have unsaved changes on this Paragraph item." message on collapsing..
All paragraphs that contain a WYSIWYG field always seem to be changed.

Proposed resolution

Investigate this and check what is changed in the WYSIWYG context

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 compare-values.png14.1 KBGinovski
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ginovski created an issue. See original summary.

johnchque’s picture

Haven't tested but what comes to my mind is that when a text field is empty and you open it to display its value in a WYSIWYG, the WYSIWYG adds an empty

tag, maybe that's why it is always "changing"?

Ginovski’s picture

Issue summary: View changes
FileSize
14.1 KB

Looks like the values are different on a text paragraph because of an '\r' escape character.
Maybe we could ignore this somehow?

miro_dietiker’s picture

Priority: Normal » Major

This smells like major inconsistency in core. I don't want to spent too much energy in workarounds.

If we can super quickly compare text after a newline normalization (simply compare after \r\n => \n) then fine.

But we need to identify why this ever is stored once with \n and then later provided with \r\n. This is wrong input data handling/conversion and we need to identify the related core issue or report this with high priority.

The diff project also contains some newline tricks to create line diffs that removes those conversion problems, but that's still a workaround and can even be confusing: why is my diff empty if it claims the value is different?

We're a content management system, we need stable content interaction and storage with the common variety of devices.

Berdir’s picture

Except this isn't happening in Drupal, which is loading/storing \r\n just fine.

it's the input string from the browser that somehow changes as far as I see. Not sure why and where and why it is \r\n first and then not anymore later.

miro_dietiker’s picture

Fun stuff i found:

When the value is read through JavaScript rather than being submitted directly from a form, browser behaviour differs. IE and Opera return strings with CRLFs in; Firefox and WebKit return LF. So any form that gets submitted with JavaScript/XMLHttpRequest help is likely to come in either form.

https://stackoverflow.com/a/6324648

Could it be that it is sometimes an ajax submission and sometimes a regular form submit?

miro_dietiker’s picture

Berdir’s picture

yes, that's exactly what happens then I guess. The wysiwyg is either closed by default and closed and then in those cases the value is submitted through ajax requests.

miro_dietiker’s picture

Note: I don't experience this issue with default content from Paragraphs Collection + Chrome on Linux.
But as soon as i add new content, save, edit again and collapse (ajax post), it is marked as changed.

Is it possible that default content stores text as \n and user added text stores as \r\n while then ajax collapse converts to \n again?
That, however, would mean that we need to normalize our default content to \r\n as well and sure process ajax submission.

Unsure if we should apply a workaround for ajax with Paragraphs or wait until core establishes consistency. I guess it will take a long time.

amateescu’s picture

Berdir’s picture

Was talking to @amateescu about change tracking problems like this, he pointed out #2856801: AJAX form submission is not encoding new lines in textarea values as CRLF pairs, but only as LF - resulting into a different values than browser submission as basically a duplicate of this, which now is basically a duplicate of #2899141: jQuery Form Plugin update to latest stable release as it is apparently fixed in the latest version of jquery form...

miro_dietiker’s picture

I tested the core patch of the jQuery Form update and i still see these paragraphs changed...
https://www.drupal.org/files/issues/2899141-jq-form-5.patch

SylvainM’s picture

Well, I just tested the patch form #2899141 with 8.x-1.2 version of paragraphs module and it solves the problem.

miro_dietiker’s picture

@SylvainM That would be cool. What Browser did you use?

SylvainM’s picture

Firefox 58.0 (Linux)

johnchque’s picture

Just tested in Chromium 63.0.3239.84 and the patch in #2899141: jQuery Form Plugin update to latest stable release works. There are no more changed icons after collapsing.

miro_dietiker’s picture

Just tested again in Firefox. It seems last time the patch was not properly applied. I used "curl LINK | git apply" and that sometimes silently does nothing at all...

So yeah, confirming that this does the job.

johnchque’s picture

johnchque’s picture

Status: Active » Postponed
miro_dietiker’s picture

Status: Postponed » Fixed

As the core issue was committed this problem is solved now.

miro_dietiker’s picture

Status: Fixed » Needs work

Except it isn't... This problem is back again.

Was this fix maybe reverted in jQuery with a more recent version?

Greg Boggs’s picture

I am also experiencing this issue. When I add a paragraph, then save the paragraph, Chrome warns: "Changes you made may not be saved" even though I am clicking save.