decaporg / decap-cms

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

Extra characters getting added to body of md files (ZERO WIDTH NO-BREAK SPACE) #6602

Closed snacksthecat closed 10 months ago

snacksthecat commented 1 year ago

Describe the bug An extra character (ZERO WIDTH NO-BREAK SPACE) is being added to body of the produced md files when creating a collection entry through the CMS.

To Reproduce 1) I defined my admin.yml. 2) Created a new entry through the CMS and published. Netlify built site. 3) Fetch/pull the updates from GitHub. 4) Opened the md file in VS Code and saw that each line had an extra character inserted.

Expected behavior Expected to see only the contents that were typed into the CMS, without the extra character.

Screenshots chrome_Xrrz4UtL6p

Code_UiBoYU1kNV

Applicable Versions:

CMS configuration

backend:
  name: git-gateway
  branch: master

media_folder: "static/uploads"
public_folder: "/uploads"

collections:
  - name: "post"
    label: "Post"
    folder: "content/post"
    path: "{{slug}}/index"
    media_folder: ""
    public_folder: ""
    extension: md
    format: toml-frontmatter
    create: true
    fields:
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Description", name: "description", widget: "text"}
      - {label: "Categories", name: "categories", widget: "relation", collection: "categories", value_field: "title", display_fields: ["title"], search_fields: ["title"], multiple: true}
      - {label: "Tags", name: "tags", widget: "list", allow_add: true}
      - {label: "Image", name: "image", widget: "image", required: false}
      - {label: "Body", name: "body", widget: "markdown"}
  - name: "categories"
    label: "Categories"
    folder: "content/categories"
    path: "{{slug}}/index"
    media_folder: ""
    public_folder: ""
    extension: md
    format: toml-frontmatter
    create: true
    fields:
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Description", name: "description", widget: "text"}
      - {label: "Image", name: "image", widget: "image", required: false}
snacksthecat commented 1 year ago

A little bit of extra information that I found.

When using the markdown editor in Chrome, random words appear as misspelled. When inspecting the page, the extra character can be seen there.

chrome_tDqmkivqe7

But using the markdown editor in Firefox, the issue does not happen, and the generated md file does not include the extra characters.

firefox_zJUu2WcbbA

Code_9KPNhv9j4a

amandoabreu commented 1 year ago

Also been having this. Wondering how it's screwing up my SEO. I essentially cannot use this headless CMS anymore. Looking for alternatives.

sh-cho commented 1 year ago

I'm having same issue. FYI, it's BOM character (U+FEFF)

jacebenson commented 1 year ago

Is there no fix for this yet?

bjxpen commented 1 year ago

Apparently, the markdown editor widget uses Slate v0.47 and it will add BOM \uFEFF since Chrome v105 when content is empty.

I followed the discussion on breaking changes in Chrome v105 and they suggested changing CSS property WebkitUserModify: 'read-write-plaintext-only' of the editor to WebkitUserModify: 'read-write'.

I replaced that in netlify-cms.min.js and now it kinda worked:

They also mentioned that Slate before v0.59 is around ~2.5 to 3 years old so this thing may only show up in old versions...

jacebenson commented 1 year ago

@bjxpen that's amazing!

jacebenson commented 1 year ago

well i'll be. I saved https://unpkg.com/netlify-cms@2.10.192/dist/netlify-cms.js locally to my project and made the change you said and it seems so far so great!

kjetilhartveit commented 1 year ago

Any progress on this? I just installed netlify cms and was quite off-putted by this. Fairly difficult to debug as well so I imagine it's hard to find find this issue for many people.

The suggestion by @bjxpen seems to work nicely. Hopefully a Slate upgrade is in the plans, or at least check if that fixes the issue

martinjagodic commented 10 months ago

Slate was updated so this issue is fixed in Decap 3.