decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.93k stars 3.04k forks source link

Falsy unsaved changes message #7267

Open yuri-g-taboola opened 2 months ago

yuri-g-taboola commented 2 months ago

Describe the bug The Unsaved changes message appears when you edit and revert the changes.

To Reproduce

  1. configure the CMS to work with gihub backend
  2. start the cms
  3. create a new post and save it
  4. make a change and revert it
  5. The Unsaved Changes doesn't change to Changes Saved

Expected behavior The Unsaved Changes should be replaced with Changes Saved

Screenshots

Applicable Versions:

CMS configuration https://github.com/decaporg/decap-cms/blob/main/dev-test/config.yml with gitthub backend

Additional context

It seems like the issue has been introduced by adding a new line in packages/decap-cms-core/src/backend.ts#entryToRaw method

    let content = format.toFile(entry.get('data').toJS(), fieldsOrder, fieldsComments);
    if (content.slice(-1) != '\n') {
      // add the EOL if it does not exist.
      content += '\n';
    }
    return content;
  }

in #7039 while solving #1382 The addition of the newline is conflicting with the trimming the end of content in markdown widget at https://github.com/decaporg/decap-cms/blob/main/packages/decap-cms-widget-markdown/src/serializers/index.js#L151

  /**
   * Return markdown with trailing whitespace removed.
   */
  return trimEnd(markdown);
martinjagodic commented 2 months ago

This is quite a dilemma. return trimEnd(markdown); appears to be there with a reason (introduced in #653), so we should be careful how we approach this.

LHSnow commented 2 months ago

Possibly related to #7142?

yuri-g-taboola commented 2 months ago

@martinjagodic I think the by the book solution will be to add the new line in #7093 only for json files.