decaporg / decaporg/decap-cms

i18n Relation Widget Causing "Unsaved Changes" Error in Posts Collection

Open
#7,276 2 comments 2 reactions 0 assignees View on GitHub
area: extensions/widgets/relation pinned type: bug
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Describe the bug**
I'm experiencing an issue with the i18n setup for relation widgets in Decap CMS. When using the relation widget with i18n across multiple locales, the CMS consistently shows a **"You have unsaved changes"** warning whenever I navigate away from a post, even if no changes were made.

**To Reproduce**

Steps to reproduce the behavior

1. Set up Decap CMS with the provided `config.yml` using i18n with multiple locales.
2. Create an author and a post, assigning the author using the relation widget.
3. Try navigating away from the page without making changes. The CMS shows the "unsaved changes" warning, despite no changes being made.

**Expected behavior**
The CMS should not display an 'unsaved changes' warning when no actual changes have been made.

**Applicable Versions:**

- Decap CMS version: 3.3.3
- Azure, local, Github
- OS: Windows 11, Linux and Mac
- Browser version chrome 128.0.6613.115, firefox 130.0
- Node.JS version: v20.12.2

**CMS configuration**

```
# Quick example to reproduce
local_backend: true
backend:
name: git-gateway
branch: main
repo: "username/repo"
media_folder: /public/media
public_folder: /media
i18n:
structure: multiple_files
locales: [no, en]
default_locale: no
collections:
- name: "authors"
label: "Authors"
folder: "content/authors"
create: true
slug: "{{fields.uuid}}"
i18n: { structure: single_file, locales: [no, en], default_locale: no }
fields:
- label: "First Name"
name: "first_name"
widget: "string"
i18n: true
- label: "UUID"
name: "uuid"
widget: "hidden"
i18n: "duplicate"

- name: "posts"
label: "Posts"
folder: "content/posts"
create: true
slug: "{{fields.uuid}}"
i18n: { structure: single_file, locales: [no, en], default_locale: no }
fields:
- label: "Title"
name: "title"
widget: "string"
i18n: true
- label: "Author"
name: "author"
widget: "relation"
collection: "authors"
search_fields: ["first_name"]
value_field: "uuid"
display_fields: ["first_name"]
i18n: "duplicate"

```

```





Content Manager





CMS.registerEventListener({
name: "preSave",
handler: ({ entry }) => {
const data = entry.toJS().data;
let uuid = data.uuid || crypto.randomUUID();
return entry.withMutations((m) => {
// Update the default locale UUID
m.setIn(["data", "uuid"], uuid);
// Iterate over remaining locales and update the UUID in each nested map
m.get("i18n").forEach((value, key) => {
m.setIn(["i18n", key, "data", "uuid"], uuid);
});
});
},
});
console.log("custom preSave-hook loaded");

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.