Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
181221 opened this issue Sep 5, 2024 · 2 comments
Open
Labels
area: extensions/widgets/relation pinned type: bug code to address defects in shipped code

Comments

@181221
Copy link

181221 commented Sep 5, 2024

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"

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="robots" content="noindex" />
    <title>Content Manager</title>
  </head>
  <body>
    <!-- Include the script that builds the page and powers Decap CMS -->
    <script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
    <script>
      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");
    </script>
  </body>
</html>

@181221 181221 added the type: bug code to address defects in shipped code label Sep 5, 2024
@LHSnow
Copy link

LHSnow commented Sep 22, 2024

This also affects gitlab, which creates empty merge requests if the user actually saves the non-changes. #7142

@alexisreina
Copy link

I can confirm, this is also happening to me in a project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: extensions/widgets/relation pinned type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

4 participants