Falsy unsaved changes message
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
**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:**
- Decap CMS version: 3.3.2
- Git provider: GitHub
- OS: Mac OS Sonoma 14.4
- Browser version Firefox 129
- Node.JS version: 20.12.2
**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);
```
Contributor guide
Research direction
Start with packages/decap-cms-core/src/backend.ts at entryToRaw and compare its trailing-newline handling with packages/decap-cms-widget-markdown/src/serializers/index.js, where trimEnd is used. Reproduce the GitHub-backend workflow from the issue, then verify that editing and reverting a saved post changes the status to Changes Saved without introducing a false unsaved state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend, content
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100